Make instcombine O(N) instead of O(N^2) in code where the same simplifiable constant is used many times.

Part of rdar://9471075.

llvm-svn: 131979
This commit is contained in:
Eli Friedman 2011-05-24 18:52:07 +00:00
parent 5de2375db8
commit 68aab459ae
1 changed files with 11 additions and 10 deletions

View File

@ -1385,8 +1385,8 @@ static bool AddReachableCodeToWorklist(BasicBlock *BB,
Worklist.push_back(BB);
SmallVector<Instruction*, 128> InstrsForInstCombineWorklist;
SmallPtrSet<ConstantExpr*, 64> FoldedConstants;
DenseMap<ConstantExpr*, Constant*> FoldedConstants;
do {
BB = Worklist.pop_back_val();
@ -1421,14 +1421,15 @@ static bool AddReachableCodeToWorklist(BasicBlock *BB,
i != e; ++i) {
ConstantExpr *CE = dyn_cast<ConstantExpr>(i);
if (CE == 0) continue;
// If we already folded this constant, don't try again.
if (!FoldedConstants.insert(CE))
continue;
Constant *NewC = ConstantFoldConstantExpression(CE, TD);
if (NewC && NewC != CE) {
*i = NewC;
Constant*& FoldRes = FoldedConstants[CE];
if (!FoldRes)
FoldRes = ConstantFoldConstantExpression(CE, TD);
if (!FoldRes)
FoldRes = CE;
if (FoldRes != CE) {
*i = FoldRes;
MadeIRChange = true;
}
}