@@ -398,9 +398,6 @@ static void addPredecessorToBlock(BasicBlock *Succ, BasicBlock *NewPred,
398398// / expensive.
399399static InstructionCost computeSpeculationCost (const User *I,
400400 const TargetTransformInfo &TTI) {
401- assert ((!isa<Instruction>(I) ||
402- isSafeToSpeculativelyExecute (cast<Instruction>(I))) &&
403- " Instruction is not safe to speculatively execute!" );
404401 return TTI.getInstructionCost (I, TargetTransformInfo::TCK_SizeAndLatency);
405402}
406403
@@ -421,12 +418,11 @@ static InstructionCost computeSpeculationCost(const User *I,
421418// / After this function returns, Cost is increased by the cost of
422419// / V plus its non-dominating operands. If that cost is greater than
423420// / Budget, false is returned and Cost is undefined.
424- static bool dominatesMergePoint (Value *V, BasicBlock *BB,
421+ static bool dominatesMergePoint (Value *V, BasicBlock *BB, Instruction *InsertPt,
425422 SmallPtrSetImpl<Instruction *> &AggressiveInsts,
426- InstructionCost &Cost,
427- InstructionCost Budget,
423+ InstructionCost &Cost, InstructionCost Budget,
428424 const TargetTransformInfo &TTI,
429- unsigned Depth = 0 ) {
425+ AssumptionCache *AC, unsigned Depth = 0 ) {
430426 // It is possible to hit a zero-cost cycle (phi/gep instructions for example),
431427 // so limit the recursion depth.
432428 // TODO: While this recursion limit does prevent pathological behavior, it
@@ -461,7 +457,7 @@ static bool dominatesMergePoint(Value *V, BasicBlock *BB,
461457 // Okay, it looks like the instruction IS in the "condition". Check to
462458 // see if it's a cheap instruction to unconditionally compute, and if it
463459 // only uses stuff defined outside of the condition. If so, hoist it out.
464- if (!isSafeToSpeculativelyExecute (I))
460+ if (!isSafeToSpeculativelyExecute (I, InsertPt, AC ))
465461 return false ;
466462
467463 Cost += computeSpeculationCost (I, TTI);
@@ -480,8 +476,8 @@ static bool dominatesMergePoint(Value *V, BasicBlock *BB,
480476 // Okay, we can only really hoist these out if their operands do
481477 // not take us over the cost threshold.
482478 for (Use &Op : I->operands ())
483- if (!dominatesMergePoint (Op, BB, AggressiveInsts, Cost, Budget, TTI ,
484- Depth + 1 ))
479+ if (!dominatesMergePoint (Op, BB, InsertPt, AggressiveInsts, Cost, Budget,
480+ TTI, AC, Depth + 1 ))
485481 return false ;
486482 // Okay, it's safe to do this! Remember this instruction.
487483 AggressiveInsts.insert (I);
@@ -3140,7 +3136,8 @@ bool SimplifyCFGOpt::speculativelyExecuteBB(BranchInst *BI,
31403136 return false ;
31413137
31423138 // Don't hoist the instruction if it's unsafe or expensive.
3143- if (!IsSafeCheapLoadStore && !isSafeToSpeculativelyExecute (&I) &&
3139+ if (!IsSafeCheapLoadStore &&
3140+ !isSafeToSpeculativelyExecute (&I, BI, Options.AC ) &&
31443141 !(HoistCondStores && !SpeculatedStoreValue &&
31453142 (SpeculatedStoreValue =
31463143 isSafeToSpeculateStore (&I, BB, ThenBB, EndBB))))
@@ -3651,7 +3648,8 @@ static bool foldCondBranchOnValueKnownInPredecessor(BranchInst *BI,
36513648// / Given a BB that starts with the specified two-entry PHI node,
36523649// / see if we can eliminate it.
36533650static bool foldTwoEntryPHINode (PHINode *PN, const TargetTransformInfo &TTI,
3654- DomTreeUpdater *DTU, const DataLayout &DL,
3651+ DomTreeUpdater *DTU, AssumptionCache *AC,
3652+ const DataLayout &DL,
36553653 bool SpeculateUnpredictables) {
36563654 // Ok, this is a two entry PHI node. Check to see if this is a simple "if
36573655 // statement", which has a very simple dominance structure. Basically, we
@@ -3741,10 +3739,10 @@ static bool foldTwoEntryPHINode(PHINode *PN, const TargetTransformInfo &TTI,
37413739 continue ;
37423740 }
37433741
3744- if (!dominatesMergePoint (PN->getIncomingValue (0 ), BB, AggressiveInsts ,
3745- Cost, Budget, TTI) ||
3746- !dominatesMergePoint (PN->getIncomingValue (1 ), BB, AggressiveInsts ,
3747- Cost, Budget, TTI))
3742+ if (!dominatesMergePoint (PN->getIncomingValue (0 ), BB, DomBI ,
3743+ AggressiveInsts, Cost, Budget, TTI, AC ) ||
3744+ !dominatesMergePoint (PN->getIncomingValue (1 ), BB, DomBI ,
3745+ AggressiveInsts, Cost, Budget, TTI, AC ))
37483746 return Changed;
37493747 }
37503748
@@ -8116,7 +8114,7 @@ bool SimplifyCFGOpt::simplifyOnce(BasicBlock *BB) {
81168114 // eliminate it, do so now.
81178115 if (auto *PN = dyn_cast<PHINode>(BB->begin ()))
81188116 if (PN->getNumIncomingValues () == 2 )
8119- if (foldTwoEntryPHINode (PN, TTI, DTU, DL,
8117+ if (foldTwoEntryPHINode (PN, TTI, DTU, Options. AC , DL,
81208118 Options.SpeculateUnpredictables ))
81218119 return true ;
81228120 }
0 commit comments