[PATCH] SimplifyIndVar: Forget loops that are made infinite

Arnold Schwaighofer aschwaighofer at apple.com
Wed May 8 14:31:08 PDT 2013


We can transform loops into infinite ones. When this happens we should "forget"
the SCEV for such loops.

Later transformations might depend on the SCEVs to be correct. For example, the
backedge taken count. The loop vectorizer - rightly in my opinion - assumes that
if there is a backedge take count - there should be an induction variable.

Fixes PR15926.


long long a;
volatile int x;
void fn1 () {
  for (a = 0; a >= 0; ++a)
    x = 0;
}

We (indvars) used to transform this from:


define void @fn1() {
entry:
  store i64 0, i64* @a, align 8
  br label %for.body

for.body:
  %inc1 = phi i64 [ 0, %entry ], [ %inc, %for.body ]
  store volatile i32 0, i32* @x, align 4
  %inc = add nsw i64 %inc1, 1
  %cmp = icmp sgt i64 %inc1, -2
  br i1 %cmp, label %for.body, label %for.end

for.end:
  %inc.lcssa = phi i64 [ %inc, %for.body ]
  store i64 %inc.lcssa, i64* @a, align 8
  ret void
}

to:

define void @fn1() {
entry:
  store i64 0, i64* @a, align 8, !tbaa !0
  br label %for.body

for.body:                                         ; preds = %entry, %for.body
  store volatile i32 0, i32* @x, align 4, !tbaa !3
  br i1 true, label %for.body, label %for.end

for.end:                                          ; preds = %for.body
  store i64 -9223372036854775807, i64* @a, align 8, !tbaa !0
  ret void
}


But kept the original SCEVs alive.



-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-SimplifyIndVar-Forget-loops-that-are-made-infinite.patch
Type: application/octet-stream
Size: 5122 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130508/3cab96ce/attachment.obj>


More information about the llvm-commits mailing list