aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms/Scalar/LoopInstSimplify.cpp
diff options
context:
space:
mode:
authorCameron Zwarich <zwarich@apple.com>2011-01-05 05:47:47 +0000
committerCameron Zwarich <zwarich@apple.com>2011-01-05 05:47:47 +0000
commit08602ab1b4b90e26d406ffb886a685c66270698c (patch)
treefd67a2b724a08e8ac16362d25d5473f93b6805d0 /lib/Transforms/Scalar/LoopInstSimplify.cpp
parente389ab16f3d98c2491dd2d8649b782203590a938 (diff)
downloadexternal_llvm-08602ab1b4b90e26d406ffb886a685c66270698c.zip
external_llvm-08602ab1b4b90e26d406ffb886a685c66270698c.tar.gz
external_llvm-08602ab1b4b90e26d406ffb886a685c66270698c.tar.bz2
Use a worklist for later iterations just like ordinary instsimplify. The next
step is to only process instructions in subloops if they have been modified by an earlier simplification. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122869 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/LoopInstSimplify.cpp')
-rw-r--r--lib/Transforms/Scalar/LoopInstSimplify.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/Transforms/Scalar/LoopInstSimplify.cpp b/lib/Transforms/Scalar/LoopInstSimplify.cpp
index 848dc40..22ec48d 100644
--- a/lib/Transforms/Scalar/LoopInstSimplify.cpp
+++ b/lib/Transforms/Scalar/LoopInstSimplify.cpp
@@ -66,6 +66,8 @@ bool LoopInstSimplify::runOnLoop(Loop *L, LPPassManager &LPM) {
L->getUniqueExitBlocks(ExitBlocks);
array_pod_sort(ExitBlocks.begin(), ExitBlocks.end());
+ SmallPtrSet<const Instruction*, 8> S1, S2, *ToSimplify = &S1, *Next = &S2;
+
SmallVector<BasicBlock*, 16> VisitStack;
SmallPtrSet<BasicBlock*, 32> Visited;
@@ -86,10 +88,22 @@ bool LoopInstSimplify::runOnLoop(Loop *L, LPPassManager &LPM) {
// Simplify instructions in the current basic block.
for (BasicBlock::iterator BI = BB->begin(), BE = BB->end(); BI != BE;) {
Instruction *I = BI++;
+
+ // The first time through the loop ToSimplify is empty and we try to
+ // simplify all instructions. On later iterations ToSimplify is not
+ // empty and we only bother simplifying instructions that are in it.
+ if (!ToSimplify->empty() && !ToSimplify->count(I))
+ continue;
+
// Don't bother simplifying unused instructions.
if (!I->use_empty()) {
Value *V = SimplifyInstruction(I, TD, DT);
if (V && LI->replacementPreservesLCSSAForm(I, V)) {
+ // Mark all uses for resimplification next time round the loop.
+ for (Value::use_iterator UI = I->use_begin(), UE = I->use_end();
+ UI != UE; ++UI)
+ Next->insert(cast<Instruction>(*UI));
+
I->replaceAllUsesWith(V);
LocalChanged = true;
++NumSimplified;
@@ -109,6 +123,11 @@ bool LoopInstSimplify::runOnLoop(Loop *L, LPPassManager &LPM) {
}
}
+ // Place the list of instructions to simplify on the next loop iteration
+ // into ToSimplify.
+ std::swap(ToSimplify, Next);
+ Next->clear();
+
Changed |= LocalChanged;
} while (LocalChanged);