llvm.org GIT mirror llvm / 8f40afe
Fix pr3571: If stride is a value defined by an instruction, make sure it dominates the loop preheader. When IV users are strength reduced, the stride is inserted into the preheader. It could create a use before def situation. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@64579 91177308-0d34-0410-b5e6-96231b3b80d8 Evan Cheng 10 years ago
2 changed file(s) with 42 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
399399 /// outer loop of the current loop.
400400 static bool getSCEVStartAndStride(const SCEVHandle &SH, Loop *L,
401401 SCEVHandle &Start, SCEVHandle &Stride,
402 ScalarEvolution *SE) {
402 ScalarEvolution *SE, DominatorTree *DT) {
403403 SCEVHandle TheAddRec = Start; // Initialize to zero.
404404
405405 // If the outer level is an AddExpr, the operands are all start values except
436436
437437 Start = SE->getAddExpr(Start, AddRec->getOperand(0));
438438
439 #ifndef NDEBUG
440 if (!isa(AddRec->getOperand(1)))
439 if (!isa(AddRec->getOperand(1))) {
440 // If stride is an instruction, make sure it dominates the loop header.
441 // Otherwise we could end up with a use before def situation.
442 if (SCEVUnknown *SU = dyn_cast(AddRec->getOperand(1))) {
443 if (Instruction *I = dyn_cast(SU->getValue())) {
444 BasicBlock *StrideBB = I->getParent();
445 BasicBlock *Preheader = L->getLoopPreheader();
446 if (!DT->dominates(StrideBB, Preheader))
447 return false;
448 }
449 }
450
441451 DOUT << "[" << L->getHeader()->getName()
442452 << "] Variable stride: " << *AddRec << "\n";
443 #endif
453 }
444454
445455 Stride = AddRec->getOperand(1);
446456 return true;
548558 // Get the start and stride for this expression.
549559 SCEVHandle Start = SE->getIntegerSCEV(0, ISE->getType());
550560 SCEVHandle Stride = Start;
551 if (!getSCEVStartAndStride(ISE, L, Start, Stride, SE))
561 if (!getSCEVStartAndStride(ISE, L, Start, Stride, SE, DT))
552562 return false; // Non-reducible symbolic expression, bail out.
553563
554564 std::vector IUsers;
0 ; RUN: llvm-as < %s | opt -loop-reduce | llvm-dis
1 ; PR3571
2
3 target triple = "i386-mingw32"
4 define void @_ZNK18qdesigner_internal10TreeWidget12drawBranchesEP8QPainterRK5QRectRK11QModelIndex() nounwind {
5 entry:
6 br label %_ZNK11QModelIndex7isValidEv.exit.i
7
8 bb.i: ; preds = %_ZNK11QModelIndex7isValidEv.exit.i
9 %indvar.next = add i32 %result.0.i, 1 ; [#uses=1]
10 br label %_ZNK11QModelIndex7isValidEv.exit.i
11
12 _ZNK11QModelIndex7isValidEv.exit.i: ; preds = %bb.i, %entry
13 %result.0.i = phi i32 [ 0, %entry ], [ %indvar.next, %bb.i ] ; [#uses=2]
14 %0 = load i32** null, align 4 ; <%struct.QAbstractItemDelegate*> [#uses=0]
15 br i1 false, label %_ZN18qdesigner_internalL5levelEP18QAbstractItemModelRK11QModelIndex.exit, label %bb.i
16
17 _ZN18qdesigner_internalL5levelEP18QAbstractItemModelRK11QModelIndex.exit: ; preds = %_ZNK11QModelIndex7isValidEv.exit.i
18 %1 = call i32 @_ZNK9QTreeView11indentationEv(i32* null) nounwind ; [#uses=1]
19 %2 = mul i32 %1, %result.0.i ; [#uses=1]
20 %3 = add i32 %2, -2 ; [#uses=1]
21 %4 = add i32 %3, 0 ; [#uses=1]
22 store i32 %4, i32* null, align 8
23 unreachable
24 }
25
26 declare i32 @_ZNK9QTreeView11indentationEv(i32*)