diff options
author | Caroline Concatto <caroline.concatto@arm.com> | 2021-05-11 15:22:27 +0100 |
---|---|---|
committer | Caroline Concatto <caroline.concatto@arm.com> | 2021-06-10 12:41:40 +0100 |
commit | 3c1f0e9ef89f7c49fdf383e6b01a61be04614a38 (patch) | |
tree | 4e24784ac834d363542b22fcb986a58152927f99 /llvm/lib/IR/ConstantFold.cpp | |
parent | e0569033e21ded970783cab557ba034b134b9c69 (diff) | |
download | llvm-3c1f0e9ef89f7c49fdf383e6b01a61be04614a38.zip llvm-3c1f0e9ef89f7c49fdf383e6b01a61be04614a38.tar.gz llvm-3c1f0e9ef89f7c49fdf383e6b01a61be04614a38.tar.bz2 |
[InstSimplify] Add constant fold for extractelement + splat for scalable vectors
This patch allows that scalable vector can fold extractelement and constant splat
only when the lane index is lower than the minimum number of elements of the vector.
Differential Revision: https://reviews.llvm.org/D103180
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r-- | llvm/lib/IR/ConstantFold.cpp | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index 78e21aee..ecd05be 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -907,14 +907,10 @@ Constant *llvm::ConstantFoldExtractElementInstruction(Constant *Val, } } - // CAZ of type ScalableVectorType and n < CAZ->getMinNumElements() => - // extractelt CAZ, n -> 0 - if (auto *ValSVTy = dyn_cast<ScalableVectorType>(Val->getType())) { - if (!CIdx->uge(ValSVTy->getMinNumElements())) { - if (auto *CAZ = dyn_cast<ConstantAggregateZero>(Val)) - return CAZ->getElementValue(CIdx->getZExtValue()); - } - return nullptr; + // Lane < Splat minimum vector width => extractelt Splat(x), Lane -> x + if (CIdx->getValue().ult(ValVTy->getElementCount().getKnownMinValue())) { + if (Constant *SplatVal = Val->getSplatValue()) + return SplatVal; } return Val->getAggregateElement(CIdx); |