[PATCH] D39345: SCEV: preserve debug information attached to PHI nodes.

Hal Finkel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 1 20:06:06 PDT 2017


hfinkel added a comment.

In https://reviews.llvm.org/D39345#912029, @aprantl wrote:

> I moved the logic over to `indvars` now, and that seems to fit naturally into `WidenIV::createWideIV()` with about the same functionality as above.
>
> But I'm having trouble generating more interesting testcases. For example: The top-level comment in IndVarSimplify claims that the pass would
>
>   //   1. The exit condition for the loop is canonicalized to compare the
>   //      induction value against the exit value.  This turns loops like:
>   //        'for (i = 7; i*i < 1000; ++i)' into 'for (i = 0; i != 25; ++i)'
>
>
> But I can't reproduce this:
>
>   char *a;
>   void f(int j) {
>     for (int i = 7; i*i < 1000; i+=1)
>         a[i] = i;
>   }
>  
>   clang -O3 -c -S -emit-llvm -o - /tmp/loop.c -fno-unroll-loops -mllvm -print-after-all -g 2>&1
>  
>   *** IR Dump After Induction Variable Simplification ***
>   for.body:                                         ; preds = %entry, %for.body
>     %indvars.iv = phi i64 [ 7, %entry ], [ %indvars.iv.next, %for.body ]
>
>
> Has the functionality bitrotted, or is the comment out-of-date, or is there now a different transformation that would rewrite a loop like int that comment? Or can I change my testcase somehow?


It is out of date. @sanjoy may know more. Thinking about it, I do recall that we might now not do these replacements in cases where SCEV can easily construct the induction-variable recurrence.

> I then put an assert that IVDiff (the diff between SCEV for the old and new phi in WidenIV::createWideIV()) is not a constant zero and check-llvm-transform still passes. That's not the end of the world, handling the constant-zero case would already be a nice improvement, but I'm wondering if I'm missing the big picture here.

Hrmm. I'm missing something too. We also don't seem to be collapsing logically-redundant phis, as in:

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

this loop still ends up with two phis after optimization. I thought IndVarSimplify took care of this, but evidently it doesn't right now.

For now, given the apparent current state of things, maybe we should just handle the zero-delta case, and then come back to this later as necessary.


https://reviews.llvm.org/D39345





More information about the llvm-commits mailing list