This patch fixes the cases of sext/zext constant folding in DAG combiner where constans do not fit 64 bits. The fix simply removes un$
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
Thanks for finding this! I think the problems you're seeing revolve around the fact that integer build vectors scalar input operands can be of a wider type than the vector type - typically for legalization reasons. So your pcmpeqd regression is because the comparison result (v4i1) actually has scalar inputs of i32 that get implicitly truncated by BUILD_VECTOR.
lib/CodeGen/SelectionDAG/DAGCombiner.cpp | ||
---|---|---|
5609 ↗ | (On Diff #28126) | The operands of an integer build vector may be wider than the vector scalar type. You need to do something like |
5611 ↗ | (On Diff #28126) | I think you need to just drop the 'getZExtValue()' and keep as a APInt: |
5613 ↗ | (On Diff #28126) | Elts.push_back(DAG.getConstant(C.shl(ShAmt).lshr(ShAmt), DL, SVT); |
test/CodeGen/X86/fold-vector-sext-crash2.ll | ||
2 ↗ | (On Diff #28126) | Missing -mtriple args |
lib/CodeGen/SelectionDAG/DAGCombiner.cpp | ||
---|---|---|
5611 ↗ | (On Diff #28126) | That's definitely safer change. But isn't it the same? |
lib/CodeGen/SelectionDAG/DAGCombiner.cpp | ||
---|---|---|
5609 ↗ | (On Diff #28126) | Sorry that should have been The aim is to ensure that the constant starts out as the bitwidth of input vector's scalar size so that the sext/zext below can work correctly. |
5611 ↗ | (On Diff #28126) | Sorry you're right - if you make the zextOrTrunc change above this should work. |
Trunc the constant value first as it might be wider than the scalar type. Thanks @RKSimon for the tip.