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