Previously ConstantFoldExtractElementInstruction() would only work with
insertelement instructions, not contants. This properly handles
insertelement constants as well.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
I think I'd prefer to keep this code in ConstantFoldExtractElementInstruction, rather than extend getAggregateElement() this way; I think it's unintuitive to be doing constant folding in getAggregateElement().
llvm/lib/IR/Constants.cpp | ||
---|---|---|
421 ↗ | (On Diff #285212) | Can we also fold in the case where the indexes are known not-equal? |
Done.
llvm/lib/IR/Constants.cpp | ||
---|---|---|
421 ↗ | (On Diff #285212) | Do you mean recursively search the vector operand? |
llvm/lib/IR/ConstantFold.cpp | ||
---|---|---|
858 | Oh, also, please avoid using getZExtValue() on constants that don't have a known width; it asserts the number is less than 2^64. Unfortunately, there isn't any convenient way to do this comparison at the moment; I guess you could use APSInt::isSameValue. |
llvm/lib/IR/ConstantFold.cpp | ||
---|---|---|
858 | Is APInt::eq() good? |
llvm/lib/IR/ConstantFold.cpp | ||
---|---|---|
858 | IDIdx and CIdx might not have the same bitwidth, I think; the index of an insertelement/extractelement can have any type. APInt::eq asserts if the widths aren't equal. |
Use APSInt::isSameValue()
llvm/lib/IR/ConstantFold.cpp | ||
---|---|---|
858 | Ah yes, I changed one of the types in the new test and repro'd. Now using APSInt::isSameValue(). |
Oh, also, please avoid using getZExtValue() on constants that don't have a known width; it asserts the number is less than 2^64. Unfortunately, there isn't any convenient way to do this comparison at the moment; I guess you could use APSInt::isSameValue.