Open k-arrows opened 10 months ago
I think the problem here is that the shl range calculation is not sufficiently accurate if the LHS can be negative: https://llvm.godbolt.org/z/afEec9q6K
POP i32 %arg in if = constantrange<-4, 5>
Result = constantrange<-4, 5>
[...]
POP %shl = shl nsw i32 %arg, 1 in if = constantrange<0, -1>
Result = constantrange<0, -1>
We're probably using this fallback case: https://github.com/llvm/llvm-project/blob/1ffcac1b077afecff4b57b2ceec73c9bcb847389/llvm/lib/IR/ConstantRange.cpp#L1489C13-L1489C13
Consider the following functions. https://godbolt.org/z/KxdWKofjd
All of these functions can be optimized (to the function which returns zero), but Clang cannot optimize
test2
,test4
, andtest8
.