[PATCH] D146457: [LSR] Use evaluateAtIteration in lsr-term-fold

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 21 07:40:17 PDT 2023


reames added a comment.

In D146457#4209092 <https://reviews.llvm.org/D146457#4209092>, @nikic wrote:

> LGTM
>
>> All of the test changes are, to my eye, semantically the same.
>
> I don't think they are: Let's say that `%length == 0`, which means that the BECount is -1. Previously, this just extended `%length` to `i64`, so that the effective trip count was zero. Now we instead extend `-1` and then add the stride, making the trip count correct. The previous code was using an incorrect order of extensions.

So, you'd be correct here, except that the IV in question is nsw, and we branch on the result.  For N=0, the starting value of the post-inc IV for the loop is -1 and we subtract 1 on every iteration.  To reach zero, we have to pass through the negative overflow case, and thus have poison and (from the branch) UB.  So, we can discount this case when reasoning about the expansion.

On the other hand, if we had an example without nsw on the induction increment, I think you'd be correct that this would be a semantic change.  I'll add a test case to that effect.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146457/new/

https://reviews.llvm.org/D146457



More information about the llvm-commits mailing list