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

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 17 20:54:07 PDT 2016


sanjoy created this revision.
sanjoy added reviewers: atrick, regehr, hfinkel, chandlerc.
sanjoy added a subscriber: llvm-commits.
Herald added subscribers: mzolotukhin, mcrosier.

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

http://reviews.llvm.org/D19213

Files:
  lib/Analysis/ScalarEvolution.cpp
  test/Analysis/ScalarEvolution/infer-prestart-no-wrap.ll
  test/Analysis/ScalarEvolution/nowrap-preinc-limits.ll
  test/Analysis/ScalarEvolution/nsw.ll
  test/Analysis/ScalarEvolution/pr27315.ll
  test/Transforms/IndVarSimplify/elim-extend.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19213.54030.patch
Type: text/x-patch
Size: 8064 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160418/d176c619/attachment.bin>


More information about the llvm-commits mailing list