This is an archive of the discontinued LLVM Phabricator instance.

[LSR] Use evaluateAtIteration in lsr-term-fold
ClosedPublic

Authored by reames on Mar 20 2023, 2:17 PM.

Details

Summary

This is a follow up to one of the side discussions on D146429. All of the test changes are, to my eye, semantically the same.

The motivation for the change to the legality condition introduced in D146429 comes from the fact that we only check the post-inc form. As such, as long as the values of the post-inc variable don't self wrap, it's actually okay if we wrap past the starting value of the pre-inc IV.

Diff Detail

Event Timeline

reames created this revision.Mar 20 2023, 2:17 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 20 2023, 2:17 PM
reames requested review of this revision.Mar 20 2023, 2:17 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 20 2023, 2:17 PM
reames edited the summary of this revision. (Show Details)Mar 20 2023, 2:22 PM
nikic accepted this revision.Mar 21 2023, 3:53 AM

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.

This revision is now accepted and ready to land.Mar 21 2023, 3:53 AM

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.

This revision was landed with ongoing or failed builds.Mar 21 2023, 8:13 AM
This revision was automatically updated to reflect the committed changes.