Don't record the increment instruction; just recompute it from the Phi
if needed. This simplifies the code a little, and is needed for an upcoming refactoring. llvm-svn: 66479
This commit is contained in:
parent
1349ab7c9f
commit
f12436891e
|
@ -97,11 +97,9 @@ namespace {
|
||||||
SCEVHandle Stride;
|
SCEVHandle Stride;
|
||||||
SCEVHandle Base;
|
SCEVHandle Base;
|
||||||
PHINode *PHI;
|
PHINode *PHI;
|
||||||
Value *IncV;
|
|
||||||
|
|
||||||
IVExpr(const SCEVHandle &stride, const SCEVHandle &base, PHINode *phi,
|
IVExpr(const SCEVHandle &stride, const SCEVHandle &base, PHINode *phi)
|
||||||
Value *incv)
|
: Stride(stride), Base(base), PHI(phi) {}
|
||||||
: Stride(stride), Base(base), PHI(phi), IncV(incv) {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// IVsOfOneStride - This structure keeps track of all IV expression inserted
|
/// IVsOfOneStride - This structure keeps track of all IV expression inserted
|
||||||
|
@ -109,9 +107,8 @@ namespace {
|
||||||
struct VISIBILITY_HIDDEN IVsOfOneStride {
|
struct VISIBILITY_HIDDEN IVsOfOneStride {
|
||||||
std::vector<IVExpr> IVs;
|
std::vector<IVExpr> IVs;
|
||||||
|
|
||||||
void addIV(const SCEVHandle &Stride, const SCEVHandle &Base, PHINode *PHI,
|
void addIV(const SCEVHandle &Stride, const SCEVHandle &Base, PHINode *PHI) {
|
||||||
Value *IncV) {
|
IVs.push_back(IVExpr(Stride, Base, PHI));
|
||||||
IVs.push_back(IVExpr(Stride, Base, PHI, IncV));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -695,10 +692,7 @@ namespace {
|
||||||
|
|
||||||
/// Phi - The induction variable that performs the striding that
|
/// Phi - The induction variable that performs the striding that
|
||||||
/// should be used for this user.
|
/// should be used for this user.
|
||||||
Value *Phi;
|
PHINode *Phi;
|
||||||
|
|
||||||
/// IncV - The post-incremented value of Phi.
|
|
||||||
Value *IncV;
|
|
||||||
|
|
||||||
// isUseOfPostIncrementedValue - True if this should use the
|
// isUseOfPostIncrementedValue - True if this should use the
|
||||||
// post-incremented version of this IV, not the preincremented version.
|
// post-incremented version of this IV, not the preincremented version.
|
||||||
|
@ -1587,13 +1581,11 @@ bool LoopStrengthReduce::ShouldUseFullStrengthReductionMode(
|
||||||
/// If NegateStride is true, the stride should be negated by using a
|
/// If NegateStride is true, the stride should be negated by using a
|
||||||
/// subtract instead of an add.
|
/// subtract instead of an add.
|
||||||
///
|
///
|
||||||
/// Return the created phi node, and return the step instruction by
|
/// Return the created phi node.
|
||||||
/// reference in IncV.
|
|
||||||
///
|
///
|
||||||
static PHINode *InsertAffinePhi(SCEVHandle Start, SCEVHandle Step,
|
static PHINode *InsertAffinePhi(SCEVHandle Start, SCEVHandle Step,
|
||||||
const Loop *L,
|
const Loop *L,
|
||||||
SCEVExpander &Rewriter,
|
SCEVExpander &Rewriter) {
|
||||||
Value *&IncV) {
|
|
||||||
assert(Start->isLoopInvariant(L) && "New PHI start is not loop invariant!");
|
assert(Start->isLoopInvariant(L) && "New PHI start is not loop invariant!");
|
||||||
assert(Step->isLoopInvariant(L) && "New PHI stride is not loop invariant!");
|
assert(Step->isLoopInvariant(L) && "New PHI stride is not loop invariant!");
|
||||||
|
|
||||||
|
@ -1615,6 +1607,7 @@ static PHINode *InsertAffinePhi(SCEVHandle Start, SCEVHandle Step,
|
||||||
// Insert an add instruction right before the terminator corresponding
|
// Insert an add instruction right before the terminator corresponding
|
||||||
// to the back-edge.
|
// to the back-edge.
|
||||||
Value *StepV = Rewriter.expandCodeFor(IncAmount, Preheader->getTerminator());
|
Value *StepV = Rewriter.expandCodeFor(IncAmount, Preheader->getTerminator());
|
||||||
|
Instruction *IncV;
|
||||||
if (isNegative) {
|
if (isNegative) {
|
||||||
IncV = BinaryOperator::CreateSub(PN, StepV, "lsr.iv.next",
|
IncV = BinaryOperator::CreateSub(PN, StepV, "lsr.iv.next",
|
||||||
LatchBlock->getTerminator());
|
LatchBlock->getTerminator());
|
||||||
|
@ -1684,16 +1677,13 @@ LoopStrengthReduce::PrepareToStrengthReduceFully(
|
||||||
SCEVHandle Imm = UsersToProcess[i].Imm;
|
SCEVHandle Imm = UsersToProcess[i].Imm;
|
||||||
SCEVHandle Base = UsersToProcess[i].Base;
|
SCEVHandle Base = UsersToProcess[i].Base;
|
||||||
SCEVHandle Start = SE->getAddExpr(CommonExprs, Base, Imm);
|
SCEVHandle Start = SE->getAddExpr(CommonExprs, Base, Imm);
|
||||||
Value *IncV;
|
|
||||||
PHINode *Phi = InsertAffinePhi(Start, Stride, L,
|
PHINode *Phi = InsertAffinePhi(Start, Stride, L,
|
||||||
PreheaderRewriter,
|
PreheaderRewriter);
|
||||||
IncV);
|
|
||||||
// Loop over all the users with the same base.
|
// Loop over all the users with the same base.
|
||||||
do {
|
do {
|
||||||
UsersToProcess[i].Base = SE->getIntegerSCEV(0, Stride->getType());
|
UsersToProcess[i].Base = SE->getIntegerSCEV(0, Stride->getType());
|
||||||
UsersToProcess[i].Imm = SE->getMinusSCEV(UsersToProcess[i].Imm, Imm);
|
UsersToProcess[i].Imm = SE->getMinusSCEV(UsersToProcess[i].Imm, Imm);
|
||||||
UsersToProcess[i].Phi = Phi;
|
UsersToProcess[i].Phi = Phi;
|
||||||
UsersToProcess[i].IncV = IncV;
|
|
||||||
assert(UsersToProcess[i].Imm->isLoopInvariant(L) &&
|
assert(UsersToProcess[i].Imm->isLoopInvariant(L) &&
|
||||||
"ShouldUseFullStrengthReductionMode should reject this!");
|
"ShouldUseFullStrengthReductionMode should reject this!");
|
||||||
} while (++i != e && Base == UsersToProcess[i].Base);
|
} while (++i != e && Base == UsersToProcess[i].Base);
|
||||||
|
@ -1713,25 +1703,19 @@ LoopStrengthReduce::PrepareToStrengthReduceWithNewPhi(
|
||||||
SCEVExpander &PreheaderRewriter) {
|
SCEVExpander &PreheaderRewriter) {
|
||||||
DOUT << " Inserting new PHI:\n";
|
DOUT << " Inserting new PHI:\n";
|
||||||
|
|
||||||
Value *IncV;
|
|
||||||
PHINode *Phi = InsertAffinePhi(SE->getUnknown(CommonBaseV),
|
PHINode *Phi = InsertAffinePhi(SE->getUnknown(CommonBaseV),
|
||||||
Stride, L,
|
Stride, L,
|
||||||
PreheaderRewriter,
|
PreheaderRewriter);
|
||||||
IncV);
|
|
||||||
|
|
||||||
// Remember this in case a later stride is multiple of this.
|
// Remember this in case a later stride is multiple of this.
|
||||||
IVsByStride[Stride].addIV(Stride, CommonExprs, Phi, IncV);
|
IVsByStride[Stride].addIV(Stride, CommonExprs, Phi);
|
||||||
|
|
||||||
// All the users will share this new IV.
|
// All the users will share this new IV.
|
||||||
for (unsigned i = 0, e = UsersToProcess.size(); i != e; ++i) {
|
for (unsigned i = 0, e = UsersToProcess.size(); i != e; ++i)
|
||||||
UsersToProcess[i].Phi = Phi;
|
UsersToProcess[i].Phi = Phi;
|
||||||
UsersToProcess[i].IncV = IncV;
|
|
||||||
}
|
|
||||||
|
|
||||||
DOUT << " IV=";
|
DOUT << " IV=";
|
||||||
DEBUG(WriteAsOperand(*DOUT, Phi, /*PrintType=*/false));
|
DEBUG(WriteAsOperand(*DOUT, Phi, /*PrintType=*/false));
|
||||||
DOUT << ", INC=";
|
|
||||||
DEBUG(WriteAsOperand(*DOUT, IncV, /*PrintType=*/false));
|
|
||||||
DOUT << "\n";
|
DOUT << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1749,10 +1733,8 @@ LoopStrengthReduce::PrepareToStrengthReduceFromSmallerStride(
|
||||||
<< " and BASE " << *ReuseIV.Base << "\n";
|
<< " and BASE " << *ReuseIV.Base << "\n";
|
||||||
|
|
||||||
// All the users will share the reused IV.
|
// All the users will share the reused IV.
|
||||||
for (unsigned i = 0, e = UsersToProcess.size(); i != e; ++i) {
|
for (unsigned i = 0, e = UsersToProcess.size(); i != e; ++i)
|
||||||
UsersToProcess[i].Phi = ReuseIV.PHI;
|
UsersToProcess[i].Phi = ReuseIV.PHI;
|
||||||
UsersToProcess[i].IncV = ReuseIV.IncV;
|
|
||||||
}
|
|
||||||
|
|
||||||
Constant *C = dyn_cast<Constant>(CommonBaseV);
|
Constant *C = dyn_cast<Constant>(CommonBaseV);
|
||||||
if (C &&
|
if (C &&
|
||||||
|
@ -1884,7 +1866,7 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEVHandle &Stride,
|
||||||
SCEVHandle RewriteFactor = SE->getIntegerSCEV(0, ReplacedTy);
|
SCEVHandle RewriteFactor = SE->getIntegerSCEV(0, ReplacedTy);
|
||||||
IVExpr ReuseIV(SE->getIntegerSCEV(0, Type::Int32Ty),
|
IVExpr ReuseIV(SE->getIntegerSCEV(0, Type::Int32Ty),
|
||||||
SE->getIntegerSCEV(0, Type::Int32Ty),
|
SE->getIntegerSCEV(0, Type::Int32Ty),
|
||||||
0, 0);
|
0);
|
||||||
|
|
||||||
/// Choose a strength-reduction strategy and prepare for it by creating
|
/// Choose a strength-reduction strategy and prepare for it by creating
|
||||||
/// the necessary PHIs and adjusting the bookkeeping.
|
/// the necessary PHIs and adjusting the bookkeeping.
|
||||||
|
@ -1957,7 +1939,7 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEVHandle &Stride,
|
||||||
// after the post-inc and use its value instead of the PHI.
|
// after the post-inc and use its value instead of the PHI.
|
||||||
Value *RewriteOp = User.Phi;
|
Value *RewriteOp = User.Phi;
|
||||||
if (User.isUseOfPostIncrementedValue) {
|
if (User.isUseOfPostIncrementedValue) {
|
||||||
RewriteOp = User.IncV;
|
RewriteOp = User.Phi->getIncomingValueForBlock(LatchBlock);
|
||||||
|
|
||||||
// If this user is in the loop, make sure it is the last thing in the
|
// If this user is in the loop, make sure it is the last thing in the
|
||||||
// loop to ensure it is dominated by the increment.
|
// loop to ensure it is dominated by the increment.
|
||||||
|
|
Loading…
Reference in New Issue