@@ -398,9 +398,6 @@ static void addPredecessorToBlock(BasicBlock *Succ, BasicBlock *NewPred,
398
398
// / expensive.
399
399
static InstructionCost computeSpeculationCost (const User *I,
400
400
const TargetTransformInfo &TTI) {
401
- assert ((!isa<Instruction>(I) ||
402
- isSafeToSpeculativelyExecute (cast<Instruction>(I))) &&
403
- " Instruction is not safe to speculatively execute!" );
404
401
return TTI.getInstructionCost (I, TargetTransformInfo::TCK_SizeAndLatency);
405
402
}
406
403
@@ -421,12 +418,11 @@ static InstructionCost computeSpeculationCost(const User *I,
421
418
// / After this function returns, Cost is increased by the cost of
422
419
// / V plus its non-dominating operands. If that cost is greater than
423
420
// / 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,
425
422
SmallPtrSetImpl<Instruction *> &AggressiveInsts,
426
- InstructionCost &Cost,
427
- InstructionCost Budget,
423
+ InstructionCost &Cost, InstructionCost Budget,
428
424
const TargetTransformInfo &TTI,
429
- unsigned Depth = 0 ) {
425
+ AssumptionCache *AC, unsigned Depth = 0 ) {
430
426
// It is possible to hit a zero-cost cycle (phi/gep instructions for example),
431
427
// so limit the recursion depth.
432
428
// TODO: While this recursion limit does prevent pathological behavior, it
@@ -461,7 +457,7 @@ static bool dominatesMergePoint(Value *V, BasicBlock *BB,
461
457
// Okay, it looks like the instruction IS in the "condition". Check to
462
458
// see if it's a cheap instruction to unconditionally compute, and if it
463
459
// only uses stuff defined outside of the condition. If so, hoist it out.
464
- if (!isSafeToSpeculativelyExecute (I))
460
+ if (!isSafeToSpeculativelyExecute (I, InsertPt, AC ))
465
461
return false ;
466
462
467
463
Cost += computeSpeculationCost (I, TTI);
@@ -480,8 +476,8 @@ static bool dominatesMergePoint(Value *V, BasicBlock *BB,
480
476
// Okay, we can only really hoist these out if their operands do
481
477
// not take us over the cost threshold.
482
478
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 ))
485
481
return false ;
486
482
// Okay, it's safe to do this! Remember this instruction.
487
483
AggressiveInsts.insert (I);
@@ -3140,7 +3136,8 @@ bool SimplifyCFGOpt::speculativelyExecuteBB(BranchInst *BI,
3140
3136
return false ;
3141
3137
3142
3138
// 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 ) &&
3144
3141
!(HoistCondStores && !SpeculatedStoreValue &&
3145
3142
(SpeculatedStoreValue =
3146
3143
isSafeToSpeculateStore (&I, BB, ThenBB, EndBB))))
@@ -3651,7 +3648,8 @@ static bool foldCondBranchOnValueKnownInPredecessor(BranchInst *BI,
3651
3648
// / Given a BB that starts with the specified two-entry PHI node,
3652
3649
// / see if we can eliminate it.
3653
3650
static bool foldTwoEntryPHINode (PHINode *PN, const TargetTransformInfo &TTI,
3654
- DomTreeUpdater *DTU, const DataLayout &DL,
3651
+ DomTreeUpdater *DTU, AssumptionCache *AC,
3652
+ const DataLayout &DL,
3655
3653
bool SpeculateUnpredictables) {
3656
3654
// Ok, this is a two entry PHI node. Check to see if this is a simple "if
3657
3655
// statement", which has a very simple dominance structure. Basically, we
@@ -3741,10 +3739,10 @@ static bool foldTwoEntryPHINode(PHINode *PN, const TargetTransformInfo &TTI,
3741
3739
continue ;
3742
3740
}
3743
3741
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 ))
3748
3746
return Changed;
3749
3747
}
3750
3748
@@ -8116,7 +8114,7 @@ bool SimplifyCFGOpt::simplifyOnce(BasicBlock *BB) {
8116
8114
// eliminate it, do so now.
8117
8115
if (auto *PN = dyn_cast<PHINode>(BB->begin ()))
8118
8116
if (PN->getNumIncomingValues () == 2 )
8119
- if (foldTwoEntryPHINode (PN, TTI, DTU, DL,
8117
+ if (foldTwoEntryPHINode (PN, TTI, DTU, Options. AC , DL,
8120
8118
Options.SpeculateUnpredictables ))
8121
8119
return true ;
8122
8120
}
0 commit comments