[llvm-commits] [llvm] r64911 - in /llvm/branches/Apple/Dib: lib/Transforms/Scalar/LoopStrengthReduce.cpp test/Transforms/LoopStrengthReduce/pr3571.ll
Bill Wendling
isanbard at gmail.com
Wed Feb 18 00:43:30 PST 2009
Author: void
Date: Wed Feb 18 02:43:29 2009
New Revision: 64911
URL: http://llvm.org/viewvc/llvm-project?rev=64911&view=rev
Log:
Merge r64789 from release_25 branch:
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.
Added:
llvm/branches/Apple/Dib/test/Transforms/LoopStrengthReduce/pr3571.ll
- copied unchanged from r64789, llvm/branches/release_25/test/Transforms/LoopStrengthReduce/pr3571.ll
Modified:
llvm/branches/Apple/Dib/lib/Transforms/Scalar/LoopStrengthReduce.cpp
Modified: llvm/branches/Apple/Dib/lib/Transforms/Scalar/LoopStrengthReduce.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Transforms/Scalar/LoopStrengthReduce.cpp?rev=64911&r1=64910&r2=64911&view=diff
==============================================================================
--- llvm/branches/Apple/Dib/lib/Transforms/Scalar/LoopStrengthReduce.cpp (original)
+++ llvm/branches/Apple/Dib/lib/Transforms/Scalar/LoopStrengthReduce.cpp Wed Feb 18 02:43:29 2009
@@ -400,7 +400,7 @@
/// outer loop of the current loop.
static bool getSCEVStartAndStride(const SCEVHandle &SH, Loop *L,
SCEVHandle &Start, SCEVHandle &Stride,
- ScalarEvolution *SE) {
+ ScalarEvolution *SE, DominatorTree *DT) {
SCEVHandle TheAddRec = Start; // Initialize to zero.
// If the outer level is an AddExpr, the operands are all start values except
@@ -437,9 +437,21 @@
Start = SE->getAddExpr(Start, AddRec->getOperand(0));
- if (!isa<SCEVConstant>(AddRec->getOperand(1)))
+ if (!isa<SCEVConstant>(AddRec->getOperand(1))) {
+ // If stride is an instruction, make sure it dominates the loop header.
+ // Otherwise we could end up with a use before def situation.
+ if (SCEVUnknown *SU = dyn_cast<SCEVUnknown>(AddRec->getOperand(1))) {
+ if (Instruction *I = dyn_cast<Instruction>(SU->getValue())) {
+ BasicBlock *StrideBB = I->getParent();
+ BasicBlock *Preheader = L->getLoopPreheader();
+ if (!DT->dominates(StrideBB, Preheader))
+ return false;
+ }
+ }
+
DOUT << "[" << L->getHeader()->getName()
<< "] Variable stride: " << *AddRec << "\n";
+ }
Stride = AddRec->getOperand(1);
return true;
@@ -547,7 +559,7 @@
// Get the start and stride for this expression.
SCEVHandle Start = SE->getIntegerSCEV(0, ISE->getType());
SCEVHandle Stride = Start;
- if (!getSCEVStartAndStride(ISE, L, Start, Stride, SE))
+ if (!getSCEVStartAndStride(ISE, L, Start, Stride, SE, DT))
return false; // Non-reducible symbolic expression, bail out.
std::vector<Instruction *> IUsers;
More information about the llvm-commits
mailing list