Alive2: https://alive2.llvm.org/ce/z/sZ6wwS
As detailed on Issue #57635 and #37628 - for unsigned comparisons, we can compare prior to a loop counter decrement iff the counter is known never to be zero.
Paths
| Differential D134172
[InstCombine] Fold ult(add(x,-1),c) -> ule(x,c) iff x != 0 (PR57635) ClosedPublic Authored by RKSimon on Sep 19 2022, 3:09 AM.
Details Summary Alive2: https://alive2.llvm.org/ce/z/sZ6wwS As detailed on Issue #57635 and #37628 - for unsigned comparisons, we can compare prior to a loop counter decrement iff the counter is known never to be zero.
Diff Detail
Event TimelineComment Actions Needs minimal tests for -instcombine alone. I looked at this kind of pattern before, and it seems like a case of missing "nuw" analysis, but I didn't see a way to solve it given that we aggressively convert "sub" to "add" even if that means dropping "nuw". Once that information is lost, there's no way to recover without some kind of ValueTracking. This revision is now accepted and ready to land.Sep 20 2022, 7:56 AM This revision was landed with ongoing or failed builds.Sep 20 2022, 8:45 AM Closed by commit rG09cb9fdef983: [InstCombine] Fold ult(add(x,-1),c) -> ule(x,c) iff x != 0 (PR57635) (authored by RKSimon). · Explain Why This revision was automatically updated to reflect the committed changes.
Revision Contents
Diff 461580 llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/icmp-add.ll
llvm/test/Transforms/LoopUnroll/AArch64/runtime-unroll-generic.ll
llvm/test/Transforms/LoopUnroll/runtime-unroll-remainder.ll
llvm/test/Transforms/LoopVectorize/AArch64/intrinsiccost.ll
llvm/test/Transforms/LoopVectorize/ARM/mve-reductions.ll
llvm/test/Transforms/LoopVectorize/X86/float-induction-x86.ll
llvm/test/Transforms/LoopVectorize/X86/intrinsiccost.ll
llvm/test/Transforms/LoopVectorize/float-induction.ll
llvm/test/Transforms/LoopVectorize/if-conversion-nest.ll
llvm/test/Transforms/LoopVectorize/induction.ll
llvm/test/Transforms/LoopVectorize/runtime-check.ll
|