Skip to content

Commit d91a796

Browse files
committed
remove more code subsumed by r86264
llvm-svn: 86270
1 parent 33e0c99 commit d91a796

File tree

1 file changed

+17
-83
lines changed

1 file changed

+17
-83
lines changed

llvm/lib/Transforms/Scalar/JumpThreading.cpp

Lines changed: 17 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ namespace {
8989
bool ProcessSwitchOnDuplicateCond(BasicBlock *PredBB, BasicBlock *DestBB);
9090

9191
bool ProcessJumpOnPHI(PHINode *PN);
92-
bool ProcessBranchOnCompare(CmpInst *Cmp, BasicBlock *BB);
9392

9493
bool SimplifyPartiallyRedundantLoad(LoadInst *LI);
9594
};
@@ -480,34 +479,25 @@ bool JumpThreading::ProcessBlock(BasicBlock *BB) {
480479
return ProcessJumpOnPHI(PN);
481480

482481
if (CmpInst *CondCmp = dyn_cast<CmpInst>(CondInst)) {
483-
if (isa<PHINode>(CondCmp->getOperand(0))) {
484-
// If we have "br (phi != 42)" and the phi node has any constant values
485-
// as operands, we can thread through this block.
486-
//
487-
// If we have "br (cmp phi, x)" and the phi node contains x such that the
488-
// comparison uniquely identifies the branch target, we can thread
489-
// through this block.
490-
491-
if (ProcessBranchOnCompare(CondCmp, BB))
492-
return true;
493-
}
494-
495-
// If we have a comparison, loop over the predecessors to see if there is
496-
// a condition with a lexically identical value.
497-
pred_iterator PI = pred_begin(BB), E = pred_end(BB);
498-
for (; PI != E; ++PI)
499-
if (BranchInst *PBI = dyn_cast<BranchInst>((*PI)->getTerminator()))
500-
if (PBI->isConditional() && *PI != BB) {
501-
if (CmpInst *CI = dyn_cast<CmpInst>(PBI->getCondition())) {
502-
if (CI->getOperand(0) == CondCmp->getOperand(0) &&
503-
CI->getOperand(1) == CondCmp->getOperand(1) &&
504-
CI->getPredicate() == CondCmp->getPredicate()) {
505-
// TODO: Could handle things like (x != 4) --> (x == 17)
506-
if (ProcessBranchOnDuplicateCond(*PI, BB))
507-
return true;
482+
if (!isa<PHINode>(CondCmp->getOperand(0)) ||
483+
cast<PHINode>(CondCmp->getOperand(0))->getParent() != BB) {
484+
// If we have a comparison, loop over the predecessors to see if there is
485+
// a condition with a lexically identical value.
486+
pred_iterator PI = pred_begin(BB), E = pred_end(BB);
487+
for (; PI != E; ++PI)
488+
if (BranchInst *PBI = dyn_cast<BranchInst>((*PI)->getTerminator()))
489+
if (PBI->isConditional() && *PI != BB) {
490+
if (CmpInst *CI = dyn_cast<CmpInst>(PBI->getCondition())) {
491+
if (CI->getOperand(0) == CondCmp->getOperand(0) &&
492+
CI->getOperand(1) == CondCmp->getOperand(1) &&
493+
CI->getPredicate() == CondCmp->getPredicate()) {
494+
// TODO: Could handle things like (x != 4) --> (x == 17)
495+
if (ProcessBranchOnDuplicateCond(*PI, BB))
496+
return true;
497+
}
508498
}
509499
}
510-
}
500+
}
511501
}
512502

513503
// Check for some cases that are worth simplifying. Right now we want to look
@@ -1028,62 +1018,6 @@ bool JumpThreading::ProcessJumpOnPHI(PHINode *PN) {
10281018
return false;
10291019
}
10301020

1031-
/// ProcessBranchOnCompare - We found a branch on a comparison between a phi
1032-
/// node and a value. If we can identify when the comparison is true between
1033-
/// the phi inputs and the value, we can fold the compare for that edge and
1034-
/// thread through it.
1035-
bool JumpThreading::ProcessBranchOnCompare(CmpInst *Cmp, BasicBlock *BB) {
1036-
PHINode *PN = cast<PHINode>(Cmp->getOperand(0));
1037-
Value *RHS = Cmp->getOperand(1);
1038-
1039-
// If the phi isn't in the current block, an incoming edge to this block
1040-
// doesn't control the destination.
1041-
if (PN->getParent() != BB)
1042-
return false;
1043-
1044-
// We can do this simplification if any comparisons fold to true or false.
1045-
// See if any do.
1046-
Value *PredVal = 0;
1047-
bool TrueDirection = false;
1048-
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
1049-
PredVal = PN->getIncomingValue(i);
1050-
1051-
Constant *Res = GetResultOfComparison(Cmp->getPredicate(), PredVal, RHS);
1052-
if (!Res) {
1053-
PredVal = 0;
1054-
continue;
1055-
}
1056-
1057-
// If this folded to a constant expr, we can't do anything.
1058-
if (ConstantInt *ResC = dyn_cast<ConstantInt>(Res)) {
1059-
TrueDirection = ResC->getZExtValue();
1060-
break;
1061-
}
1062-
// If this folded to undef, just go the false way.
1063-
if (isa<UndefValue>(Res)) {
1064-
TrueDirection = false;
1065-
break;
1066-
}
1067-
1068-
// Otherwise, we can't fold this input.
1069-
PredVal = 0;
1070-
}
1071-
1072-
// If no match, bail out.
1073-
if (PredVal == 0)
1074-
return false;
1075-
1076-
// If so, we can actually do this threading. Merge any common predecessors
1077-
// that will act the same.
1078-
BasicBlock *PredBB = FactorCommonPHIPreds(PN, PredVal);
1079-
1080-
// Next, get our successor.
1081-
BasicBlock *SuccBB = BB->getTerminator()->getSuccessor(!TrueDirection);
1082-
1083-
// Ok, try to thread it!
1084-
return ThreadEdge(BB, PredBB, SuccBB);
1085-
}
1086-
10871021

10881022
/// AddPHINodeEntriesForMappedBlock - We're adding 'NewPred' as a new
10891023
/// predecessor to the PHIBB block. If it has PHI nodes, add entries for

0 commit comments

Comments
 (0)