[llvm] [ConstraintElim] Decompose shl nsw for signed predicates (PR #76961)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 4 08:28:40 PST 2024
================
@@ -517,6 +517,17 @@ static Decomposition decompose(Value *V,
return Result;
}
+ // shl nsw x, shift is mul nsw x, (1<<shift),
+ // with the exception of shift == bw-1.
+ if (match(V, m_NSWShl(m_Value(Op0), m_ConstantInt(CI)))) {
+ uint64_t Shift = CI->getValue().getLimitedValue();
+ if (Shift < Ty->getIntegerBitWidth() - 1 && Shift < 64) {
----------------
fhahn wrote:
Looks like there's no test case for `Shift >= 64` at the moment. IIUC this is to avoid overflows when doing `1 << Shift`? We won't reach this code if the types are wider than 64 bit and if the type is <= i64 then shifts >= 64 will produce poison. Might be helpful for future readers to document the condition
https://github.com/llvm/llvm-project/pull/76961
More information about the llvm-commits
mailing list