[llvm] r263827 - [IndVars] Pass the right loop to isLoopInvariantPredicate

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 18 13:37:07 PDT 2016


Author: sanjoy
Date: Fri Mar 18 15:37:07 2016
New Revision: 263827

URL: http://llvm.org/viewvc/llvm-project?rev=263827&view=rev
Log:
[IndVars] Pass the right loop to isLoopInvariantPredicate

The loop on IVOperand's incoming values assumes IVOperand to be an
induction variable on the loop over which `S Pred X` is invariant;
otherwise loop invariant incoming values to IVOperand are not guaranteed
to dominate the comparision.

This fixes PR26973.

Added:
    llvm/trunk/test/Transforms/IndVarSimplify/pr26973.ll
Modified:
    llvm/trunk/lib/Transforms/Utils/SimplifyIndVar.cpp

Modified: llvm/trunk/lib/Transforms/Utils/SimplifyIndVar.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyIndVar.cpp?rev=263827&r1=263826&r2=263827&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyIndVar.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyIndVar.cpp Fri Mar 18 15:37:07 2016
@@ -183,9 +183,8 @@ void SimplifyIndvar::eliminateIVComparis
     DeadInsts.emplace_back(ICmp);
     DEBUG(dbgs() << "INDVARS: Eliminated comparison: " << *ICmp << '\n');
   } else if (isa<PHINode>(IVOperand) &&
-             SE->isLoopInvariantPredicate(Pred, S, X, ICmpLoop,
-                                          InvariantPredicate, InvariantLHS,
-                                          InvariantRHS)) {
+             SE->isLoopInvariantPredicate(Pred, S, X, L, InvariantPredicate,
+                                          InvariantLHS, InvariantRHS)) {
 
     // Rewrite the comparison to a loop invariant comparison if it can be done
     // cheaply, where cheaply means "we don't need to emit any new

Added: llvm/trunk/test/Transforms/IndVarSimplify/pr26973.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/pr26973.ll?rev=263827&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/IndVarSimplify/pr26973.ll (added)
+++ llvm/trunk/test/Transforms/IndVarSimplify/pr26973.ll Fri Mar 18 15:37:07 2016
@@ -0,0 +1,33 @@
+; RUN: opt -S -indvars < %s | FileCheck %s
+
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.11.0"
+
+ at a = common global double* null, align 8
+ at b = common global double 0.000000e+00, align 8
+
+define void @fn1(i32 %p1) {
+; CHECK-LABEL: @fn1(
+entry:
+  %ld = load double*, double** @a, align 8
+  br label %outer.loop
+
+outer.loop:
+  %iv.outer = phi i32 [ %p1, %entry ], [ %iv.outer.dec, %outer.be ]
+  %idxprom = sext i32 %iv.outer to i64
+  %arrayidx = getelementptr inbounds double, double* %ld, i64 %idxprom
+  %arrayidx.bc = bitcast double* %arrayidx to i64*
+  br label %inner.loop
+
+inner.loop:
+  %iv.inner = phi i32 [ %iv.outer, %outer.loop ], [ %iv.inner.dec, %inner.loop ]
+  %ld.arr = load i64, i64* %arrayidx.bc, align 8
+  store i64 %ld.arr, i64* bitcast (double* @b to i64*), align 8
+  %iv.inner.dec = add nsw i32 %iv.inner, -1
+  %cmp = icmp slt i32 %iv.outer, %iv.inner.dec
+  br i1 %cmp, label %outer.be, label %inner.loop
+
+outer.be:
+  %iv.outer.dec = add nsw i32 %iv.outer, -1
+  br label %outer.loop
+}




More information about the llvm-commits mailing list