[PATCH] D45439: [IRCE] Use NUW flag for indvar

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 11 22:40:20 PDT 2018


mkazantsev added a comment.

Hi Sam,

In test_02 in decrementing loop `%idx` starts from %len.a and then make a range check on `%idx < %len.a` which always fails on 1st iteration. In practice it means that we should have a preloop (in this particular case it means that we deoptimize on 1st iteration). So IRCE here basically makes no sense, but if it DOES happen (i.e. the compiler is not smart enough to understand its non-profitability), it MUST make a preloop.

It does not have `nuw` flag because of `%len.a` is zero then `%idx.next = sub i32 %idx, 1` is calculated with passing from 0 to -1 which is an unsigned overflow, so this instruction does not have a `nuw`, so SCEV might also not set `nuw` for the addrec.

I think (I didn't check it, though) that if you insert a check `%len.a != 0` above the loop and only go to the loop with this condition, it will have `nuw`. I hope it helps!

- Max


https://reviews.llvm.org/D45439





More information about the llvm-commits mailing list