[llvm-commits] [llvm] r93208 - /llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp
Chris Lattner
sabre at nondot.org
Mon Jan 11 15:41:10 PST 2010
Author: lattner
Date: Mon Jan 11 17:41:09 2010
New Revision: 93208
URL: http://llvm.org/viewvc/llvm-project?rev=93208&view=rev
Log:
some cleanup, and make it obvious that ProcessJumpOnPHI only works
on branches by renaming it and checking for a branch at the call site.
Modified:
llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp?rev=93208&r1=93207&r2=93208&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp Mon Jan 11 17:41:09 2010
@@ -102,7 +102,7 @@
bool ProcessBranchOnDuplicateCond(BasicBlock *PredBB, BasicBlock *DestBB);
bool ProcessSwitchOnDuplicateCond(BasicBlock *PredBB, BasicBlock *DestBB);
- bool ProcessJumpOnPHI(PHINode *PN);
+ bool ProcessBranchOnPHI(PHINode *PN);
bool SimplifyPartiallyRedundantLoad(LoadInst *LI);
};
@@ -550,11 +550,6 @@
}
- // See if this is a phi node in the current block.
- if (PHINode *PN = dyn_cast<PHINode>(CondInst))
- if (PN->getParent() == BB)
- return ProcessJumpOnPHI(PN);
-
if (CmpInst *CondCmp = dyn_cast<CmpInst>(CondInst)) {
if (!LVI &&
(!isa<PHINode>(CondCmp->getOperand(0)) ||
@@ -583,8 +578,6 @@
// we see one, check to see if it's partially redundant. If so, insert a PHI
// which can then be used to thread the values.
//
- // This is particularly important because reg2mem inserts loads and stores all
- // over the place, and this blocks jump threading if we don't zap them.
Value *SimplifyValue = CondInst;
if (CmpInst *CondCmp = dyn_cast<CmpInst>(SimplifyValue))
if (isa<Constant>(CondCmp->getOperand(1)))
@@ -604,9 +597,14 @@
if (ProcessThreadableEdges(CondInst, BB))
return true;
+ // If this is an otherwise-unfoldable branch on a phi node in the current
+ // block, see if we can simplify.
+ if (PHINode *PN = dyn_cast<PHINode>(CondInst))
+ if (PN->getParent() == BB && isa<BranchInst>(BB->getTerminator()))
+ return ProcessBranchOnPHI(PN);
// TODO: If we have: "br (X > 0)" and we have a predecessor where we know
- // "(X == 4)" thread through this block.
+ // "(X == 4)", thread through this block.
return false;
}
@@ -1068,24 +1066,17 @@
return ThreadEdge(BB, PredsToFactor, MostPopularDest);
}
-/// ProcessJumpOnPHI - We have a conditional branch or switch on a PHI node in
-/// the current block. See if there are any simplifications we can do based on
-/// inputs to the phi node.
+/// ProcessBranchOnPHI - We have an otherwise unthreadable conditional branch on
+/// a PHI node in the current block. See if there are any simplifications we
+/// can do based on inputs to the phi node.
///
-bool JumpThreading::ProcessJumpOnPHI(PHINode *PN) {
+bool JumpThreading::ProcessBranchOnPHI(PHINode *PN) {
BasicBlock *BB = PN->getParent();
// If any of the predecessor blocks end in an unconditional branch, we can
- // *duplicate* the jump into that block in order to further encourage jump
- // threading and to eliminate cases where we have branch on a phi of an icmp
- // (branch on icmp is much better).
-
- // We don't want to do this tranformation for switches, because we don't
- // really want to duplicate a switch.
- if (isa<SwitchInst>(BB->getTerminator()))
- return false;
-
- // Look for unconditional branch predecessors.
+ // *duplicate* the conditional branch into that block in order to further
+ // encourage jump threading and to eliminate cases where we have branch on a
+ // phi of an icmp (branch on icmp is much better).
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
BasicBlock *PredBB = PN->getIncomingBlock(i);
if (BranchInst *PredBr = dyn_cast<BranchInst>(PredBB->getTerminator()))
@@ -1098,7 +1089,6 @@
return false;
}
-
/// AddPHINodeEntriesForMappedBlock - We're adding 'NewPred' as a new
/// predecessor to the PHIBB block. If it has PHI nodes, add entries for
/// NewPred using the entries from OldPred (suitably mapped).
More information about the llvm-commits
mailing list