diff options
author | Philip Reames <listmail@philipreames.com> | 2016-12-30 18:00:55 +0000 |
---|---|---|
committer | Philip Reames <listmail@philipreames.com> | 2016-12-30 18:00:55 +0000 |
commit | a570a2303c9d5331812214bfc4834ca3133b68e5 (patch) | |
tree | e77ca31d12ef75c8357af6b35a091fe18c274749 /llvm/lib | |
parent | 1e48efcfc5275f9393f1c2622183dcecd97b1264 (diff) | |
download | bcm5719-llvm-a570a2303c9d5331812214bfc4834ca3133b68e5.tar.gz bcm5719-llvm-a570a2303c9d5331812214bfc4834ca3133b68e5.zip |
[CVP] Adjust iteration order to reduce the amount of work required
CVP doesn't care about the order of blocks visited, but by using a pre-order traversal over the graph we can a) not visit unreachable blocks and b) optimize as we go so that analysis of later blocks produce slightly more precise results.
I noticed this via inspection and don't have a concrete example which points to the issue.
llvm-svn: 290760
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp index de62d9de7a8..141e99b92cd 100644 --- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp +++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp @@ -481,9 +481,14 @@ static Constant *getConstantAt(Value *V, Instruction *At, LazyValueInfo *LVI) { static bool runImpl(Function &F, LazyValueInfo *LVI) { bool FnChanged = false; - for (BasicBlock &BB : F) { + // Visiting in a pre-order depth-first traversal causes us to simplify early + // blocks before querying later blocks (which require us to analyze early + // blocks). Eagerly simplifying shallow blocks means there is strictly less + // work to do for deep blocks. This also means we don't visit unreachable + // blocks. + for (BasicBlock *BB : depth_first(&F.getEntryBlock())) { bool BBChanged = false; - for (BasicBlock::iterator BI = BB.begin(), BE = BB.end(); BI != BE;) { + for (BasicBlock::iterator BI = BB->begin(), BE = BB->end(); BI != BE;) { Instruction *II = &*BI++; switch (II->getOpcode()) { case Instruction::Select: @@ -519,7 +524,7 @@ static bool runImpl(Function &F, LazyValueInfo *LVI) { } } - Instruction *Term = BB.getTerminator(); + Instruction *Term = BB->getTerminator(); switch (Term->getOpcode()) { case Instruction::Switch: BBChanged |= processSwitch(cast<SwitchInst>(Term), LVI); |