This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] Set nowrap for finite non-strict predicates for addrecs
AbandonedPublic

Authored by nikic on Apr 12 2023, 3:46 AM.

Details

Summary

While we cannot mark the add 1 as nowrap in general (because we only know that it holds at this specific comparison), we can mark it for addrecs in this loop, because their defining scope (in which nowrap must hold) is limited to that loop (and we also know that there are no other normal or abnormal exits, so we're definitely executing this comparison).

This fixes the regression reported in https://reviews.llvm.org/D145510#4259519.

Diff Detail

Event Timeline

nikic created this revision.Apr 12 2023, 3:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 12 2023, 3:46 AM
nikic requested review of this revision.Apr 12 2023, 3:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 12 2023, 3:46 AM

I don't understand why this is safe. You're checking that the LHS is an AddRec (which is bound to the loop in question), but then you're adding the flags to math on the RHS (which is not).

nikic abandoned this revision.Apr 12 2023, 10:46 AM

I don't understand why this is safe. You're checking that the LHS is an AddRec (which is bound to the loop in question), but then you're adding the flags to math on the RHS (which is not).

Uh yeah, I have honestly no idea what I was thinking here.

I don't think this holds. I think it would hold if you were adding to LHS, but RHS is an unrelated loop invariant value.

What prevents this:
if (rhs + 1 would not overflow) {

for (int i = 0; i < rhs; i++) { ... }

}
else {

use (rhs+1).

}