[PATCH] D103153: [InstCombine] Add fold for extracting known elements from a stepvector
Jay Foad via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 26 06:38:08 PDT 2021
foad added inline comments.
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp:357
+ cast<VectorType>(EI.getVectorOperandType())->getScalarType(),
+ IndexC->getZExtValue());
+ return replaceInstUsesWith(EI, Idx);
----------------
CarolineConcatto wrote:
> foad wrote:
> > Just use getValue here.
> It crashes when I replace
> IndexC->getZExtValue() by IndexC->getValue()
>
> ```
> Assertion `C->getType() == Ty->getScalarType() && "ConstantInt type doesn't match the type implied by its value!"' failed.
> ```
OK, it's a bit more complicated if the index type does not match the vector element type. You also need to give up if the index value is too large to fit in the vector element type (this is the case where the langref says "If the sequence value exceeds the allowed limit for the element type then the result for that lane is undefined").
How about something like:
```
Type *Ty = EI.getType();
unsigned BitWidth = Ty->getIntegerBitWidth();
if (IndexC->getValue().getActiveBits() > BitWidth)
break; // with a suitable comment
auto *Idx = ConstantInt::get(Ty, IndexC->getValue().zextOrTrunc(BitWidth));
```
You should also add at least one test where the extractelement index type is wider than the stepvector element type.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D103153/new/
https://reviews.llvm.org/D103153
More information about the llvm-commits
mailing list