diff options
author | Sander de Smalen <sander.desmalen@arm.com> | 2020-01-21 10:20:27 +0000 |
---|---|---|
committer | Sander de Smalen <sander.desmalen@arm.com> | 2020-01-22 10:09:27 +0000 |
commit | 67d4c9924c1fbfdbfcfa90bf729945eca0a92f86 (patch) | |
tree | 4509f1d0ea9abc619ad898f0ae157eee767e9576 /llvm/lib/CodeGen/CodeGenPrepare.cpp | |
parent | e57a9abc4b01fa69fe81ace8df70517983b6cbac (diff) | |
download | llvm-67d4c9924c1fbfdbfcfa90bf729945eca0a92f86.zip llvm-67d4c9924c1fbfdbfcfa90bf729945eca0a92f86.tar.gz llvm-67d4c9924c1fbfdbfcfa90bf729945eca0a92f86.tar.bz2 |
Add support for (expressing) vscale.
In LLVM IR, vscale can be represented with an intrinsic. For some targets,
this is equivalent to the constexpr:
getelementptr <vscale x 1 x i8>, <vscale x 1 x i8>* null, i32 1
This can be used to propagate the value in CodeGenPrepare.
In ISel we add a node that can be legalized to one or more
instructions to materialize the runtime vector length.
This patch also adds SVE CodeGen support for VSCALE, which maps this
node to RDVL instructions (for scaled multiples of 16bytes) or CNT[HSD]
instructions (scaled multiples of 2, 4, or 8 bytes, respectively).
Reviewers: rengolin, cameron.mcinally, hfinkel, sebpop, SjoerdMeijer, efriedma, lattner
Reviewed by: efriedma
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D68203
Diffstat (limited to 'llvm/lib/CodeGen/CodeGenPrepare.cpp')
-rw-r--r-- | llvm/lib/CodeGen/CodeGenPrepare.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp index f05afd0..01adfc1 100644 --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -2010,6 +2010,22 @@ bool CodeGenPrepare::optimizeCallInst(CallInst *CI, bool &ModifiedDT) { return despeculateCountZeros(II, TLI, DL, ModifiedDT); case Intrinsic::dbg_value: return fixupDbgValue(II); + case Intrinsic::vscale: { + // If datalayout has no special restrictions on vector data layout, + // replace `llvm.vscale` by an equivalent constant expression + // to benefit from cheap constant propagation. + Type *ScalableVectorTy = + VectorType::get(Type::getInt8Ty(II->getContext()), 1, true); + if (DL->getTypeAllocSize(ScalableVectorTy).getKnownMinSize() == 8) { + auto Null = Constant::getNullValue(ScalableVectorTy->getPointerTo()); + auto One = ConstantInt::getSigned(II->getType(), 1); + auto *CGep = + ConstantExpr::getGetElementPtr(ScalableVectorTy, Null, One); + II->replaceAllUsesWith(ConstantExpr::getPtrToInt(CGep, II->getType())); + II->eraseFromParent(); + return true; + } + } } if (TLI) { |