aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/Transforms/Scalar/IndVarSimplify.cpp6
-rw-r--r--test/Transforms/IndVarSimplify/no-iv-rewrite.ll35
2 files changed, 35 insertions, 6 deletions
diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp
index b75db7d..55094b9 100644
--- a/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -1419,6 +1419,11 @@ void IndVarSimplify::SimplifyCongruentIVs(Loop *L) {
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 @@ void IndVarSimplify::SimplifyCongruentIVs(Loop *L) {
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: "
diff --git a/test/Transforms/IndVarSimplify/no-iv-rewrite.ll b/test/Transforms/IndVarSimplify/no-iv-rewrite.ll
index 9605670..bb951c6 100644
--- a/test/Transforms/IndVarSimplify/no-iv-rewrite.ll
+++ b/test/Transforms/IndVarSimplify/no-iv-rewrite.ll
@@ -125,9 +125,9 @@ return:
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 @@ entry:
; 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 @@ return:
%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
+}