summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2011-05-24 18:52:07 +0000
committerEli Friedman <eli.friedman@gmail.com>2011-05-24 18:52:07 +0000
commit68aab459ae32f309279682633e260d44d322161c (patch)
treeeb120a2494660a0c8e031c96c2d1b13048d3412b /llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
parent5de2375db86f5948647a969a38afbd2ff4945be6 (diff)
downloadbcm5719-llvm-68aab459ae32f309279682633e260d44d322161c.tar.gz
bcm5719-llvm-68aab459ae32f309279682633e260d44d322161c.zip
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
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstructionCombining.cpp')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstructionCombining.cpp21
1 files changed, 11 insertions, 10 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 4468f13f631..2993629e90e 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -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;
}
}
OpenPOWER on IntegriCloud