[llvm-commits] [llvm] r135558 - in /llvm/trunk: lib/Transforms/Scalar/IndVarSimplify.cpp test/Transforms/IndVarSimplify/no-iv-rewrite.ll

Andrew Trick atrick at apple.com
Tue Jul 19 19:08:58 PDT 2011


Author: atrick
Date: Tue Jul 19 21:08:58 2011
New Revision: 135558

URL: http://llvm.org/viewvc/llvm-project?rev=135558&view=rev
Log:
indvars -disable-iv-rewrite fix: derived GEP IVs

Modified:
    llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp
    llvm/trunk/test/Transforms/IndVarSimplify/no-iv-rewrite.ll

Modified: llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp?rev=135558&r1=135557&r2=135558&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Tue Jul 19 21:08:58 2011
@@ -1419,6 +1419,11 @@
     if (Inserted)
       continue;
     PHINode *OrigPhi = Pos->second;
+
+    // If one phi derives from the other via GEPs, types may differ.
+    if (OrigPhi->getType() != Phi->getType())
+      continue;
+
     // Replacing the congruent phi is sufficient because acyclic redundancy
     // elimination, CSE/GVN, should handle the rest. However, once SCEV proves
     // that a phi is congruent, it's almost certain to be the head of an IV
@@ -1430,6 +1435,7 @@
       Instruction *IsomorphicInc =
         cast<Instruction>(Phi->getIncomingValueForBlock(LatchBlock));
       if (OrigInc != IsomorphicInc &&
+          OrigInc->getType() == IsomorphicInc->getType() &&
           SE->getSCEV(OrigInc) == SE->getSCEV(IsomorphicInc) &&
           HoistStep(OrigInc, IsomorphicInc, DT)) {
         DEBUG(dbgs() << "INDVARS: Eliminated congruent iv.inc: "

Modified: llvm/trunk/test/Transforms/IndVarSimplify/no-iv-rewrite.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/no-iv-rewrite.ll?rev=135558&r1=135557&r2=135558&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/IndVarSimplify/no-iv-rewrite.ll (original)
+++ llvm/trunk/test/Transforms/IndVarSimplify/no-iv-rewrite.ll Tue Jul 19 21:08:58 2011
@@ -125,9 +125,9 @@
   ret void
 }
 
-%struct = type { i32 }
+%structI = type { i32 }
 
-define void @bitcastiv(i32 %start, i32 %limit, i32 %step, %struct* %base)
+define void @bitcastiv(i32 %start, i32 %limit, i32 %step, %structI* %base)
 nounwind
 {
 entry:
@@ -142,12 +142,12 @@
 ; CHECK: exit:
 loop:
   %iv = phi i32 [%start, %entry], [%next, %loop]
-  %p = phi %struct* [%base, %entry], [%pinc, %loop]
-  %adr = getelementptr %struct* %p, i32 0, i32 0
+  %p = phi %structI* [%base, %entry], [%pinc, %loop]
+  %adr = getelementptr %structI* %p, i32 0, i32 0
   store i32 3, i32* %adr
-  %pp = bitcast %struct* %p to i32*
+  %pp = bitcast %structI* %p to i32*
   store i32 4, i32* %pp
-  %pinc = getelementptr %struct* %p, i32 1
+  %pinc = getelementptr %structI* %p, i32 1
   %next = add i32 %iv, 1
   %cond = icmp ne i32 %next, %limit
   br i1 %cond, label %loop, label %exit
@@ -320,3 +320,26 @@
   %sum4 = add i32 %sum1, %l.next
   ret i32 %sum4
 }
+
+; Test a GEP IV that is derived from another GEP IV by a nop gep that
+; lowers the type without changing the expression.
+%structIF = type { i32, float }
+
+define void @congruentgepiv(%structIF* %base) nounwind uwtable ssp {
+entry:
+  %first = getelementptr inbounds %structIF* %base, i64 0, i32 0
+  br label %loop
+
+loop:
+  %ptr.iv = phi %structIF* [ %ptr.inc, %latch ], [ %base, %entry ]
+  %next = phi i32* [ %next.inc, %latch ], [ %first, %entry ]
+  br i1 undef, label %latch, label %exit
+
+latch:                         ; preds = %for.inc50.i
+  %ptr.inc = getelementptr inbounds %structIF* %ptr.iv, i64 1
+  %next.inc = getelementptr inbounds %structIF* %ptr.inc, i64 0, i32 0
+  br label %loop
+
+exit:
+  ret void
+}





More information about the llvm-commits mailing list