LLVM
16.0.0git
|
This pass performs 'jump threading', which looks at blocks that have multiple predecessors and multiple successors. More...
#include "llvm/Transforms/Scalar/JumpThreading.h"
Public Member Functions | |
JumpThreadingPass (int T=-1) | |
bool | runImpl (Function &F, TargetLibraryInfo *TLI, TargetTransformInfo *TTI, LazyValueInfo *LVI, AAResults *AA, DomTreeUpdater *DTU, bool HasProfileData, std::unique_ptr< BlockFrequencyInfo > BFI, std::unique_ptr< BranchProbabilityInfo > BPI) |
PreservedAnalyses | run (Function &F, FunctionAnalysisManager &AM) |
void | releaseMemory () |
void | findLoopHeaders (Function &F) |
findLoopHeaders - We do not want jump threading to turn proper loop structures into irreducible loops. More... | |
bool | processBlock (BasicBlock *BB) |
processBlock - If there are any predecessors whose control can be threaded through to a successor, transform them now. More... | |
bool | maybeMergeBasicBlockIntoOnlyPred (BasicBlock *BB) |
Merge basic block BB into its sole predecessor if possible. More... | |
void | updateSSA (BasicBlock *BB, BasicBlock *NewBB, DenseMap< Instruction *, Value * > &ValueMapping) |
Update the SSA form. More... | |
DenseMap< Instruction *, Value * > | cloneInstructions (BasicBlock::iterator BI, BasicBlock::iterator BE, BasicBlock *NewBB, BasicBlock *PredBB) |
Clone instructions in range [BI, BE) to NewBB. More... | |
bool | tryThreadEdge (BasicBlock *BB, const SmallVectorImpl< BasicBlock * > &PredBBs, BasicBlock *SuccBB) |
tryThreadEdge - Thread an edge if it's safe and profitable to do so. More... | |
void | threadEdge (BasicBlock *BB, const SmallVectorImpl< BasicBlock * > &PredBBs, BasicBlock *SuccBB) |
threadEdge - We have decided that it is safe and profitable to factor the blocks in PredBBs to one predecessor, then thread an edge from it to SuccBB across BB. More... | |
bool | duplicateCondBranchOnPHIIntoPred (BasicBlock *BB, const SmallVectorImpl< BasicBlock * > &PredBBs) |
duplicateCondBranchOnPHIIntoPred - PredBB contains an unconditional branch to BB which contains an i1 PHI node and a conditional branch on that PHI. More... | |
bool | computeValueKnownInPredecessorsImpl (Value *V, BasicBlock *BB, jumpthreading::PredValueInfo &Result, jumpthreading::ConstantPreference Preference, DenseSet< Value * > &RecursionSet, Instruction *CxtI=nullptr) |
computeValueKnownInPredecessors - Given a basic block BB and a value V, see if we can infer that the value is a known ConstantInt/BlockAddress or undef in any of our predecessors. More... | |
bool | computeValueKnownInPredecessors (Value *V, BasicBlock *BB, jumpthreading::PredValueInfo &Result, jumpthreading::ConstantPreference Preference, Instruction *CxtI=nullptr) |
Constant * | evaluateOnPredecessorEdge (BasicBlock *BB, BasicBlock *PredPredBB, Value *cond) |
bool | maybethreadThroughTwoBasicBlocks (BasicBlock *BB, Value *Cond) |
Attempt to thread through two successive basic blocks. More... | |
void | threadThroughTwoBasicBlocks (BasicBlock *PredPredBB, BasicBlock *PredBB, BasicBlock *BB, BasicBlock *SuccBB) |
bool | processThreadableEdges (Value *Cond, BasicBlock *BB, jumpthreading::ConstantPreference Preference, Instruction *CxtI=nullptr) |
bool | processBranchOnPHI (PHINode *PN) |
processBranchOnPHI - We have an otherwise unthreadable conditional branch on a PHI node (or freeze PHI) in the current block. More... | |
bool | processBranchOnXOR (BinaryOperator *BO) |
processBranchOnXOR - We have an otherwise unthreadable conditional branch on a xor instruction in the current block. More... | |
bool | processImpliedCondition (BasicBlock *BB) |
bool | simplifyPartiallyRedundantLoad (LoadInst *LI) |
simplifyPartiallyRedundantLoad - If LoadI is an obviously partially redundant load instruction, eliminate it by replacing it with a PHI node. More... | |
void | unfoldSelectInstr (BasicBlock *Pred, BasicBlock *BB, SelectInst *SI, PHINode *SIUse, unsigned Idx) |
bool | tryToUnfoldSelect (CmpInst *CondCmp, BasicBlock *BB) |
tryToUnfoldSelect - Look for blocks of the form bb1: a = select br bb2 More... | |
bool | tryToUnfoldSelect (SwitchInst *SI, BasicBlock *BB) |
bool | tryToUnfoldSelectInCurrBB (BasicBlock *BB) |
tryToUnfoldSelectInCurrBB - Look for PHI/Select or PHI/CMP/Select in the same BB in the form bb: p = phi [false, bb1], [true, bb2], [false, bb3], [true, bb4], ... More... | |
bool | processGuards (BasicBlock *BB) |
Try to propagate a guard from the current BB into one of its predecessors in case if another branch of execution implies that the condition of this guard is always true. More... | |
bool | threadGuard (BasicBlock *BB, IntrinsicInst *Guard, BranchInst *BI) |
Try to propagate the guard from BB which is the lower block of a diamond to one of its branches, in case if diamond's condition implies guard's condition. More... | |
![]() | |
void | printPipeline (raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName) |
Additional Inherited Members | |
![]() | |
static StringRef | name () |
Gets the name of the pass we are mixed into. More... | |
This pass performs 'jump threading', which looks at blocks that have multiple predecessors and multiple successors.
If one or more of the predecessors of the block can be proven to always jump to one of the successors, we forward the edge from the predecessor to the successor by duplicating the contents of this block.
An example of when this can occur is code like this:
if () { ... X = 4; } if (X < 3) {
In this case, the unconditional branch at the end of the first if can be revectored to the false side of the second if.
Definition at line 77 of file JumpThreading.h.
JumpThreadingPass::JumpThreadingPass | ( | int | T = -1 | ) |
Definition at line 175 of file JumpThreading.cpp.
References BBDuplicateThreshold, and T.
DenseMap< Instruction *, Value * > JumpThreadingPass::cloneInstructions | ( | BasicBlock::iterator | BI, |
BasicBlock::iterator | BE, | ||
BasicBlock * | NewBB, | ||
BasicBlock * | PredBB | ||
) |
Clone instructions in range [BI, BE) to NewBB.
For PHI nodes, we only clone arguments that come from PredBB. Return the map from the variables in the source basic block to the variables in the newly created basic block.
Definition at line 2056 of file JumpThreading.cpp.
References llvm::adaptNoAliasScopes(), llvm::PHINode::addIncoming(), llvm::cloneNoAliasScopes(), Context, llvm::PHINode::Create(), llvm::numbers::e, llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::end(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::find(), llvm::BasicBlock::getContext(), llvm::PHINode::getIncomingValueForBlock(), llvm::BasicBlock::getInstList(), llvm::Value::getName(), llvm::Value::getType(), i, I, and llvm::identifyNoAliasScopesToClone().
|
inline |
Definition at line 134 of file JumpThreading.h.
References BB, and computeValueKnownInPredecessorsImpl().
bool JumpThreadingPass::computeValueKnownInPredecessorsImpl | ( | Value * | V, |
BasicBlock * | BB, | ||
jumpthreading::PredValueInfo & | Result, | ||
jumpthreading::ConstantPreference | Preference, | ||
DenseSet< Value * > & | RecursionSet, | ||
Instruction * | CxtI = nullptr |
||
) |
computeValueKnownInPredecessors - Given a basic block BB and a value V, see if we can infer that the value is a known ConstantInt/BlockAddress or undef in any of our predecessors.
If so, return the known list of value and pred BB in the result vector.
This returns true if there were any known values.
TODO: Per PR2563, we could infer value range information about a predecessor based on its terminator.
If I is a PHI node, then we know the incoming values for any constants.
Definition at line 633 of file JumpThreading.cpp.
References llvm::ConstantRange::add(), assert(), BB, Cond, llvm::ConstantFoldBinaryOpOperands(), llvm::ConstantRange::contains(), llvm::SmallPtrSetImpl< PtrType >::count(), DL, llvm::Value::DoPHITranslation(), llvm::numbers::e, llvm::erase_if(), llvm::tgtok::FalseVal, llvm::ConstantInt::get(), llvm::ConstantExpr::getCast(), llvm::ConstantExpr::getCompare(), llvm::Value::getContext(), llvm::Module::getDataLayout(), llvm::ConstantInt::getFalse(), llvm::PHINode::getIncomingBlock(), llvm::PHINode::getIncomingValue(), llvm::Type::getInt1Ty(), getKnownConstant(), llvm::Instruction::getModule(), llvm::ConstantExpr::getNot(), llvm::PHINode::getNumIncomingValues(), llvm::Instruction::getParent(), getParent(), llvm::ConstantInt::getTrue(), llvm::ConstantInt::getValue(), i, I, llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::insert(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::ConstantRange::inverse(), llvm::isGuaranteedNotToBeUndefOrPoison(), llvm::Type::isVectorTy(), LHS, llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_LogicalAnd(), llvm::PatternMatch::m_LogicalOr(), llvm::PatternMatch::m_Value(), llvm::ConstantRange::makeExactICmpRegion(), llvm::PatternMatch::match(), P, llvm::predecessors(), RHS, SI, llvm::simplifyCmpInst(), llvm::Sched::Source, llvm::tgtok::TrueVal, llvm::LazyValueInfo::Unknown, and llvm::jumpthreading::WantInteger.
Referenced by computeValueKnownInPredecessors().
bool JumpThreadingPass::duplicateCondBranchOnPHIIntoPred | ( | BasicBlock * | BB, |
const SmallVectorImpl< BasicBlock * > & | PredBBs | ||
) |
duplicateCondBranchOnPHIIntoPred - PredBB contains an unconditional branch to BB which contains an i1 PHI node and a conditional branch on that PHI.
If we can duplicate the contents of BB up into PredBB do so now, this improves the odds that the branch will be on an analyzable instruction like a compare.
Definition at line 2590 of file JumpThreading.cpp.
References assert(), BB, llvm::dbgs(), llvm::DominatorTreeBase< BasicBlock, false >::Delete, llvm::numbers::e, llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::end(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::find(), llvm::PHINode::getIncomingValueForBlock(), llvm::BasicBlock::getInstList(), llvm::ilist_node_impl< OptionsT >::getIterator(), getJumpThreadDuplicationCost(), llvm::Value::getName(), llvm::BasicBlock::getTerminator(), i, I, llvm::DominatorTreeBase< BasicBlock, false >::Insert, llvm::BranchInst::isUnconditional(), IV, LLVM_DEBUG, llvm::simplifyInstruction(), and llvm::SplitEdge().
Constant * JumpThreadingPass::evaluateOnPredecessorEdge | ( | BasicBlock * | BB, |
BasicBlock * | PredPredBB, | ||
Value * | cond | ||
) |
Definition at line 1572 of file JumpThreading.cpp.
References assert(), BB, llvm::ConstantExpr::getCompare(), and I.
void JumpThreadingPass::findLoopHeaders | ( | Function & | F | ) |
findLoopHeaders - We do not want jump threading to turn proper loop structures into irreducible loops.
Doing this breaks up the loop nesting hierarchy and pessimizes later transformations. To prevent this from happening, we first have to find the loop headers. Here we approximate this by finding targets of backedges in the CFG.
Note that there definitely are cases when we want to allow threading of edges across a loop header. For example, threading a jump from outside the loop (the preheader) to an exit block of the loop is definitely profitable. It is also almost always profitable to thread backedges from within the loop to exit blocks, and is often profitable to thread backedges to other blocks within the loop (forming a nested loop). This simple analysis is not rich enough to track all of these properties and keep it up-to-date as the CFG mutates, so we don't allow any of these transformations.
Definition at line 600 of file JumpThreading.cpp.
References F, and llvm::FindFunctionBackedges().
bool JumpThreadingPass::maybeMergeBasicBlockIntoOnlyPred | ( | BasicBlock * | BB | ) |
Merge basic block BB into its sole predecessor if possible.
Definition at line 1959 of file JumpThreading.cpp.
References BB, llvm::Instruction::getNumSuccessors(), llvm::BasicBlock::getTerminator(), hasAddressTakenAndUsed(), llvm::Instruction::isExceptionalTerminator(), llvm::isGuaranteedToTransferExecutionToSuccessor(), and llvm::MergeBasicBlockIntoOnlyPred().
bool JumpThreadingPass::maybethreadThroughTwoBasicBlocks | ( | BasicBlock * | BB, |
Value * | Cond | ||
) |
Attempt to thread through two successive basic blocks.
Definition at line 2105 of file JumpThreading.cpp.
References BB, Cond, llvm::dbgs(), getJumpThreadDuplicationCost(), llvm::Value::getName(), llvm::BasicBlock::getSinglePredecessor(), llvm::BranchInst::getSuccessor(), llvm::BasicBlock::getTerminator(), llvm::is_contained(), llvm::BasicBlock::isEHPad(), llvm::BranchInst::isUnconditional(), LLVM_DEBUG, P, llvm::predecessors(), and llvm::successors().
bool JumpThreadingPass::processBlock | ( | BasicBlock * | BB | ) |
processBlock - If there are any predecessors whose control can be threaded through to a successor, transform them now.
Definition at line 1024 of file JumpThreading.cpp.
References BB, llvm::ConstantFoldInstruction(), llvm::ConstantFoldTerminator(), llvm::BranchInst::Create(), llvm::dbgs(), llvm::DominatorTreeBase< BasicBlock, false >::Delete, llvm::numbers::e, llvm::Instruction::eraseFromParent(), getBestDestForJumpOnUndef(), llvm::ConstantInt::getFalse(), getKnownConstant(), llvm::Instruction::getNumSuccessors(), llvm::Instruction::getOpcode(), llvm::Instruction::getParent(), llvm::Instruction::getSuccessor(), llvm::ConstantInt::getTrue(), i, I, llvm::isInstructionTriviallyDead(), LLVM_DEBUG, llvm::pred_empty(), llvm::BasicBlock::removePredecessor(), replaceFoldableUses(), llvm::MipsISD::Ret, SI, llvm::Value::stripPointerCasts(), llvm::MCID::Terminator, llvm::LazyValueInfo::True, llvm::LazyValueInfo::Unknown, updatePredecessorProfileMetadata(), llvm::jumpthreading::WantBlockAddress, and llvm::jumpthreading::WantInteger.
bool JumpThreadingPass::processBranchOnPHI | ( | PHINode * | PN | ) |
processBranchOnPHI - We have an otherwise unthreadable conditional branch on a PHI node (or freeze PHI) in the current block.
See if there are any simplifications we can do based on inputs to the phi node.
Definition at line 1792 of file JumpThreading.cpp.
References BB, llvm::numbers::e, llvm::PHINode::getIncomingBlock(), llvm::PHINode::getNumIncomingValues(), llvm::Instruction::getParent(), llvm::BasicBlock::getTerminator(), i, and llvm::SmallVectorImpl< T >::resize().
bool JumpThreadingPass::processBranchOnXOR | ( | BinaryOperator * | BO | ) |
processBranchOnXOR - We have an otherwise unthreadable conditional branch on a xor instruction in the current block.
See if there are any simplifications we can do based on inputs to the xor.
Definition at line 1824 of file JumpThreading.cpp.
References llvm::any_of(), assert(), BB, llvm::Instruction::eraseFromParent(), llvm::UndefValue::get(), llvm::ConstantInt::getFalse(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::BasicBlock::getTerminator(), llvm::ConstantInt::getTrue(), llvm::Value::getType(), llvm::ConstantInt::isZero(), llvm::Value::replaceAllUsesWith(), llvm::User::setOperand(), and llvm::jumpthreading::WantInteger.
bool JumpThreadingPass::processGuards | ( | BasicBlock * | BB | ) |
Try to propagate a guard from the current BB into one of its predecessors in case if another branch of execution implies that the condition of this guard is always true.
Currently we only process the simplest case that looks like:
Start: cond = ... br i1 cond, label T1, label F1 T1: br label Merge F1: br label Merge Merge: condGuard = ... call void(i1, ...) @llvm.experimental.guard( i1 condGuard )[ "deopt"() ]
And cond either implies condGuard or !condGuard. In this case all the instructions before the guard can be duplicated in both branches, and the guard is then threaded to one of them.
Definition at line 2953 of file JumpThreading.cpp.
References BB, llvm::BasicBlock::getSinglePredecessor(), I, llvm::isGuard(), llvm::pred_begin(), and llvm::pred_end().
bool JumpThreadingPass::processImpliedCondition | ( | BasicBlock * | BB | ) |
Definition at line 1223 of file JumpThreading.cpp.
References BB, Cond, llvm::BranchInst::Create(), llvm::DominatorTreeBase< BasicBlock, false >::Delete, DL, llvm::BasicBlock::getSinglePredecessor(), llvm::BasicBlock::getTerminator(), ImplicationSearchThreshold, llvm::isImpliedCondition(), llvm::BasicBlock::removePredecessor(), and llvm::Instruction::setDebugLoc().
bool JumpThreadingPass::processThreadableEdges | ( | Value * | Cond, |
BasicBlock * | BB, | ||
jumpthreading::ConstantPreference | Preference, | ||
Instruction * | CxtI = nullptr |
||
) |
Definition at line 1612 of file JumpThreading.cpp.
References assert(), BB, Cond, llvm::BranchInst::Create(), llvm::dbgs(), llvm::DominatorTreeBase< BasicBlock, false >::Delete, llvm::SmallVectorImpl< T >::emplace_back(), llvm::erase_if(), findMostPopularDest(), getBestDestForJumpOnUndef(), llvm::BasicBlock::getTerminator(), isZero(), LLVM_DEBUG, replaceFoldableUses(), SI, llvm::successors(), and llvm::M68kBeads::Term.
|
inline |
Definition at line 107 of file JumpThreading.h.
PreservedAnalyses JumpThreadingPass::run | ( | Function & | F, |
FunctionAnalysisManager & | AM | ||
) |
Definition at line 335 of file JumpThreading.cpp.
References llvm::PreservedAnalyses::all(), llvm::AMDGPUISD::BFI, llvm::dbgs(), F, llvm::AnalysisManager< IRUnitT, ExtraArgTs >::getResult(), llvm::TargetTransformInfo::hasBranchDivergence(), llvm::DomTreeUpdater::Lazy, move, llvm::PreservedAnalyses::preserve(), PrintLVIAfterJumpThreading, llvm::DominatorTreeBase< NodeT, IsPostDom >::reset(), and runImpl().
bool JumpThreadingPass::runImpl | ( | Function & | F, |
TargetLibraryInfo * | TLI, | ||
TargetTransformInfo * | TTI, | ||
LazyValueInfo * | LVI, | ||
AAResults * | AA, | ||
DomTreeUpdater * | DTU, | ||
bool | HasProfileData, | ||
std::unique_ptr< BlockFrequencyInfo > | BFI, | ||
std::unique_ptr< BranchProbabilityInfo > | BPI | ||
) |
Definition at line 371 of file JumpThreading.cpp.
References assert(), BB, BBDuplicateThreshold, llvm::AMDGPUISD::BFI, llvm::SmallPtrSetImpl< PtrType >::count(), llvm::dbgs(), llvm::DeleteDeadBlock(), F, llvm::Intrinsic::getName(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::DominatorTree::isReachableFromEntry(), LLVM_DEBUG, move, llvm::pred_empty(), llvm::RemoveRedundantDbgInstrs(), ThreadAcrossLoopHeaders, and llvm::TryToSimplifyUncondBranchFromEmptyBlock().
bool JumpThreadingPass::simplifyPartiallyRedundantLoad | ( | LoadInst * | LoadI | ) |
simplifyPartiallyRedundantLoad - If LoadI is an obviously partially redundant load instruction, eliminate it by replacing it with a PHI node.
This is an important optimization that encourages jump threading, and needs to be run interlaced with other jump threading tasks.
Definition at line 1300 of file JumpThreading.cpp.
References llvm::PHINode::addIncoming(), llvm::array_pod_sort(), assert(), llvm::BasicBlock::begin(), llvm::combineMetadataForCSE(), llvm::SmallPtrSetImpl< PtrType >::count(), llvm::PHINode::Create(), llvm::CastInst::CreateBitOrPointerCast(), llvm::DefMaxInstsToScan, DL, llvm::Value::DoPHITranslation(), llvm::SmallVectorImpl< T >::emplace_back(), llvm::BasicBlock::end(), llvm::Instruction::eraseFromParent(), llvm::FindAvailableLoadedValue(), llvm::findAvailablePtrLoadStore(), llvm::BasicBlock::front(), llvm::PoisonValue::get(), llvm::Instruction::getAAMetadata(), llvm::LoadInst::getAlign(), llvm::Module::getDataLayout(), llvm::Instruction::getDebugLoc(), llvm::Instruction::getModule(), llvm::Value::getName(), llvm::Instruction::getNumSuccessors(), llvm::User::getOperand(), llvm::LoadInst::getOrdering(), llvm::Instruction::getParent(), llvm::BasicBlock::getSinglePredecessor(), llvm::LoadInst::getSyncScopeID(), llvm::BasicBlock::getTerminator(), llvm::Value::getType(), I, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::Instruction::isAtomic(), llvm::BasicBlock::isEHPad(), llvm::isGuaranteedToTransferExecutionToSuccessor(), isOpDefinedInBlock(), llvm::isSafeToSpeculativelyExecute(), llvm::LoadInst::isUnordered(), llvm::lower_bound(), P, PB(), llvm::LocationSize::precise(), llvm::pred_begin(), llvm::pred_end(), llvm::predecessors(), llvm::Value::replaceAllUsesWith(), llvm::Instruction::setAAMetadata(), llvm::Instruction::setDebugLoc(), llvm::SmallPtrSetImplBase::size(), and llvm::Value::takeName().
void JumpThreadingPass::threadEdge | ( | BasicBlock * | BB, |
const SmallVectorImpl< BasicBlock * > & | PredBBs, | ||
BasicBlock * | SuccBB | ||
) |
threadEdge - We have decided that it is safe and profitable to factor the blocks in PredBBs to one predecessor, then thread an edge from it to SuccBB across BB.
Transform the IR to reflect this change.
Definition at line 2350 of file JumpThreading.cpp.
References addPHINodeEntriesForMappedBlock(), assert(), BB, llvm::AMDGPUISD::BFI, llvm::BasicBlock::Create(), llvm::BranchInst::Create(), llvm::dbgs(), llvm::DominatorTreeBase< BasicBlock, false >::Delete, llvm::numbers::e, llvm::Value::getName(), llvm::Instruction::getNumSuccessors(), llvm::Instruction::getSuccessor(), llvm::BasicBlock::getTerminator(), i, llvm::DominatorTreeBase< BasicBlock, false >::Insert, LLVM_DEBUG, llvm::BasicBlock::moveAfter(), llvm::Instruction::setDebugLoc(), llvm::Instruction::setSuccessor(), and llvm::SimplifyInstructionsInBlock().
bool JumpThreadingPass::threadGuard | ( | BasicBlock * | BB, |
IntrinsicInst * | Guard, | ||
BranchInst * | BI | ||
) |
Try to propagate the guard from BB which is the lower block of a diamond to one of its branches, in case if diamond's condition implies guard's condition.
Definition at line 2987 of file JumpThreading.cpp.
References llvm::PHINode::addIncoming(), assert(), BB, llvm::Cost, llvm::PHINode::Create(), llvm::dbgs(), DL, llvm::DuplicateInstructionsInSplitBetween(), llvm::CallBase::getArgOperand(), llvm::BranchInst::getCondition(), getJumpThreadDuplicationCost(), llvm::Value::getName(), llvm::ilist_node_with_parent< NodeTy, ParentTy, Options >::getNextNode(), llvm::BranchInst::getNumSuccessors(), llvm::BranchInst::getSuccessor(), llvm::Instruction::insertBefore(), llvm::BranchInst::isConditional(), llvm::isImpliedCondition(), LLVM_DEBUG, llvm::reverse(), and ToRemove.
void JumpThreadingPass::threadThroughTwoBasicBlocks | ( | BasicBlock * | PredPredBB, |
BasicBlock * | PredBB, | ||
BasicBlock * | BB, | ||
BasicBlock * | SuccBB | ||
) |
Definition at line 2245 of file JumpThreading.cpp.
References addPHINodeEntriesForMappedBlock(), BB, llvm::BasicBlock::begin(), llvm::AMDGPUISD::BFI, llvm::BasicBlock::Create(), llvm::dbgs(), llvm::DominatorTreeBase< BasicBlock, false >::Delete, llvm::numbers::e, llvm::BasicBlock::end(), llvm::BasicBlock::getContext(), llvm::Value::getName(), llvm::Instruction::getNumSuccessors(), llvm::BasicBlock::getParent(), llvm::Instruction::getSuccessor(), llvm::BranchInst::getSuccessor(), llvm::BasicBlock::getTerminator(), i, llvm::DominatorTreeBase< BasicBlock, false >::Insert, LLVM_DEBUG, llvm::BasicBlock::moveAfter(), llvm::BasicBlock::removePredecessor(), llvm::Instruction::setSuccessor(), and llvm::SimplifyInstructionsInBlock().
bool JumpThreadingPass::tryThreadEdge | ( | BasicBlock * | BB, |
const SmallVectorImpl< BasicBlock * > & | PredBBs, | ||
BasicBlock * | SuccBB | ||
) |
tryThreadEdge - Thread an edge if it's safe and profitable to do so.
Definition at line 2311 of file JumpThreading.cpp.
References BB, llvm::dbgs(), getJumpThreadDuplicationCost(), llvm::Value::getName(), and LLVM_DEBUG.
bool JumpThreadingPass::tryToUnfoldSelect | ( | CmpInst * | CondCmp, |
BasicBlock * | BB | ||
) |
tryToUnfoldSelect - Look for blocks of the form bb1: a = select br bb2
bb2: p = phi [a, bb1] ... c = icmp p br i1 c
And expand the select into a branch structure if one of its arms allows c to be folded. This later enables threading from bb1 over bb2.
Definition at line 2792 of file JumpThreading.cpp.
References BB, E, llvm::PHINode::getIncomingBlock(), llvm::PHINode::getIncomingValue(), llvm::PHINode::getNumIncomingValues(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::CmpInst::getPredicate(), llvm::BasicBlock::getTerminator(), I, llvm::BranchInst::isConditional(), llvm::BranchInst::isUnconditional(), SI, and llvm::LazyValueInfo::Unknown.
bool JumpThreadingPass::tryToUnfoldSelect | ( | SwitchInst * | SI, |
BasicBlock * | BB | ||
) |
Definition at line 2754 of file JumpThreading.cpp.
References BB, E, llvm::PHINode::getIncomingBlock(), llvm::PHINode::getIncomingValue(), llvm::PHINode::getNumIncomingValues(), llvm::Instruction::getParent(), llvm::BasicBlock::getTerminator(), llvm::Value::hasOneUse(), I, llvm::BranchInst::isUnconditional(), and SI.
bool JumpThreadingPass::tryToUnfoldSelectInCurrBB | ( | BasicBlock * | BB | ) |
tryToUnfoldSelectInCurrBB - Look for PHI/Select or PHI/CMP/Select in the same BB in the form bb: p = phi [false, bb1], [true, bb2], [false, bb3], [true, bb4], ...
s = select p, trueval, falseval
or
bb: p = phi [0, bb1], [1, bb2], [0, bb3], [1, bb4], ... c = cmp p, 0 s = select c, trueval, falseval
And expand the select into a branch structure. This later enables jump-threading over bb in this pass.
Using the similar approach of SimplifyCFG::FoldCondBranchOnPHI(), unfold select if the associated PHI has at least one constant. If the unfolded select is not jump-threaded, it will be folded again in the later optimizations.
Definition at line 2853 of file JumpThreading.cpp.
References llvm::PHINode::addIncoming(), llvm::all_of(), BB, Cond, llvm::PHINode::Create(), llvm::DominatorTreeBase< BasicBlock, false >::Delete, llvm::Instruction::getNumSuccessors(), llvm::BasicBlock::getTerminator(), llvm::DominatorTreeBase< BasicBlock, false >::Insert, llvm::isGuaranteedNotToBeUndefOrPoison(), llvm::PatternMatch::m_CombineOr(), llvm::PatternMatch::m_LogicalAnd(), llvm::PatternMatch::m_LogicalOr(), llvm::PatternMatch::match(), SI, llvm::SplitBlockAndInsertIfThen(), llvm::successors(), llvm::M68kBeads::Term, and llvm::Value::uses().
void JumpThreadingPass::unfoldSelectInstr | ( | BasicBlock * | Pred, |
BasicBlock * | BB, | ||
SelectInst * | SI, | ||
PHINode * | SIUse, | ||
unsigned | Idx | ||
) |
Definition at line 2718 of file JumpThreading.cpp.
References llvm::PHINode::addIncoming(), BB, llvm::BasicBlock::Create(), llvm::BranchInst::Create(), llvm::BasicBlock::end(), llvm::Instruction::getDebugLoc(), llvm::BasicBlock::getInstList(), llvm::BasicBlock::getTerminator(), llvm::DominatorTreeBase< BasicBlock, false >::Insert, llvm::Instruction::removeFromParent(), llvm::PHINode::setIncomingValue(), and SI.
void JumpThreadingPass::updateSSA | ( | BasicBlock * | BB, |
BasicBlock * | NewBB, | ||
DenseMap< Instruction *, Value * > & | ValueMapping | ||
) |
Update the SSA form.
NewBB contains instructions that are copied from BB. ValueMapping maps old values in BB to new ones in NewBB.
Definition at line 2010 of file JumpThreading.cpp.
References llvm::SSAUpdater::AddAvailableValue(), BB, llvm::dbgs(), I, llvm::SSAUpdater::Initialize(), LLVM_DEBUG, llvm::SmallVectorImpl< T >::pop_back_val(), and llvm::SSAUpdater::RewriteUse().