@@ -541,10 +541,6 @@ class InnerLoopVectorizer {
541541protected:
542542 friend class LoopVectorizationPlanner ;
543543
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-
548544 // / Returns (and creates if needed) the trip count of the widened loop.
549545 Value *getOrCreateVectorTripCount (BasicBlock *InsertBlock);
550546
@@ -629,9 +625,6 @@ class InnerLoopVectorizer {
629625 // / A list of all bypass blocks. The first block is the entry of the loop.
630626 SmallVector<BasicBlock *, 4 > LoopBypassBlocks;
631627
632- // / Store instructions that were predicated.
633- SmallVector<Instruction *, 4 > PredicatedInstructions;
634-
635628 // / Trip count of the original loop.
636629 Value *TripCount = nullptr ;
637630
@@ -2385,15 +2378,12 @@ void InnerLoopVectorizer::scalarizeInstruction(const Instruction *Instr,
23852378
23862379 // End if-block.
23872380 VPRegionBlock *Parent = RepRecipe->getParent ()->getParent ();
2388- bool IfPredicateInstr = Parent ? Parent->isReplicator () : false ;
23892381 assert (
23902382 (Parent || !RepRecipe->getParent ()->getPlan ()->getVectorLoopRegion () ||
23912383 all_of (RepRecipe->operands (),
23922384 [](VPValue *Op) { return Op->isDefinedOutsideLoopRegions (); })) &&
23932385 " Expected a recipe is either within a region or all of its operands "
23942386 " are defined outside the vectorized region." );
2395- if (IfPredicateInstr)
2396- PredicatedInstructions.push_back (Cloned);
23972387}
23982388
23992389Value *
@@ -2867,9 +2857,6 @@ void InnerLoopVectorizer::fixVectorizedLoop(VPTransformState &State) {
28672857 if (!State.Plan ->getVectorLoopRegion ())
28682858 return ;
28692859
2870- for (Instruction *PI : PredicatedInstructions)
2871- sinkScalarOperands (&*PI);
2872-
28732860 VPRegionBlock *VectorRegion = State.Plan ->getVectorLoopRegion ();
28742861 VPBasicBlock *HeaderVPBB = VectorRegion->getEntryBasicBlock ();
28752862 BasicBlock *HeaderBB = State.CFG .VPBB2IRBB [HeaderVPBB];
@@ -2895,82 +2882,6 @@ void InnerLoopVectorizer::fixVectorizedLoop(VPTransformState &State) {
28952882 VF.getKnownMinValue () * UF);
28962883}
28972884
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-
29742885void InnerLoopVectorizer::fixNonInductionPHIs (VPTransformState &State) {
29752886 auto Iter = vp_depth_first_deep (Plan.getEntry ());
29762887 for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(Iter)) {
0 commit comments