47 using namespace jumpthreading;
49 #define DEBUG_TYPE "jump-threading"
51 STATISTIC(NumThreads,
"Number of jumps threaded");
52 STATISTIC(NumFolds,
"Number of terminators folded");
53 STATISTIC(NumDupes,
"Number of branch blocks duplicated to eliminate phi");
57 cl::desc(
"Max block size to duplicate for jump threading"),
62 "jump-threading-implication-search-threshold",
63 cl::desc(
"The number of predecessors to search for a stronger "
64 "condition to use to thread over a weaker condition"),
68 "print-lvi-after-jump-threading",
69 cl::desc(
"Print the LazyValueInfo cache after JumpThreading"),
cl::init(
false),
115 "Jump Threading",
false,
false)
131 bool JumpThreading::runOnFunction(
Function &
F) {
134 auto TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
135 auto LVI = &getAnalysis<LazyValueInfoWrapperPass>().getLVI();
136 auto AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
137 std::unique_ptr<BlockFrequencyInfo>
BFI;
138 std::unique_ptr<BranchProbabilityInfo> BPI;
140 if (HasProfileData) {
146 bool Changed = Impl.runImpl(F, TLI, LVI, AA, HasProfileData, std::move(BFI),
149 dbgs() <<
"LVI for function '" << F.
getName() <<
"':\n";
150 LVI->printLVI(F, getAnalysis<DominatorTreeWrapperPass>().getDomTree(),
163 std::unique_ptr<BlockFrequencyInfo>
BFI;
164 std::unique_ptr<BranchProbabilityInfo> BPI;
166 if (HasProfileData) {
172 bool Changed =
runImpl(F, &TLI, &LVI, &AA, HasProfileData, std::move(BFI),
184 bool HasProfileData_,
185 std::unique_ptr<BlockFrequencyInfo> BFI_,
186 std::unique_ptr<BranchProbabilityInfo> BPI_) {
196 HasProfileData = HasProfileData_;
199 HasGuards = GuardDecl && !GuardDecl->
use_empty();
200 if (HasProfileData) {
201 BPI = std::move(BPI_);
202 BFI = std::move(BFI_);
212 bool EverChanged =
false;
234 LoopHeaders.erase(BB);
264 EverChanged |= Changed;
294 I.replaceUsesOfWith(Cond, ToVal);
306 assert(StopAt->
getParent() == BB &&
"Not an instruction from proper BB?");
318 if (isa<SwitchInst>(StopAt))
322 if (isa<IndirectBrInst>(StopAt))
333 for (; &*
I != StopAt; ++
I) {
336 if (Size > Threshold)
340 if (isa<DbgInfoIntrinsic>(
I))
continue;
343 if (isa<BitCastInst>(
I) &&
I->getType()->isPointerTy())
348 if (
I->getType()->isTokenTy() &&
I->isUsedOutsideOfBlock(BB))
358 if (
const CallInst *CI = dyn_cast<CallInst>(
I)) {
359 if (CI->cannotDuplicate() || CI->isConvergent())
363 else if (!isa<IntrinsicInst>(CI))
365 else if (!CI->getType()->isVectorTy())
370 return Size > Bonus ? Size - Bonus : 0;
392 for (
const auto &Edge : Edges)
393 LoopHeaders.insert(Edge.second);
406 if (
UndefValue *U = dyn_cast<UndefValue>(Val))
429 if (!RecursionSet.insert(std::make_pair(V, BB)).second)
434 RecursionSetRemover remover(RecursionSet, std::make_pair(V, BB));
439 Result.
push_back(std::make_pair(KC, Pred));
441 return !Result.
empty();
465 Constant *PredCst = LVI->getConstantOnEdge(V,
P, BB, CxtI);
470 return !Result.
empty();
474 if (
PHINode *PN = dyn_cast<PHINode>(I)) {
475 for (
unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
476 Value *InVal = PN->getIncomingValue(i);
478 Result.
push_back(std::make_pair(KC, PN->getIncomingBlock(i)));
480 Constant *CI = LVI->getConstantOnEdge(InVal,
481 PN->getIncomingBlock(i),
484 Result.
push_back(std::make_pair(KC, PN->getIncomingBlock(i)));
488 return !Result.
empty();
493 if (
CastInst *CI = dyn_cast<CastInst>(I)) {
497 if (!isa<PHINode>(Source) && !isa<CmpInst>(
Source))
499 ComputeValueKnownInPredecessors(Source, BB, Result, Preference, CxtI);
504 for (
auto &R : Result)
519 ComputeValueKnownInPredecessors(I->
getOperand(0), BB, LHSVals,
521 ComputeValueKnownInPredecessors(I->
getOperand(1), BB, RHSVals,
524 if (LHSVals.empty() && RHSVals.empty())
537 for (
const auto &LHSVal : LHSVals)
538 if (LHSVal.first == InterestingVal || isa<UndefValue>(LHSVal.first)) {
540 LHSKnownBBs.insert(LHSVal.second);
542 for (
const auto &RHSVal : RHSVals)
543 if (RHSVal.first == InterestingVal || isa<UndefValue>(RHSVal.first)) {
546 if (!LHSKnownBBs.count(RHSVal.second))
550 return !Result.
empty();
554 if (I->
getOpcode() == Instruction::Xor &&
556 cast<ConstantInt>(I->
getOperand(1))->isOne()) {
557 ComputeValueKnownInPredecessors(I->
getOperand(0), BB, Result,
563 for (
auto &R : Result)
572 &&
"A binary operator creating a block address?");
573 if (
ConstantInt *CI = dyn_cast<ConstantInt>(BO->getOperand(1))) {
575 ComputeValueKnownInPredecessors(BO->getOperand(0), BB, LHSVals,
579 for (
const auto &LHSVal : LHSVals) {
584 Result.
push_back(std::make_pair(KC, LHSVal.second));
588 return !Result.
empty();
592 if (
CmpInst *Cmp = dyn_cast<CmpInst>(I)) {
594 Type *CmpType = Cmp->getType();
595 Value *CmpLHS = Cmp->getOperand(0);
596 Value *CmpRHS = Cmp->getOperand(1);
611 if (!isa<Constant>(RHS))
615 ResT = LVI->getPredicateOnEdge(Pred, LHS,
616 cast<Constant>(RHS), PredBB, BB,
624 Result.
push_back(std::make_pair(KC, PredBB));
627 return !Result.
empty();
632 if (isa<Constant>(CmpRHS) && !CmpType->
isVectorTy()) {
633 Constant *CmpConst = cast<Constant>(CmpRHS);
635 if (!isa<Instruction>(CmpLHS) ||
636 cast<Instruction>(CmpLHS)->
getParent() != BB) {
641 LVI->getPredicateOnEdge(Pred, CmpLHS,
642 CmpConst,
P, BB, CxtI ? CxtI : Cmp);
650 return !Result.
empty();
657 using namespace PatternMatch;
660 if (isa<ConstantInt>(CmpConst) &&
662 if (!isa<Instruction>(AddLHS) ||
663 cast<Instruction>(AddLHS)->
getParent() != BB) {
669 AddLHS,
P, BB, CxtI ? CxtI : cast<Instruction>(CmpLHS));
671 CR = CR.
add(AddConst->getValue());
675 Pred, cast<ConstantInt>(CmpConst)->getValue());
688 return !Result.
empty();
696 ComputeValueKnownInPredecessors(I->
getOperand(0), BB, LHSVals,
699 for (
const auto &LHSVal : LHSVals) {
703 Result.
push_back(std::make_pair(KC, LHSVal.second));
706 return !Result.
empty();
716 if ((TrueVal || FalseVal) &&
717 ComputeValueKnownInPredecessors(
SI->getCondition(), BB, Conds,
719 for (
auto &
C : Conds) {
724 if (
ConstantInt *CI = dyn_cast<ConstantInt>(Cond)) {
726 KnownCond = CI->isOne();
728 assert(isa<UndefValue>(Cond) &&
"Unexpected condition value");
732 KnownCond = (TrueVal !=
nullptr);
736 if (
Constant *Val = KnownCond ? TrueVal : FalseVal)
737 Result.
push_back(std::make_pair(Val,
C.second));
740 return !Result.
empty();
745 Constant *CI = LVI->getConstant(V, BB, CxtI);
748 Result.
push_back(std::make_pair(KC, Pred));
751 return !Result.
empty();
764 unsigned MinSucc = 0;
771 if (NumPreds < MinNumPreds) {
773 MinNumPreds = NumPreds;
808 if (LoopHeaders.erase(SinglePred))
809 LoopHeaders.insert(BB);
811 LVI->eraseBlock(SinglePred);
849 if (TryToUnfoldSelectInCurrBB(BB))
853 if (HasGuards && ProcessGuards(BB))
863 if (
BranchInst *BI = dyn_cast<BranchInst>(Terminator)) {
865 if (BI->isUnconditional())
return false;
866 Condition = BI->getCondition();
867 }
else if (
SwitchInst *
SI = dyn_cast<SwitchInst>(Terminator)) {
868 Condition =
SI->getCondition();
869 }
else if (
IndirectBrInst *IB = dyn_cast<IndirectBrInst>(Terminator)) {
871 if (IB->getNumSuccessors() == 0)
return false;
880 if (
Instruction *
I = dyn_cast<Instruction>(Condition)) {
884 I->replaceAllUsesWith(SimpleVal);
886 I->eraseFromParent();
887 Condition = SimpleVal;
893 if (isa<UndefValue>(Condition)) {
899 if (i == BestSucc)
continue;
904 <<
"' folding undef terminator: " << *BBTerm <<
'\n');
915 <<
"' folding terminator: " << *BB->
getTerminator() <<
'\n');
926 if (ProcessThreadableEdges(Condition, BB, Preference, Terminator))
931 if (
CmpInst *CondCmp = dyn_cast<CmpInst>(CondInst)) {
938 if (CondBr && CondConst) {
945 LVI->getPredicateAt(CondCmp->getPredicate(), CondCmp->getOperand(0),
953 if (CondCmp->use_empty())
954 CondCmp->eraseFromParent();
962 else if (CondCmp->getParent() == BB) {
973 if (TryToUnfoldSelect(CondCmp, BB))
983 Value *SimplifyValue = CondInst;
984 if (
CmpInst *CondCmp = dyn_cast<CmpInst>(SimplifyValue))
985 if (isa<Constant>(CondCmp->getOperand(1)))
986 SimplifyValue = CondCmp->getOperand(0);
990 if (
LoadInst *LI = dyn_cast<LoadInst>(SimplifyValue))
991 if (SimplifyPartiallyRedundantLoad(LI))
998 if (ProcessThreadableEdges(CondInst, BB, Preference, Terminator))
1003 if (
PHINode *PN = dyn_cast<PHINode>(CondInst))
1004 if (PN->getParent() == BB && isa<BranchInst>(BB->
getTerminator()))
1005 return ProcessBranchOnPHI(PN);
1008 if (CondInst->
getOpcode() == Instruction::Xor &&
1010 return ProcessBranchOnXOR(cast<BinaryOperator>(CondInst));
1014 if (ProcessImpliedCondition(BB))
1022 if (!BI || !BI->isConditional())
1025 Value *Cond = BI->getCondition();
1034 if (!PBI || !PBI->isConditional())
1036 if (PBI->getSuccessor(0) != CurrentBB && PBI->getSuccessor(1) != CurrentBB)
1043 BI->getSuccessor(*Implication ? 1 : 0)->removePredecessor(BB);
1048 CurrentBB = CurrentPred;
1057 if (
Instruction *OpInst = dyn_cast<Instruction>(Op))
1058 if (OpInst->getParent() == BB)
1100 LoadInst *NLI = cast<LoadInst>(AvailableVal);
1107 if (AvailableVal->getType() != LI->
getType())
1118 if (BBIt != LoadBB->
begin())
1128 AvailablePredsTy AvailablePreds;
1136 if (!PredsScanned.
insert(PredBB).second)
1139 BBIt = PredBB->end();
1140 unsigned NumScanedInst = 0;
1141 Value *PredAvailable =
nullptr;
1150 AA, &IsLoadCSE, &NumScanedInst);
1155 while (!PredAvailable && SinglePredBB && BBIt == SinglePredBB->begin() &&
1159 BBIt = SinglePredBB->
end();
1162 (DefMaxInstsToScan - NumScanedInst), AA, &IsLoadCSE,
1167 if (!PredAvailable) {
1168 OneUnavailablePred = PredBB;
1173 CSELoads.
push_back(cast<LoadInst>(PredAvailable));
1177 AvailablePreds.push_back(std::make_pair(PredBB, PredAvailable));
1182 if (AvailablePreds.empty())
return false;
1194 if (PredsScanned.
size() == AvailablePreds.size()+1 &&
1196 UnavailablePred = OneUnavailablePred;
1197 }
else if (PredsScanned.
size() != AvailablePreds.size()) {
1203 for (
const auto &AvailablePred : AvailablePreds)
1204 AvailablePredSet.
insert(AvailablePred.first);
1209 if (isa<IndirectBrInst>(
P->getTerminator()))
1212 if (!AvailablePredSet.
count(
P))
1217 UnavailablePred = SplitBlockPreds(LoadBB, PredsToSplit,
"thread-pre-split");
1223 if (UnavailablePred) {
1225 "Can't handle critical edge here!");
1232 NewVal->setAAMetadata(AATags);
1234 AvailablePreds.push_back(std::make_pair(UnavailablePred, NewVal));
1252 AvailablePredsTy::iterator
I =
1253 std::lower_bound(AvailablePreds.begin(), AvailablePreds.end(),
1254 std::make_pair(P, (
Value*)
nullptr));
1256 assert(I != AvailablePreds.end() && I->first == P &&
1257 "Didn't find entry for predecessor!");
1263 Value *&PredV = I->second;
1264 if (PredV->getType() != LI->
getType())
1271 for (
LoadInst *PredLI : CSELoads) {
1288 assert(!PredToDestList.empty());
1295 for (
const auto &PredToDest : PredToDestList)
1296 if (PredToDest.second)
1297 DestPopularity[PredToDest.second]++;
1302 unsigned Popularity = DPI->second;
1305 for (++DPI; DPI != DestPopularity.
end(); ++DPI) {
1308 if (DPI->second < Popularity)
1310 else if (DPI->second == Popularity) {
1315 SamePopularity.
clear();
1316 MostPopularDest = DPI->first;
1317 Popularity = DPI->second;
1325 if (!SamePopularity.
empty()) {
1326 SamePopularity.
push_back(MostPopularDest);
1328 for (
unsigned i = 0; ; ++i) {
1340 return MostPopularDest;
1348 if (LoopHeaders.count(BB))
1352 if (!ComputeValueKnownInPredecessors(Cond, BB, PredValues, Preference, CxtI))
1356 "ComputeValueKnownInPredecessors returned true with no values");
1359 for (
const auto &PredValue : PredValues) {
1360 dbgs() <<
" BB '" << BB->
getName() <<
"': FOUND condition = "
1362 <<
" for pred '" << PredValue.second->getName() <<
"'.\n";
1377 unsigned PredWithKnownDest = 0;
1378 for (
const auto &PredValue : PredValues) {
1380 if (!SeenPreds.insert(Pred).second)
1386 if (isa<UndefValue>(Val))
1389 assert(isa<ConstantInt>(Val) &&
"Expecting a constant integer");
1390 DestBB = BI->getSuccessor(cast<ConstantInt>(Val)->
isZero());
1392 assert(isa<ConstantInt>(Val) &&
"Expecting a constant integer");
1393 DestBB =
SI->findCaseValue(cast<ConstantInt>(Val))->getCaseSuccessor();
1396 &&
"Unexpected terminator");
1397 assert(isa<BlockAddress>(Val) &&
"Expecting a constant blockaddress");
1398 DestBB = cast<BlockAddress>(Val)->getBasicBlock();
1402 if (PredToDestList.
empty()) {
1406 if (OnlyDest != DestBB)
1407 OnlyDest = MultipleDestSentinel;
1411 OnlyVal = MultipleVal;
1415 ++PredWithKnownDest;
1422 PredToDestList.
push_back(std::make_pair(Pred, DestBB));
1426 if (PredToDestList.
empty())
1432 if (OnlyDest && OnlyDest != MultipleDestSentinel) {
1433 if (PredWithKnownDest ==
1435 bool SeenFirstBranchToOnlyDest =
false;
1437 if (SuccBB == OnlyDest && !SeenFirstBranchToOnlyDest)
1438 SeenFirstBranchToOnlyDest =
true;
1440 SuccBB->removePredecessor(BB,
true);
1450 if (
auto *CondInst = dyn_cast<Instruction>(Cond)) {
1451 if (CondInst->use_empty() && !CondInst->mayHaveSideEffects())
1452 CondInst->eraseFromParent();
1460 else if (OnlyVal && OnlyVal != MultipleVal &&
1461 CondInst->getParent() == BB)
1474 if (MostPopularDest == MultipleDestSentinel)
1480 for (
const auto &PredToDest : PredToDestList)
1481 if (PredToDest.second == MostPopularDest) {
1494 if (!MostPopularDest)
1499 return ThreadEdge(BB, PredsToFactor, MostPopularDest);
1521 if (PredBr->isUnconditional()) {
1522 PredBBs[0] = PredBB;
1524 if (DuplicateCondBranchOnPHIIntoPred(BB, PredBBs))
1547 if (!isa<PHINode>(BB->
front()))
1574 if (!ComputeValueKnownInPredecessors(BO->
getOperand(0), BB, XorOpValues,
1576 assert(XorOpValues.empty());
1577 if (!ComputeValueKnownInPredecessors(BO->
getOperand(1), BB, XorOpValues,
1583 assert(!XorOpValues.empty() &&
1584 "ComputeValueKnownInPredecessors returned true with no values");
1588 unsigned NumTrue = 0, NumFalse = 0;
1589 for (
const auto &XorOpValue : XorOpValues) {
1590 if (isa<UndefValue>(XorOpValue.first))
1593 if (cast<ConstantInt>(XorOpValue.first)->isZero())
1601 if (NumTrue > NumFalse)
1603 else if (NumTrue != 0 || NumFalse != 0)
1609 for (
const auto &XorOpValue : XorOpValues) {
1610 if (XorOpValue.first != SplitVal && !isa<UndefValue>(XorOpValue.first))
1613 BlocksToFoldInto.
push_back(XorOpValue.second);
1618 if (BlocksToFoldInto.size() ==
1619 cast<PHINode>(BB->
front()).getNumIncomingValues()) {
1624 }
else if (SplitVal->
isZero()) {
1637 return DuplicateCondBranchOnPHIIntoPred(BB, BlocksToFoldInto);
1655 if (
Instruction *Inst = dyn_cast<Instruction>(IV)) {
1657 if (I != ValueMap.
end())
1674 <<
"' - would thread to self!\n");
1680 if (LoopHeaders.count(BB)) {
1682 <<
"' to dest BB '" << SuccBB->
getName()
1683 <<
"' - it might create an irreducible loop!\n");
1687 unsigned JumpThreadCost =
1689 if (JumpThreadCost > BBDupThreshold) {
1691 <<
"' - Cost is too high: " << JumpThreadCost <<
"\n");
1697 if (PredBBs.
size() == 1)
1698 PredBB = PredBBs[0];
1701 <<
" common predecessors.\n");
1702 PredBB = SplitBlockPreds(BB, PredBBs,
".thr_comm");
1707 << SuccBB->
getName() <<
"' with cost: " << JumpThreadCost
1708 <<
", across block:\n "
1711 LVI->threadEdge(PredBB, BB, SuccBB);
1724 if (HasProfileData) {
1726 BFI->getBlockFreq(PredBB) * BPI->getEdgeProbability(PredBB, BB);
1727 BFI->setBlockFreq(NewBB, NewBBFreq.getFrequency());
1736 for (; !isa<TerminatorInst>(BI); ++BI) {
1740 ValueMapping[&*BI] = New;
1746 if (I != ValueMapping.
end())
1769 for (
Use &U :
I.uses()) {
1771 if (
PHINode *UserPN = dyn_cast<PHINode>(User)) {
1772 if (UserPN->getIncomingBlock(U) == BB)
1781 if (UsesToRename.
empty())
1784 DEBUG(
dbgs() <<
"JT: Renaming non-local uses of: " <<
I <<
"\n");
1793 while (!UsesToRename.
empty())
1805 BB->removePredecessor(PredBB,
true);
1815 UpdateBlockFreqAndEdgeWeight(PredBB, BB, NewBB, SuccBB);
1827 const char *Suffix) {
1832 for (
auto Pred : Preds)
1833 PredBBFreq += BFI->getBlockFreq(Pred) * BPI->getEdgeProbability(Pred, BB);
1840 BFI->setBlockFreq(PredBB, PredBBFreq.getFrequency());
1844 bool JumpThreadingPass::doesBlockHaveProfileData(
BasicBlock *BB) {
1852 MDString *MDName = cast<MDString>(WeightsNode->getOperand(0));
1853 if (MDName->
getString() !=
"branch_weights")
1864 void JumpThreadingPass::UpdateBlockFreqAndEdgeWeight(
BasicBlock *PredBB,
1868 if (!HasProfileData)
1871 assert(BFI && BPI &&
"BFI & BPI should have been created here");
1875 auto BBOrigFreq = BFI->getBlockFreq(BB);
1876 auto NewBBFreq = BFI->getBlockFreq(NewBB);
1877 auto BB2SuccBBFreq = BBOrigFreq * BPI->getEdgeProbability(BB, SuccBB);
1878 auto BBNewFreq = BBOrigFreq - NewBBFreq;
1879 BFI->setBlockFreq(BB, BBNewFreq.getFrequency());
1885 auto SuccFreq = (Succ == SuccBB)
1886 ? BB2SuccBBFreq - NewBBFreq
1887 : BBOrigFreq * BPI->getEdgeProbability(BB, Succ);
1888 BBSuccFreq.
push_back(SuccFreq.getFrequency());
1891 uint64_t MaxBBSuccFreq =
1892 *std::max_element(BBSuccFreq.
begin(), BBSuccFreq.
end());
1895 if (MaxBBSuccFreq == 0)
1897 {1,
static_cast<unsigned>(BBSuccFreq.
size())});
1899 for (uint64_t Freq : BBSuccFreq)
1900 BBSuccProbs.push_back(
1908 for (
int I = 0,
E = BBSuccProbs.size();
I <
E;
I++)
1909 BPI->setEdgeProbability(BB,
I, BBSuccProbs[
I]);
1945 if (BBSuccProbs.size() >= 2 && doesBlockHaveProfileData(BB)) {
1947 for (
auto Prob : BBSuccProbs)
1964 assert(!PredBBs.
empty() &&
"Can't handle an empty set");
1969 if (LoopHeaders.count(BB)) {
1971 <<
"' into predecessor block '" << PredBBs[0]->getName()
1972 <<
"' - it might create an irreducible loop!\n");
1976 unsigned DuplicationCost =
1978 if (DuplicationCost > BBDupThreshold) {
1980 <<
"' - Cost is too high: " << DuplicationCost <<
"\n");
1986 if (PredBBs.
size() == 1)
1987 PredBB = PredBBs[0];
1990 <<
" common predecessors.\n");
1991 PredBB = SplitBlockPreds(BB, PredBBs,
".thr_comm");
1996 DEBUG(
dbgs() <<
" Duplicating block '" << BB->
getName() <<
"' into end of '"
1997 << PredBB->
getName() <<
"' to eliminate branch on phi. Cost: "
1998 << DuplicationCost <<
" block is:" << *BB <<
"\n");
2004 if (!OldPredBranch || !OldPredBranch->isUnconditional()) {
2018 for (; BI != BB->
end(); ++BI) {
2025 if (I != ValueMapping.
end())
2035 ValueMapping[&*BI] = IV;
2041 ValueMapping[&*BI] = New;
2067 for (
Use &U : I.uses()) {
2069 if (
PHINode *UserPN = dyn_cast<PHINode>(User)) {
2070 if (UserPN->getIncomingBlock(U) == BB)
2079 if (UsesToRename.
empty())
2082 DEBUG(
dbgs() <<
"JT: Renaming non-local uses of: " << I <<
"\n");
2087 SSAUpdate.Initialize(I.getType(), I.getName());
2088 SSAUpdate.AddAvailableValue(BB, &I);
2089 SSAUpdate.AddAvailableValue(PredBB, ValueMapping[&I]);
2091 while (!UsesToRename.
empty())
2098 BB->removePredecessor(PredBB,
true);
2101 OldPredBranch->eraseFromParent();
2125 CondLHS->getParent() != BB)
2128 for (
unsigned I = 0, E = CondLHS->getNumIncomingValues(); I !=
E; ++
I) {
2129 BasicBlock *Pred = CondLHS->getIncomingBlock(I);
2146 CondRHS, Pred, BB, CondCmp);
2149 CondRHS, Pred, BB, CondCmp);
2152 LHSFolds != RHSFolds) {
2163 BB->getParent(), BB);
2208 if (LoopHeaders.count(BB))
2215 [](
Value *V) {
return !isa<ConstantInt>(V); }))
2228 if (
ICmpInst *Cmp = dyn_cast<ICmpInst>(U.getUser())) {
2231 if (Cmp->getParent() == BB && Cmp->
hasOneUse() &&
2232 isa<ConstantInt>(Cmp->getOperand(1 - U.getOperandNo())))
2233 if (
SelectInst *SelectI = dyn_cast<SelectInst>(Cmp->user_back()))
2234 if (isUnfoldCandidate(SelectI, Cmp->use_begin()->get())) {
2238 }
else if (
SelectInst *SelectI = dyn_cast<SelectInst>(U.getUser())) {
2240 if (isUnfoldCandidate(SelectI, U.get())) {
2282 using namespace PatternMatch;
2299 auto *Parent = Pred1->getSinglePredecessor();
2300 if (!Parent || Parent != Pred2->getSinglePredecessor())
2303 if (
auto *BI = dyn_cast<BranchInst>(Parent->getTerminator()))
2305 if (
match(&I, m_Intrinsic<Intrinsic::experimental_guard>()))
2306 if (ThreadGuard(BB, cast<IntrinsicInst>(&I), BI))
2325 bool TrueDestIsSafe =
false;
2326 bool FalseDestIsSafe =
false;
2331 TrueDestIsSafe =
true;
2337 FalseDestIsSafe =
true;
2340 if (!TrueDestIsSafe && !FalseDestIsSafe)
2343 BasicBlock *UnguardedBlock = TrueDestIsSafe ? TrueDest : FalseDest;
2344 BasicBlock *GuardedBlock = FalseDestIsSafe ? TrueDest : FalseDest;
2349 if (Cost > BBDupThreshold)
2354 BB, GuardedBlock, AfterGuard, GuardedMapping);
2355 assert(GuardedBlock &&
"Could not create the guarded block?");
2360 Guard, UnguardedMapping);
2361 assert(UnguardedBlock &&
"Could not create the unguarded block?");
2362 DEBUG(
dbgs() <<
"Moved guard " << *Guard <<
" to block "
2363 << GuardedBlock->
getName() <<
"\n");
2369 for (
auto BI = BB->
begin(); &*BI != AfterGuard; ++BI)
2370 if (!isa<PHINode>(&*BI))
2374 assert(InsertionPoint &&
"Empty block?");
2376 for (
auto *Inst :
reverse(ToRemove)) {
2377 if (!Inst->use_empty()) {
2379 NewPN->
addIncoming(UnguardedMapping[Inst], UnguardedBlock);
2380 NewPN->
addIncoming(GuardedMapping[Inst], GuardedBlock);
2382 Inst->replaceAllUsesWith(NewPN);
2384 Inst->eraseFromParent();
Legacy wrapper pass to provide the GlobalsAAResult object.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
static ConstantInt * getFalse(LLVMContext &Context)
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
This class is the base class for the comparison instructions.
iterator_range< use_iterator > uses()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
void removePredecessor(BasicBlock *Pred, bool DontDeleteUselessPHIs=false)
Notify the BasicBlock that the predecessor Pred is no longer able to reach it.
static IntegerType * getInt1Ty(LLVMContext &C)
Helper class for SSA formation on a set of values defined in multiple blocks.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
STATISTIC(NumFunctions,"Total number of functions")
bool 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 pr...
Wrapper around LazyValueInfo.
This is the interface for a simple mod/ref and alias analysis over globals.
void Initialize(Type *Ty, StringRef Name)
Reset this object to get ready for a new set of SSA updates with type 'Ty'.
virtual void releaseMemory()
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
void initializeJumpThreadingPass(PassRegistry &)
unsigned getNumOperands() const
void DeleteDeadBlock(BasicBlock *BB)
Delete the specified block, which must have no predecessors.
void AddAvailableValue(BasicBlock *BB, Value *V)
Indicate that a rewritten value is available in the specified block with the specified value...
This class represents a function call, abstracting a target machine's calling convention.
cl::opt< unsigned > DefMaxInstsToScan
The default number of maximum instructions to scan in the block, used by FindAvailableLoadedValue().
void MergeBasicBlockIntoOnlyPred(BasicBlock *BB, DominatorTree *DT=nullptr)
BB is a block with one predecessor and its predecessor is known to have one successor (BB!)...
bool mayHaveSideEffects() const
Return true if the instruction may have side effects.
static CastInst * CreateBitOrPointerCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a BitCast, a PtrToInt, or an IntToPTr cast instruction.
void deleteValue()
Delete a pointer to a generic Value.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
Value * FindAvailablePtrLoadStore(Value *Ptr, Type *AccessTy, bool AtLeastAtomic, BasicBlock *ScanBB, BasicBlock::iterator &ScanFrom, unsigned MaxInstsToScan, AliasAnalysis *AA, bool *IsLoad, unsigned *NumScanedInst)
Scan backwards to see if we have the value of the given pointer available locally within a small numb...
bool isEHPad() const
Return true if this basic block is an exception handling block.
const Function * getParent() const
Return the enclosing method, or null if none.
unsigned getNumSuccessors() const
Return the number of successors that this terminator has.
bool SimplifyInstructionsInBlock(BasicBlock *BB, const TargetLibraryInfo *TLI=nullptr)
Scan the specified basic block and try to simplify any instructions in it and recursively delete dead...
const Instruction & front() const
An instruction for reading from memory.
static Constant * getCompare(unsigned short pred, Constant *C1, Constant *C2, bool OnlyIfReduced=false)
Return an ICmp or FCmp comparison operator constant expression.
INITIALIZE_PASS_BEGIN(JumpThreading,"jump-threading","Jump Threading", false, false) INITIALIZE_PASS_END(JumpThreading
FunctionPass * createJumpThreadingPass(int Threshold=-1)
StringRef getName() const
Return a constant reference to the value's name.
iterator begin()
Instruction iterator methods.
The address of a basic block.
bool match(Val *V, const Pattern &P)
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
bool isUnconditional() const
static void AddPHINodeEntriesForMappedBlock(BasicBlock *PHIBB, BasicBlock *OldPred, BasicBlock *NewPred, DenseMap< Instruction *, Value * > &ValueMap)
AddPHINodeEntriesForMappedBlock - We're adding 'NewPred' as a new predecessor to the PHIBB block...
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
This class represents the LLVM 'select' instruction.
This is the base class for all instructions that perform data casts.
static cl::opt< unsigned > BBDuplicateThreshold("jump-threading-threshold", cl::desc("Max block size to duplicate for jump threading"), cl::init(6), cl::Hidden)
'undef' values are things that do not have specified contents.
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr it the function does no...
Value * FindAvailableLoadedValue(LoadInst *Load, BasicBlock *ScanBB, BasicBlock::iterator &ScanFrom, unsigned MaxInstsToScan=DefMaxInstsToScan, AliasAnalysis *AA=nullptr, bool *IsLoadCSE=nullptr, unsigned *NumScanedInst=nullptr)
Scan backwards to see if we have the value of the given load available locally within a small number ...
A Use represents the edge between a Value definition and its users.
bool ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions=false, const TargetLibraryInfo *TLI=nullptr)
If a terminator instruction is predicated on a constant value, convert it into an unconditional branc...
static bool runImpl(CallGraphSCC &SCC, AARGetterT AARGetter)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs...ExtraArgs)
Get the result of an analysis pass for a given IR unit.
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches, switches, etc.
static cl::opt< unsigned > ImplicationSearchThreshold("jump-threading-implication-search-threshold", cl::desc("The number of predecessors to search for a stronger ""condition to use to thread over a weaker condition"), cl::init(3), cl::Hidden)
void setName(const Twine &Name)
Change the name of the value.
bool TryToUnfoldSelectInCurrBB(BasicBlock *BB)
TryToUnfoldSelectInCurrBB - Look for PHI/Select or PHI/CMP/Select in the same BB in the form bb: p = ...
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
LLVM_NODISCARD bool empty() const
void assign(size_type NumElts, const T &Elt)
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
static Constant * get(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags=0, Type *OnlyIfReducedTy=nullptr)
get - Return a binary or shift operator constant expression, folding if possible. ...
Value * SimplifyCmpInst(unsigned Predicate, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a CmpInst, fold the result or return null.
static void normalizeProbabilities(ProbabilityIter Begin, ProbabilityIter End)
bool contains(const APInt &Val) const
Return true if the specified value is in the set.
BasicBlock * getSuccessor(unsigned i) const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
static bool ProcessBlock(BasicBlock &BB, DominatorTree &DT, LoopInfo &LI, AAResults &AA)
Optional< uint64_t > getEntryCount() const
Get the entry count for this function.
void takeName(Value *V)
Transfer the name from V to this value.
static Constant * getKnownConstant(Value *Val, ConstantPreference Preference)
getKnownConstant - Helper method to determine if we can thread over a terminator with the given value...
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
bool isAtomic() const
Return true if this instruction has an AtomicOrdering of unordered or higher.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
iterator find(const_arg_type_t< KeyT > Val)
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
initializer< Ty > init(const Ty &Val)
bool isGuaranteedToTransferExecutionToSuccessor(const Instruction *I)
Return true if this function can prove that the instruction I will always transfer execution to one o...
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
Subclasses of this class are all able to terminate a basic block.
A set of analyses that are preserved following a run of a transformation pass.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
void setSuccessor(unsigned idx, BasicBlock *B)
Update the specified successor to point at the provided block.
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction...
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
bool TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB)
BB is known to contain an unconditional branch, and contains no instructions other than PHI nodes...
Conditional or Unconditional Branch instruction.
bool isVectorTy() const
True if this is an instance of VectorType.
static BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
This is an important base class in LLVM.
const Value * getCondition() const
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
static bool isOpDefinedInBlock(Value *Op, BasicBlock *BB)
Return true if Op is an instruction defined in the given block.
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
Indirect Branch Instruction.
bool DuplicateCondBranchOnPHIIntoPred(BasicBlock *BB, const SmallVectorImpl< BasicBlock * > &PredBBs)
DuplicateCondBranchOnPHIIntoPred - PredBB contains an unconditional branch to BB which contains an i1...
A manager for alias analyses.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Constant * ConstantFoldInstruction(Instruction *I, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldInstruction - Try to constant fold the specified instruction.
bool runImpl(Function &F, TargetLibraryInfo *TLI_, LazyValueInfo *LVI_, AliasAnalysis *AA_, bool HasProfileData_, std::unique_ptr< BlockFrequencyInfo > BFI_, std::unique_ptr< BranchProbabilityInfo > BPI_)
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Represent the analysis usage information of a pass.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
bool any_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
const InstListType & getInstList() const
Return the underlying instruction list container.
This instruction compares its operands according to the predicate given to the constructor.
Analysis pass providing a never-invalidated alias analysis result.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
JumpThreadingPass(int T=-1)
FunctionPass class - This class is used to implement most global optimizations.
Value * getOperand(unsigned i) const
Interval::pred_iterator pred_end(Interval *I)
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Predicate getPredicate() const
Return the predicate for this instruction.
bool pred_empty(const BasicBlock *BB)
static Constant * getNot(Constant *C)
void FindLoopHeaders(Function &F)
FindLoopHeaders - We do not want jump threading to turn proper loop structures into irreducible loops...
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
LLVMContext & getContext() const
All values hold a context through their type.
const Value * getTrueValue() const
ConstantRange add(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an addition of a value in this ran...
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
static unsigned GetBestDestForJumpOnUndef(BasicBlock *BB)
GetBestDestForBranchOnUndef - If we determine that the specified block ends in an undefined jump...
Tristate
This is used to return true/false/dunno results.
bool isTerminator() const
bool ProcessBranchOnPHI(PHINode *PN)
ProcessBranchOnPHI - We have an otherwise unthreadable conditional branch on a PHI node in the curren...
bool isConditional() const
bool ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB, jumpthreading::PredValueInfo &Result, jumpthreading::ConstantPreference Preference, Instruction *CxtI=nullptr)
ComputeValueKnownInPredecessors - Given a basic block BB and a value V, see if we can infer that the ...
const Value * DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB) const
Translate PHI node to its predecessor from the given basic block.
StringRef getString() const
static cl::opt< bool > PrintLVIAfterJumpThreading("print-lvi-after-jump-threading", cl::desc("Print the LazyValueInfo cache after JumpThreading"), cl::init(false), cl::Hidden)
Iterator for intrusive lists based on ilist_node.
void moveAfter(BasicBlock *MovePos)
Unlink this basic block from its current function and insert it right after MovePos in the function M...
static ConstantRange makeExactICmpRegion(CmpInst::Predicate Pred, const APInt &Other)
Produce the exact range such that all values in the returned range satisfy the given predicate with a...
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
void FindFunctionBackedges(const Function &F, SmallVectorImpl< std::pair< const BasicBlock *, const BasicBlock * > > &Result)
Analyze the specified function to find all of the loop backedges in the function and return them...
This is the shared class of boolean and integer constants.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
bool removeUnreachableBlocks(Function &F, LazyValueInfo *LVI=nullptr)
Remove all blocks that can not be reached from the function's entry.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
ConstantRange inverse() const
Return a new range that is the logical not of the current set.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Type * getType() const
All values are typed, get the type of this value.
Provides information about what library functions are available for the current target.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
SyncScope::ID getSyncScopeID() const
Returns the synchronization scope ID of this load instruction.
This pass performs 'jump threading', which looks at blocks that have multiple predecessors and multip...
This class represents a range of values.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
static BranchProbability getBranchProbability(uint64_t Numerator, uint64_t Denominator)
TerminatorInst * SplitBlockAndInsertIfThen(Value *Cond, Instruction *SplitBefore, bool Unreachable, MDNode *BranchWeights=nullptr, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr)
Split the containing block at the specified instruction - everything before SplitBefore stays in the ...
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
LLVM_NODISCARD T pop_back_val()
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
bool SimplifyPartiallyRedundantLoad(LoadInst *LI)
SimplifyPartiallyRedundantLoad - If LI is an obviously partially redundant load instruction, eliminate it by replacing it with a PHI node.
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
AtomicOrdering getOrdering() const
Returns the ordering constraint of this load instruction.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
pred_range predecessors(BasicBlock *BB)
const BasicBlock & getEntryBlock() const
static ConstantInt * getTrue(LLVMContext &Context)
BasicBlock * getSuccessor(unsigned idx) const
Return the specified successor.
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
void setOperand(unsigned i, Value *Val)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static unsigned getJumpThreadDuplicationCost(BasicBlock *BB, Instruction *StopAt, unsigned Threshold)
Return the cost of duplicating a piece of this block from first non-phi and before StopAt instruction...
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
void push_back(pointer val)
Value * getIncomingValueForBlock(const BasicBlock *BB) const
bool isIntegerTy() const
True if this is an instance of IntegerType.
BasicBlock * DuplicateInstructionsInSplitBetween(BasicBlock *BB, BasicBlock *PredBB, Instruction *StopAt, ValueToValueMapTy &ValueMapping)
Split edge between BB and PredBB and duplicate all non-Phi instructions from BB between its beginning...
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
void removeFromParent()
This method unlinks 'this' from the containing basic block, but does not delete it.
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Value * getCondition() const
Analysis providing branch probability information.
iterator insert(iterator where, pointer New)
void emplace_back(ArgTypes &&...Args)
unsigned getNumSuccessors() const
bool ProcessBranchOnXOR(BinaryOperator *BO)
ProcessBranchOnXOR - We have an otherwise unthreadable conditional branch on a xor instruction in the...
unsigned getAlignment() const
Return the alignment of the access that is being performed.
void getAAMetadata(AAMDNodes &N, bool Merge=false) const
Fills the AAMDNodes structure with AA metadata from this instruction.
bool ProcessImpliedCondition(BasicBlock *BB)
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
bool hasOneUse() const
Return true if there is exactly one user of this value.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
static void ReplaceFoldableUses(Instruction *Cond, Value *ToVal)
void preserve()
Mark an analysis as preserved.
void combineMetadataForCSE(Instruction *K, const Instruction *J)
Combine the metadata of two instructions so that K can replace J.
bool ProcessThreadableEdges(Value *Cond, BasicBlock *BB, jumpthreading::ConstantPreference Preference, Instruction *CxtI=nullptr)
BasicBlock * SplitBlockPredecessors(BasicBlock *BB, ArrayRef< BasicBlock * > Preds, const char *Suffix, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, bool PreserveLCSSA=false)
This method introduces at least one new basic block into the function and moves some of the predecess...
Analysis pass providing the TargetLibraryInfo.
static int const Threshold
TODO: Write a new FunctionPass AliasAnalysis so that it can keep a cache.
Helper struct that represents how a value is mapped through different register banks.
This pass computes, caches, and vends lazy value constraint information.
static BasicBlock * FindMostPopularDest(BasicBlock *BB, const SmallVectorImpl< std::pair< BasicBlock *, BasicBlock * > > &PredToDestList)
FindMostPopularDest - The specified list contains multiple possible threadable destinations.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
See the comments on JumpThreadingPass.
LLVMContext & getContext() const
Get the context in which this basic block lives.
void removeDeadConstantUsers() const
If there are any dead constant users dangling off of this constant, remove them.
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
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...
bool ProcessGuards(BasicBlock *BB)
Try to propagate a guard from the current BB into one of its predecessors in case if another branch o...
Module * getParent()
Get the module that this global value is contained inside of...
bool isInstructionTriviallyDead(Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction is not used, and the instruction has no side ef...
LLVM Value Representation.
succ_range successors(BasicBlock *BB)
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
bool ProcessBlock(BasicBlock *BB)
ProcessBlock - If there are any predecessors whose control can be threaded through to a successor...
static const Function * getParent(const Value *V)
BasicBlock * SplitEdge(BasicBlock *From, BasicBlock *To, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr)
Split the edge connecting specified block.
const Instruction * getFirstNonPHIOrDbg() const
Returns a pointer to the first instruction in this block that is not a PHINode or a debug intrinsic...
bool isExceptional() const
Optional< bool > isImpliedCondition(const Value *LHS, const Value *RHS, const DataLayout &DL, bool LHSIsFalse=false, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return true if RHS is known to be implied true by LHS.
const Value * getFalseValue() const
A container for analyses that lazily runs them and caches their results.
Legacy analysis pass which computes a DominatorTree.
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
const TerminatorInst * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
op_range incoming_values()
void RewriteUse(Use &U)
Rewrite a use of the symbolic value.
static bool hasAddressTakenAndUsed(BasicBlock *BB)
Value * SimplifyInstruction(Instruction *I, const SimplifyQuery &Q, OptimizationRemarkEmitter *ORE=nullptr)
See if we can compute a simplified version of this instruction.
const BasicBlock * getParent() const
unsigned replaceNonLocalUsesWith(Instruction *From, Value *To)
Analysis to compute lazy value information.
A wrapper class for inspecting calls to intrinsic functions.
bool TryToUnfoldSelect(CmpInst *CondCmp, BasicBlock *BB)
TryToUnfoldSelect - Look for blocks of the form bb1: a = select br bb2.
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.