indvars -disable-iv-rewrite fix: derived GEP IVs

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135558 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Andrew Trick 2011-07-20 02:08:58 +00:00
parent e236dc6553
commit f22d95749a
2 changed files with 35 additions and 6 deletions

View File

@ -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: "

View File

@ -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
}