forked from OSchip/llvm-project
Remove the option to disable LazyValueInfo in JumpThreading, as it is now
on by default and has received significant testing. llvm-svn: 113852
This commit is contained in:
parent
7fc3f5d0f7
commit
d361aac3d0
|
@ -44,15 +44,6 @@ Threshold("jump-threading-threshold",
|
|||
cl::desc("Max block size to duplicate for jump threading"),
|
||||
cl::init(6), cl::Hidden);
|
||||
|
||||
// Turn on use of LazyValueInfo.
|
||||
static cl::opt<bool>
|
||||
EnableLVI("enable-jump-threading-lvi",
|
||||
cl::desc("Use LVI for jump threading"),
|
||||
cl::init(true),
|
||||
cl::ReallyHidden);
|
||||
|
||||
|
||||
|
||||
namespace {
|
||||
/// This pass performs 'jump threading', which looks at blocks that have
|
||||
/// multiple predecessors and multiple successors. If one or more of the
|
||||
|
@ -100,10 +91,8 @@ namespace {
|
|||
bool runOnFunction(Function &F);
|
||||
|
||||
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
||||
if (EnableLVI) {
|
||||
AU.addRequired<LazyValueInfo>();
|
||||
AU.addPreserved<LazyValueInfo>();
|
||||
}
|
||||
AU.addRequired<LazyValueInfo>();
|
||||
AU.addPreserved<LazyValueInfo>();
|
||||
}
|
||||
|
||||
void FindLoopHeaders(Function &F);
|
||||
|
@ -143,7 +132,7 @@ FunctionPass *llvm::createJumpThreadingPass() { return new JumpThreading(); }
|
|||
bool JumpThreading::runOnFunction(Function &F) {
|
||||
DEBUG(dbgs() << "Jump threading on function '" << F.getName() << "'\n");
|
||||
TD = getAnalysisIfAvailable<TargetData>();
|
||||
LVI = EnableLVI ? &getAnalysis<LazyValueInfo>() : 0;
|
||||
LVI = &getAnalysis<LazyValueInfo>();
|
||||
|
||||
FindLoopHeaders(F);
|
||||
|
||||
|
@ -165,7 +154,7 @@ bool JumpThreading::runOnFunction(Function &F) {
|
|||
DEBUG(dbgs() << " JT: Deleting dead block '" << BB->getName()
|
||||
<< "' with terminator: " << *BB->getTerminator() << '\n');
|
||||
LoopHeaders.erase(BB);
|
||||
if (LVI) LVI->eraseBlock(BB);
|
||||
LVI->eraseBlock(BB);
|
||||
DeleteDeadBlock(BB);
|
||||
Changed = true;
|
||||
} else if (BranchInst *BI = dyn_cast<BranchInst>(BB->getTerminator())) {
|
||||
|
@ -190,7 +179,7 @@ bool JumpThreading::runOnFunction(Function &F) {
|
|||
// for a block even if it doesn't get erased. This isn't totally
|
||||
// awesome, but it allows us to use AssertingVH to prevent nasty
|
||||
// dangling pointer issues within LazyValueInfo.
|
||||
if (LVI) LVI->eraseBlock(BB);
|
||||
LVI->eraseBlock(BB);
|
||||
if (TryToSimplifyUncondBranchFromEmptyBlock(BB)) {
|
||||
Changed = true;
|
||||
// If we deleted BB and BB was the header of a loop, then the
|
||||
|
@ -331,29 +320,25 @@ ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB,PredValueInfo &Result){
|
|||
/// TODO: Per PR2563, we could infer value range information about a
|
||||
/// predecessor based on its terminator.
|
||||
//
|
||||
if (LVI) {
|
||||
// FIXME: change this to use the more-rich 'getPredicateOnEdge' method if
|
||||
// "I" is a non-local compare-with-a-constant instruction. This would be
|
||||
// able to handle value inequalities better, for example if the compare is
|
||||
// "X < 4" and "X < 3" is known true but "X < 4" itself is not available.
|
||||
// Perhaps getConstantOnEdge should be smart enough to do this?
|
||||
|
||||
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
|
||||
BasicBlock *P = *PI;
|
||||
// If the value is known by LazyValueInfo to be a constant in a
|
||||
// predecessor, use that information to try to thread this block.
|
||||
Constant *PredCst = LVI->getConstantOnEdge(V, P, BB);
|
||||
if (PredCst == 0 ||
|
||||
(!isa<ConstantInt>(PredCst) && !isa<UndefValue>(PredCst)))
|
||||
continue;
|
||||
|
||||
Result.push_back(std::make_pair(dyn_cast<ConstantInt>(PredCst), P));
|
||||
}
|
||||
|
||||
return !Result.empty();
|
||||
}
|
||||
// FIXME: change this to use the more-rich 'getPredicateOnEdge' method if
|
||||
// "I" is a non-local compare-with-a-constant instruction. This would be
|
||||
// able to handle value inequalities better, for example if the compare is
|
||||
// "X < 4" and "X < 3" is known true but "X < 4" itself is not available.
|
||||
// Perhaps getConstantOnEdge should be smart enough to do this?
|
||||
|
||||
return false;
|
||||
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
|
||||
BasicBlock *P = *PI;
|
||||
// If the value is known by LazyValueInfo to be a constant in a
|
||||
// predecessor, use that information to try to thread this block.
|
||||
Constant *PredCst = LVI->getConstantOnEdge(V, P, BB);
|
||||
if (PredCst == 0 ||
|
||||
(!isa<ConstantInt>(PredCst) && !isa<UndefValue>(PredCst)))
|
||||
continue;
|
||||
|
||||
Result.push_back(std::make_pair(dyn_cast<ConstantInt>(PredCst), P));
|
||||
}
|
||||
|
||||
return !Result.empty();
|
||||
}
|
||||
|
||||
/// If I is a PHI node, then we know the incoming values for any constants.
|
||||
|
@ -363,7 +348,7 @@ ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB,PredValueInfo &Result){
|
|||
if (isa<ConstantInt>(InVal) || isa<UndefValue>(InVal)) {
|
||||
ConstantInt *CI = dyn_cast<ConstantInt>(InVal);
|
||||
Result.push_back(std::make_pair(CI, PN->getIncomingBlock(i)));
|
||||
} else if (LVI) {
|
||||
} else {
|
||||
Constant *CI = LVI->getConstantOnEdge(InVal,
|
||||
PN->getIncomingBlock(i), BB);
|
||||
// LVI returns null is no value could be determined.
|
||||
|
@ -467,7 +452,7 @@ ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB,PredValueInfo &Result){
|
|||
|
||||
Value *Res = SimplifyCmpInst(Cmp->getPredicate(), LHS, RHS, TD);
|
||||
if (Res == 0) {
|
||||
if (!LVI || !isa<Constant>(RHS))
|
||||
if (!isa<Constant>(RHS))
|
||||
continue;
|
||||
|
||||
LazyValueInfo::Tristate
|
||||
|
@ -488,8 +473,7 @@ ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB,PredValueInfo &Result){
|
|||
|
||||
// If comparing a live-in value against a constant, see if we know the
|
||||
// live-in value on any predecessors.
|
||||
if (LVI && isa<Constant>(Cmp->getOperand(1)) &&
|
||||
Cmp->getType()->isIntegerTy()) {
|
||||
if (isa<Constant>(Cmp->getOperand(1)) && Cmp->getType()->isIntegerTy()) {
|
||||
if (!isa<Instruction>(Cmp->getOperand(0)) ||
|
||||
cast<Instruction>(Cmp->getOperand(0))->getParent() != BB) {
|
||||
Constant *RHSCst = cast<Constant>(Cmp->getOperand(1));
|
||||
|
@ -530,19 +514,15 @@ ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB,PredValueInfo &Result){
|
|||
}
|
||||
}
|
||||
|
||||
if (LVI) {
|
||||
// If all else fails, see if LVI can figure out a constant value for us.
|
||||
Constant *CI = LVI->getConstant(V, BB);
|
||||
ConstantInt *CInt = dyn_cast_or_null<ConstantInt>(CI);
|
||||
if (CInt) {
|
||||
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI)
|
||||
Result.push_back(std::make_pair(CInt, *PI));
|
||||
}
|
||||
|
||||
return !Result.empty();
|
||||
// If all else fails, see if LVI can figure out a constant value for us.
|
||||
Constant *CI = LVI->getConstant(V, BB);
|
||||
ConstantInt *CInt = dyn_cast_or_null<ConstantInt>(CI);
|
||||
if (CInt) {
|
||||
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI)
|
||||
Result.push_back(std::make_pair(CInt, *PI));
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
return !Result.empty();
|
||||
}
|
||||
|
||||
|
||||
|
@ -592,7 +572,7 @@ bool JumpThreading::ProcessBlock(BasicBlock *BB) {
|
|||
// Remember if SinglePred was the entry block of the function. If so, we
|
||||
// will need to move BB back to the entry position.
|
||||
bool isEntry = SinglePred == &SinglePred->getParent()->getEntryBlock();
|
||||
if (LVI) LVI->eraseBlock(SinglePred);
|
||||
LVI->eraseBlock(SinglePred);
|
||||
MergeBasicBlockIntoOnlyPred(BB);
|
||||
|
||||
if (isEntry && BB != &BB->getParent()->getEntryBlock())
|
||||
|
@ -645,75 +625,23 @@ bool JumpThreading::ProcessBlock(BasicBlock *BB) {
|
|||
|
||||
Instruction *CondInst = dyn_cast<Instruction>(Condition);
|
||||
|
||||
// If the condition is an instruction defined in another block, see if a
|
||||
// predecessor has the same condition:
|
||||
// br COND, BBX, BBY
|
||||
// BBX:
|
||||
// br COND, BBZ, BBW
|
||||
if (!LVI &&
|
||||
!Condition->hasOneUse() && // Multiple uses.
|
||||
(CondInst == 0 || CondInst->getParent() != BB)) { // Non-local definition.
|
||||
pred_iterator PI = pred_begin(BB), E = pred_end(BB);
|
||||
if (isa<BranchInst>(BB->getTerminator())) {
|
||||
for (; PI != E; ++PI) {
|
||||
BasicBlock *P = *PI;
|
||||
if (BranchInst *PBI = dyn_cast<BranchInst>(P->getTerminator()))
|
||||
if (PBI->isConditional() && PBI->getCondition() == Condition &&
|
||||
ProcessBranchOnDuplicateCond(P, BB))
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
assert(isa<SwitchInst>(BB->getTerminator()) && "Unknown jump terminator");
|
||||
for (; PI != E; ++PI) {
|
||||
BasicBlock *P = *PI;
|
||||
if (SwitchInst *PSI = dyn_cast<SwitchInst>(P->getTerminator()))
|
||||
if (PSI->getCondition() == Condition &&
|
||||
ProcessSwitchOnDuplicateCond(P, BB))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// All the rest of our checks depend on the condition being an instruction.
|
||||
if (CondInst == 0) {
|
||||
// FIXME: Unify this with code below.
|
||||
if (LVI && ProcessThreadableEdges(Condition, BB))
|
||||
if (ProcessThreadableEdges(Condition, BB))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (CmpInst *CondCmp = dyn_cast<CmpInst>(CondInst)) {
|
||||
if (!LVI &&
|
||||
(!isa<PHINode>(CondCmp->getOperand(0)) ||
|
||||
cast<PHINode>(CondCmp->getOperand(0))->getParent() != BB)) {
|
||||
// If we have a comparison, loop over the predecessors to see if there is
|
||||
// a condition with a lexically identical value.
|
||||
pred_iterator PI = pred_begin(BB), E = pred_end(BB);
|
||||
for (; PI != E; ++PI) {
|
||||
BasicBlock *P = *PI;
|
||||
if (BranchInst *PBI = dyn_cast<BranchInst>(P->getTerminator()))
|
||||
if (PBI->isConditional() && P != BB) {
|
||||
if (CmpInst *CI = dyn_cast<CmpInst>(PBI->getCondition())) {
|
||||
if (CI->getOperand(0) == CondCmp->getOperand(0) &&
|
||||
CI->getOperand(1) == CondCmp->getOperand(1) &&
|
||||
CI->getPredicate() == CondCmp->getPredicate()) {
|
||||
// TODO: Could handle things like (x != 4) --> (x == 17)
|
||||
if (ProcessBranchOnDuplicateCond(P, BB))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// For a comparison where the LHS is outside this block, it's possible
|
||||
// that we've branched on it before. Used LVI to see if we can simplify
|
||||
// the branch based on that.
|
||||
BranchInst *CondBr = dyn_cast<BranchInst>(BB->getTerminator());
|
||||
Constant *CondConst = dyn_cast<Constant>(CondCmp->getOperand(1));
|
||||
pred_iterator PI = pred_begin(BB), PE = pred_end(BB);
|
||||
if (LVI && CondBr && CondConst && CondBr->isConditional() && PI != PE &&
|
||||
if (CondBr && CondConst && CondBr->isConditional() && PI != PE &&
|
||||
(!isa<Instruction>(CondCmp->getOperand(0)) ||
|
||||
cast<Instruction>(CondCmp->getOperand(0))->getParent() != BB)) {
|
||||
// For predecessor edge, determine if the comparison is true or false
|
||||
|
@ -1455,8 +1383,7 @@ bool JumpThreading::ThreadEdge(BasicBlock *BB,
|
|||
<< ", across block:\n "
|
||||
<< *BB << "\n");
|
||||
|
||||
if (LVI)
|
||||
LVI->threadEdge(PredBB, BB, SuccBB);
|
||||
LVI->threadEdge(PredBB, BB, SuccBB);
|
||||
|
||||
// We are going to have to map operands from the original BB block to the new
|
||||
// copy of the block 'NewBB'. If there are PHI nodes in BB, evaluate them to
|
||||
|
|
Loading…
Reference in New Issue