llvm.org GIT mirror llvm / f22d957
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 Andrew Trick 8 years ago
2 changed file(s) with 36 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
14181418 if (Inserted)
14191419 continue;
14201420 PHINode *OrigPhi = Pos->second;
1421
1422 // If one phi derives from the other via GEPs, types may differ.
1423 if (OrigPhi->getType() != Phi->getType())
1424 continue;
1425
14211426 // Replacing the congruent phi is sufficient because acyclic redundancy
14221427 // elimination, CSE/GVN, should handle the rest. However, once SCEV proves
14231428 // that a phi is congruent, it's almost certain to be the head of an IV
14291434 Instruction *IsomorphicInc =
14301435 cast(Phi->getIncomingValueForBlock(LatchBlock));
14311436 if (OrigInc != IsomorphicInc &&
1437 OrigInc->getType() == IsomorphicInc->getType() &&
14321438 SE->getSCEV(OrigInc) == SE->getSCEV(IsomorphicInc) &&
14331439 HoistStep(OrigInc, IsomorphicInc, DT)) {
14341440 DEBUG(dbgs() << "INDVARS: Eliminated congruent iv.inc: "
124124 ret void
125125 }
126126
127 %struct = type { i32 }
128
129 define void @bitcastiv(i32 %start, i32 %limit, i32 %step, %struct* %base)
127 %structI = type { i32 }
128
129 define void @bitcastiv(i32 %start, i32 %limit, i32 %step, %structI* %base)
130130 nounwind
131131 {
132132 entry:
141141 ; CHECK: exit:
142142 loop:
143143 %iv = phi i32 [%start, %entry], [%next, %loop]
144 %p = phi %struct* [%base, %entry], [%pinc, %loop]
145 %adr = getelementptr %struct* %p, i32 0, i32 0
144 %p = phi %structI* [%base, %entry], [%pinc, %loop]
145 %adr = getelementptr %structI* %p, i32 0, i32 0
146146 store i32 3, i32* %adr
147 %pp = bitcast %struct* %p to i32*
147 %pp = bitcast %structI* %p to i32*
148148 store i32 4, i32* %pp
149 %pinc = getelementptr %struct* %p, i32 1
149 %pinc = getelementptr %structI* %p, i32 1
150150 %next = add i32 %iv, 1
151151 %cond = icmp ne i32 %next, %limit
152152 br i1 %cond, label %loop, label %exit
319319 %sum4 = add i32 %sum1, %l.next
320320 ret i32 %sum4
321321 }
322
323 ; Test a GEP IV that is derived from another GEP IV by a nop gep that
324 ; lowers the type without changing the expression.
325 %structIF = type { i32, float }
326
327 define void @congruentgepiv(%structIF* %base) nounwind uwtable ssp {
328 entry:
329 %first = getelementptr inbounds %structIF* %base, i64 0, i32 0
330 br label %loop
331
332 loop:
333 %ptr.iv = phi %structIF* [ %ptr.inc, %latch ], [ %base, %entry ]
334 %next = phi i32* [ %next.inc, %latch ], [ %first, %entry ]
335 br i1 undef, label %latch, label %exit
336
337 latch: ; preds = %for.inc50.i
338 %ptr.inc = getelementptr inbounds %structIF* %ptr.iv, i64 1
339 %next.inc = getelementptr inbounds %structIF* %ptr.inc, i64 0, i32 0
340 br label %loop
341
342 exit:
343 ret void
344 }