This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] Don't always add no-wrap flags to post-inc add recs
AbandonedPublic

Authored by sanjoy on Apr 17 2016, 8:54 PM.

Details

Summary

Fixes PR27315.

The post-inc version of an add recurrence needs to "follow the same
rules" as a normal add or subtract expression. Otherwise we miscompile
programs like

int main() {
  int a = 0;
  unsigned a_u = 0;
  volatile long last_value;
  do {
    a_u += 3;
    last_value = (long) ((int) a_u);
    if (will_add_overflow(a, 3)) {
      // Leave, and don't actually do the increment, so no UB.
      printf("last_value = %ld\n", last_value);
      exit(0);
    }
    a += 3;
  } while (a != 46);
  return 0;
}

Some previous patches (added as dependencies here) are needed for this
not regress performance too much.

Depends on: D19209
Depends on: D19210
Depends on: D19211
Depends on: D19212

Diff Detail

Event Timeline

sanjoy updated this revision to Diff 54030.Apr 17 2016, 8:54 PM
sanjoy retitled this revision from to [SCEV] Don't always add no-wrap flags to post-inc add recs.
sanjoy updated this object.
sanjoy added reviewers: atrick, regehr, hfinkel, chandlerc.
sanjoy added a subscriber: llvm-commits.
hfinkel accepted this revision.Apr 26 2016, 10:21 AM
hfinkel edited edge metadata.

LGTM.

lib/Analysis/ScalarEvolution.cpp
3990

Indentation looks odd here.

This revision is now accepted and ready to land.Apr 26 2016, 10:21 AM

LGTM.

Hi Hal,

Thanks for the review; but just FYI: it looks like one of the key changes I was relying on to have this pass not regress too much performance is incorrect (D19211). I'm now exploring other, less performance hurting ways to fix the same underlying issue as this bug.

sanjoy abandoned this revision.May 30 2016, 1:30 PM

I've checked in a somewhat modified form of this in rL271151