[llvm] r290760 - [CVP] Adjust iteration order to reduce the amount of work required
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 30 10:00:56 PST 2016
Author: reames
Date: Fri Dec 30 12:00:55 2016
New Revision: 290760
URL: http://llvm.org/viewvc/llvm-project?rev=290760&view=rev
Log:
[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.
Modified:
llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp?rev=290760&r1=290759&r2=290760&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp Fri Dec 30 12:00:55 2016
@@ -481,9 +481,14 @@ static Constant *getConstantAt(Value *V,
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, LazyVal
}
}
- Instruction *Term = BB.getTerminator();
+ Instruction *Term = BB->getTerminator();
switch (Term->getOpcode()) {
case Instruction::Switch:
BBChanged |= processSwitch(cast<SwitchInst>(Term), LVI);
More information about the llvm-commits
mailing list