@@ -541,10 +541,6 @@ class InnerLoopVectorizer {
541
541
protected:
542
542
friend class LoopVectorizationPlanner ;
543
543
544
- // / Iteratively sink the scalarized operands of a predicated instruction into
545
- // / the block that was created for it.
546
- void sinkScalarOperands (Instruction *PredInst);
547
-
548
544
// / Returns (and creates if needed) the trip count of the widened loop.
549
545
Value *getOrCreateVectorTripCount (BasicBlock *InsertBlock);
550
546
@@ -629,9 +625,6 @@ class InnerLoopVectorizer {
629
625
// / A list of all bypass blocks. The first block is the entry of the loop.
630
626
SmallVector<BasicBlock *, 4 > LoopBypassBlocks;
631
627
632
- // / Store instructions that were predicated.
633
- SmallVector<Instruction *, 4 > PredicatedInstructions;
634
-
635
628
// / Trip count of the original loop.
636
629
Value *TripCount = nullptr ;
637
630
@@ -2385,15 +2378,12 @@ void InnerLoopVectorizer::scalarizeInstruction(const Instruction *Instr,
2385
2378
2386
2379
// End if-block.
2387
2380
VPRegionBlock *Parent = RepRecipe->getParent ()->getParent ();
2388
- bool IfPredicateInstr = Parent ? Parent->isReplicator () : false ;
2389
2381
assert (
2390
2382
(Parent || !RepRecipe->getParent ()->getPlan ()->getVectorLoopRegion () ||
2391
2383
all_of (RepRecipe->operands (),
2392
2384
[](VPValue *Op) { return Op->isDefinedOutsideLoopRegions (); })) &&
2393
2385
" Expected a recipe is either within a region or all of its operands "
2394
2386
" are defined outside the vectorized region." );
2395
- if (IfPredicateInstr)
2396
- PredicatedInstructions.push_back (Cloned);
2397
2387
}
2398
2388
2399
2389
Value *
@@ -2867,9 +2857,6 @@ void InnerLoopVectorizer::fixVectorizedLoop(VPTransformState &State) {
2867
2857
if (!State.Plan ->getVectorLoopRegion ())
2868
2858
return ;
2869
2859
2870
- for (Instruction *PI : PredicatedInstructions)
2871
- sinkScalarOperands (&*PI);
2872
-
2873
2860
VPRegionBlock *VectorRegion = State.Plan ->getVectorLoopRegion ();
2874
2861
VPBasicBlock *HeaderVPBB = VectorRegion->getEntryBasicBlock ();
2875
2862
BasicBlock *HeaderBB = State.CFG .VPBB2IRBB [HeaderVPBB];
@@ -2895,82 +2882,6 @@ void InnerLoopVectorizer::fixVectorizedLoop(VPTransformState &State) {
2895
2882
VF.getKnownMinValue () * UF);
2896
2883
}
2897
2884
2898
- void InnerLoopVectorizer::sinkScalarOperands (Instruction *PredInst) {
2899
- // The basic block and loop containing the predicated instruction.
2900
- auto *PredBB = PredInst->getParent ();
2901
- auto *VectorLoop = LI->getLoopFor (PredBB);
2902
-
2903
- // Initialize a worklist with the operands of the predicated instruction.
2904
- SetVector<Value *> Worklist (PredInst->op_begin (), PredInst->op_end ());
2905
-
2906
- // Holds instructions that we need to analyze again. An instruction may be
2907
- // reanalyzed if we don't yet know if we can sink it or not.
2908
- SmallVector<Instruction *, 8 > InstsToReanalyze;
2909
-
2910
- // Returns true if a given use occurs in the predicated block. Phi nodes use
2911
- // their operands in their corresponding predecessor blocks.
2912
- auto IsBlockOfUsePredicated = [&](Use &U) -> bool {
2913
- auto *I = cast<Instruction>(U.getUser ());
2914
- BasicBlock *BB = I->getParent ();
2915
- if (auto *Phi = dyn_cast<PHINode>(I))
2916
- BB = Phi->getIncomingBlock (
2917
- PHINode::getIncomingValueNumForOperand (U.getOperandNo ()));
2918
- return BB == PredBB;
2919
- };
2920
-
2921
- // Iteratively sink the scalarized operands of the predicated instruction
2922
- // into the block we created for it. When an instruction is sunk, it's
2923
- // operands are then added to the worklist. The algorithm ends after one pass
2924
- // through the worklist doesn't sink a single instruction.
2925
- bool Changed;
2926
- do {
2927
- // Add the instructions that need to be reanalyzed to the worklist, and
2928
- // reset the changed indicator.
2929
- Worklist.insert_range (InstsToReanalyze);
2930
- InstsToReanalyze.clear ();
2931
- Changed = false ;
2932
-
2933
- while (!Worklist.empty ()) {
2934
- auto *I = dyn_cast<Instruction>(Worklist.pop_back_val ());
2935
-
2936
- // We can't sink an instruction if it is a phi node, is not in the loop,
2937
- // may have side effects or may read from memory.
2938
- // TODO: Could do more granular checking to allow sinking
2939
- // a load past non-store instructions.
2940
- if (!I || isa<PHINode>(I) || !VectorLoop->contains (I) ||
2941
- I->mayHaveSideEffects () || I->mayReadFromMemory ())
2942
- continue ;
2943
-
2944
- // If the instruction is already in PredBB, check if we can sink its
2945
- // operands. In that case, VPlan's sinkScalarOperands() succeeded in
2946
- // sinking the scalar instruction I, hence it appears in PredBB; but it
2947
- // may have failed to sink I's operands (recursively), which we try
2948
- // (again) here.
2949
- if (I->getParent () == PredBB) {
2950
- Worklist.insert_range (I->operands ());
2951
- continue ;
2952
- }
2953
-
2954
- // It's legal to sink the instruction if all its uses occur in the
2955
- // predicated block. Otherwise, there's nothing to do yet, and we may
2956
- // need to reanalyze the instruction.
2957
- if (!llvm::all_of (I->uses (), IsBlockOfUsePredicated)) {
2958
- InstsToReanalyze.push_back (I);
2959
- continue ;
2960
- }
2961
-
2962
- // Move the instruction to the beginning of the predicated block, and add
2963
- // it's operands to the worklist.
2964
- I->moveBefore (PredBB->getFirstInsertionPt ());
2965
- Worklist.insert_range (I->operands ());
2966
-
2967
- // The sinking may have enabled other instructions to be sunk, so we will
2968
- // need to iterate.
2969
- Changed = true ;
2970
- }
2971
- } while (Changed);
2972
- }
2973
-
2974
2885
void InnerLoopVectorizer::fixNonInductionPHIs (VPTransformState &State) {
2975
2886
auto Iter = vp_depth_first_deep (Plan.getEntry ());
2976
2887
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(Iter)) {
0 commit comments