Existing condition for
fold icmp ugt (ashr X, ShAmtC), C --> icmp ugt X, ((C + 1) << ShAmtC) - 1
missed some boundary. It cause this fold don't work for some cases, and the
reason is due to signed number overflow.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
For reference, this was the Alive2 from the original review ( D117365 ):
https://alive2.llvm.org/ce/z/tFAcZt
To catch the overflow case, I think we check if the incremented + shifted constant became signed min (0x8000...):
https://alive2.llvm.org/ce/z/RZdftJ
So that should be simpler than the pre-condition currently shown in this patch.
(C + 1).shl(ShAmtVal).isMinSignedValue()
LGTM - it may be worth looking at the related folds to see if there's some generalization that we missed (see inline comment about the other TODO comment in the test file).
llvm/test/Transforms/InstCombine/icmp-shr.ll | ||
---|---|---|
857–858 | Check the history to see where this got fixed? Either way, we should delete the TODO since it optimized now. |
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | ||
---|---|---|
2258–2259 | Rephrase this comment: // 'C + 1 << ShAmtC' can overflow as a signed number, so the 2nd // clause accounts for that pattern. |
Rephrase this comment: