[PATCH] D12073: Make ScalarEvolution::isKnownPredicate a little smarter

hfinkel@anl.gov via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 17 00:41:38 PDT 2015


hfinkel created this revision.
hfinkel added reviewers: sanjoy, atrick.
hfinkel added a subscriber: llvm-commits.
hfinkel set the repository for this revision to rL LLVM.
Herald added a subscriber: sanjoy.

First, the motivation for this patch is to allow LLVM to optimize this code as one might hope:

  void foo (int *a, int *b, int n) {
    for (int i = 0; i < n; ++i) {
      if (i > n)
        a[i] = b[i] + 1;
    }
  }

As `i` is less than `n` in the loop, the conditional `(i > n)` can be folded to false.

With this relatively-simple change, we can perform the simplification in the default pipeline: indvars can perform the folding using SCEV.

Now the obvious question is: is it correct? For now, I've XFAIL'ed two tests:

I believe that the test/Transforms/IndVarSimplify/backedge-on-min-max.ll changes are legitimate (some of the loops in those tests are actually infinite loops, this change causes indvars to make that explicit instead of making other changes - unfortunately, I've been unable to fix the tests to serve their original purpose).

The test/Transforms/LoopStrengthReduce/X86/pr17473.ll changes look more dubious, and I'd certainly appreciate a second opinion. I'll attach some screen shots with the diffs.


Repository:
  rL LLVM

http://reviews.llvm.org/D12073

Files:
  lib/Analysis/ScalarEvolution.cpp
  test/Transforms/IndVarSimplify/backedge-on-min-max.ll
  test/Transforms/IndVarSimplify/bec-cmp.ll
  test/Transforms/LoopStrengthReduce/X86/pr17473.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12073.32272.patch
Type: text/x-patch
Size: 3595 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150817/2832383d/attachment.bin>


More information about the llvm-commits mailing list