@@ -2450,11 +2450,10 @@ SelectionDAGBuilder::EmitBranchForMergedCondition(const Value *Cond,
2450
2450
2451
2451
// Collect dependencies on V recursively. This is used for the cost analysis in
2452
2452
// `shouldKeepJumpConditionsTogether`.
2453
- static bool
2454
- collectInstructionDeps (SmallPtrSet<const Instruction *, 8 > *Deps,
2455
- const Value *V,
2456
- SmallPtrSet<const Instruction *, 8 > *Necessary = nullptr ,
2457
- unsigned Depth = 0 ) {
2453
+ static bool collectInstructionDeps (
2454
+ SmallMapVector<const Instruction *, bool , 8 > *Deps, const Value *V,
2455
+ SmallMapVector<const Instruction *, bool , 8 > *Necessary = nullptr ,
2456
+ unsigned Depth = 0 ) {
2458
2457
// Return false if we have an incomplete count.
2459
2458
if (Depth >= SelectionDAG::MaxRecursionDepth)
2460
2459
return false ;
@@ -2471,7 +2470,7 @@ collectInstructionDeps(SmallPtrSet<const Instruction *, 8> *Deps,
2471
2470
}
2472
2471
2473
2472
// Already added this dep.
2474
- if (!Deps->insert (I ).second )
2473
+ if (!Deps->try_emplace (I, false ).second )
2475
2474
return true ;
2476
2475
2477
2476
for (unsigned OpIdx = 0 , E = I->getNumOperands (); OpIdx < E; ++OpIdx)
@@ -2526,7 +2525,9 @@ bool SelectionDAGBuilder::shouldKeepJumpConditionsTogether(
2526
2525
return false ;
2527
2526
2528
2527
// Collect "all" instructions that lhs condition is dependent on.
2529
- SmallPtrSet<const Instruction *, 8 > LhsDeps, RhsDeps;
2528
+ // Use map for stable iteration (to avoid non-determanism of iteration of
2529
+ // SmallPtrSet). The `bool` value is just a dummy.
2530
+ SmallMapVector<const Instruction *, bool , 8 > LhsDeps, RhsDeps;
2530
2531
collectInstructionDeps (&LhsDeps, Lhs);
2531
2532
// Collect "all" instructions that rhs condition is dependent on AND are
2532
2533
// dependencies of lhs. This gives us an estimate on which instructions we
@@ -2536,7 +2537,7 @@ bool SelectionDAGBuilder::shouldKeepJumpConditionsTogether(
2536
2537
// Add the compare instruction itself unless its a dependency on the LHS.
2537
2538
if (const auto *RhsI = dyn_cast<Instruction>(Rhs))
2538
2539
if (!LhsDeps.contains (RhsI))
2539
- RhsDeps.insert (RhsI);
2540
+ RhsDeps.try_emplace (RhsI, false );
2540
2541
2541
2542
const auto &TLI = DAG.getTargetLoweringInfo ();
2542
2543
const auto &TTI =
@@ -2564,9 +2565,9 @@ bool SelectionDAGBuilder::shouldKeepJumpConditionsTogether(
2564
2565
// instructions.
2565
2566
for (unsigned PruneIters = 0 ; PruneIters < MaxPruneIters; ++PruneIters) {
2566
2567
const Instruction *ToDrop = nullptr ;
2567
- for (const auto *Ins : RhsDeps) {
2568
- if (!ShouldCountInsn (Ins )) {
2569
- ToDrop = Ins ;
2568
+ for (const auto &InsPair : RhsDeps) {
2569
+ if (!ShouldCountInsn (InsPair. first )) {
2570
+ ToDrop = InsPair. first ;
2570
2571
break ;
2571
2572
}
2572
2573
}
@@ -2575,13 +2576,13 @@ bool SelectionDAGBuilder::shouldKeepJumpConditionsTogether(
2575
2576
RhsDeps.erase (ToDrop);
2576
2577
}
2577
2578
2578
- for (const auto *Ins : RhsDeps) {
2579
+ for (const auto &InsPair : RhsDeps) {
2579
2580
// Finally accumulate latency that we can only attribute to computing the
2580
2581
// RHS condition. Use latency because we are essentially trying to calculate
2581
2582
// the cost of the dependency chain.
2582
2583
// Possible TODO: We could try to estimate ILP and make this more precise.
2583
2584
CostOfIncluding +=
2584
- TTI.getInstructionCost (Ins , TargetTransformInfo::TCK_Latency);
2585
+ TTI.getInstructionCost (InsPair. first , TargetTransformInfo::TCK_Latency);
2585
2586
2586
2587
if (CostOfIncluding > CostThresh)
2587
2588
return false ;
0 commit comments