From: Dan Gohman Date: Fri, 27 Aug 2010 20:45:56 +0000 (+0000) Subject: Make the {A,+,B} + {C,+,D} --> Other + {A+C,+,B+D} X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=32527156b3f33466af15a43d3a1695fd9ee2d315;p=oota-llvm.git Make the {A,+,B} + {C,+,D} --> Other + {A+C,+,B+D} 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 --- diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index f3fd887f56e..be4f3b598c9 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -1675,30 +1675,28 @@ const SCEV *ScalarEvolution::getAddExpr(SmallVectorImpl &Ops, // there are multiple AddRec's with the same loop induction variable being // added together. If so, we can fold them. for (unsigned OtherIdx = Idx+1; - OtherIdx < Ops.size() && isa(Ops[OtherIdx]);++OtherIdx) - if (OtherIdx != Idx) { - const SCEVAddRecExpr *OtherAddRec = cast(Ops[OtherIdx]); - if (AddRecLoop == OtherAddRec->getLoop()) { - // Other + {A,+,B} + {C,+,D} --> Other + {A+C,+,B+D} - SmallVector NewOps(AddRec->op_begin(), - AddRec->op_end()); - for (unsigned i = 0, e = OtherAddRec->getNumOperands(); i != e; ++i) { - if (i >= NewOps.size()) { - NewOps.append(OtherAddRec->op_begin()+i, - OtherAddRec->op_end()); - break; + OtherIdx < Ops.size() && isa(Ops[OtherIdx]); + ++OtherIdx) + if (AddRecLoop == cast(Ops[OtherIdx])->getLoop()) { + // Other + {A,+,B} + {C,+,D} --> Other + {A+C,+,B+D} + SmallVector AddRecOps(AddRec->op_begin(), + AddRec->op_end()); + for (; OtherIdx != Ops.size() && isa(Ops[OtherIdx]); + ++OtherIdx) + if (const SCEVAddRecExpr *AR = + dyn_cast(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; + } + AddRecOps[i] = getAddExpr(AddRecOps[i], AR->getOperand(i)); + } + Ops.erase(Ops.begin() + OtherIdx); --OtherIdx; } - NewOps[i] = getAddExpr(NewOps[i], OtherAddRec->getOperand(i)); - } - const SCEV *NewAddRec = getAddRecExpr(NewOps, AddRecLoop); - - if (Ops.size() == 2) return NewAddRec; - - Ops.erase(Ops.begin()+Idx); - Ops.erase(Ops.begin()+OtherIdx-1); - Ops.push_back(NewAddRec); - return getAddExpr(Ops); - } + Ops[Idx] = getAddRecExpr(AddRecOps, AddRecLoop); + return getAddExpr(Ops); } // Otherwise couldn't fold anything into this recurrence. Move onto the