Make the {A,+,B}<L> + {C,+,D}<L> --> Other + {A+C,+,B+D}<L>

transformation collect all the addrecs with the same loop
add combine them at once rather than starting everything over
at the first chance.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112290 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman
2010-08-27 20:45:56 +00:00
parent d07ad66791
commit 32527156b3

View File

@@ -1675,31 +1675,29 @@ const SCEV *ScalarEvolution::getAddExpr(SmallVectorImpl<const SCEV *> &Ops,
// there are multiple AddRec's with the same loop induction variable being // there are multiple AddRec's with the same loop induction variable being
// added together. If so, we can fold them. // added together. If so, we can fold them.
for (unsigned OtherIdx = Idx+1; for (unsigned OtherIdx = Idx+1;
OtherIdx < Ops.size() && isa<SCEVAddRecExpr>(Ops[OtherIdx]);++OtherIdx) OtherIdx < Ops.size() && isa<SCEVAddRecExpr>(Ops[OtherIdx]);
if (OtherIdx != Idx) { ++OtherIdx)
const SCEVAddRecExpr *OtherAddRec = cast<SCEVAddRecExpr>(Ops[OtherIdx]); if (AddRecLoop == cast<SCEVAddRecExpr>(Ops[OtherIdx])->getLoop()) {
if (AddRecLoop == OtherAddRec->getLoop()) { // Other + {A,+,B}<L> + {C,+,D}<L> --> Other + {A+C,+,B+D}<L>
// Other + {A,+,B} + {C,+,D} --> Other + {A+C,+,B+D} SmallVector<const SCEV *, 4> AddRecOps(AddRec->op_begin(),
SmallVector<const SCEV *, 4> NewOps(AddRec->op_begin(),
AddRec->op_end()); AddRec->op_end());
for (unsigned i = 0, e = OtherAddRec->getNumOperands(); i != e; ++i) { for (; OtherIdx != Ops.size() && isa<SCEVAddRecExpr>(Ops[OtherIdx]);
if (i >= NewOps.size()) { ++OtherIdx)
NewOps.append(OtherAddRec->op_begin()+i, if (const SCEVAddRecExpr *AR =
OtherAddRec->op_end()); dyn_cast<SCEVAddRecExpr>(Ops[OtherIdx]))
if (AR->getLoop() == AddRecLoop) {
for (unsigned i = 0, e = AR->getNumOperands(); i != e; ++i) {
if (i >= AddRecOps.size()) {
AddRecOps.append(AR->op_begin()+i, AR->op_end());
break; break;
} }
NewOps[i] = getAddExpr(NewOps[i], OtherAddRec->getOperand(i)); AddRecOps[i] = getAddExpr(AddRecOps[i], AR->getOperand(i));
} }
const SCEV *NewAddRec = getAddRecExpr(NewOps, AddRecLoop); Ops.erase(Ops.begin() + OtherIdx); --OtherIdx;
}
if (Ops.size() == 2) return NewAddRec; Ops[Idx] = getAddRecExpr(AddRecOps, AddRecLoop);
Ops.erase(Ops.begin()+Idx);
Ops.erase(Ops.begin()+OtherIdx-1);
Ops.push_back(NewAddRec);
return getAddExpr(Ops); return getAddExpr(Ops);
} }
}
// Otherwise couldn't fold anything into this recurrence. Move onto the // Otherwise couldn't fold anything into this recurrence. Move onto the
// next one. // next one.