File tree Expand file tree Collapse file tree 4 files changed +30
-18
lines changed
llvm/lib/Transforms/Vectorize Expand file tree Collapse file tree 4 files changed +30
-18
lines changed Original file line number Diff line number Diff line change @@ -9095,16 +9095,11 @@ addUsersInExitBlocks(VPlan &Plan,
90959095 // Introduce extract for exiting values and update the VPIRInstructions
90969096 // modeling the corresponding LCSSA phis.
90979097 for (VPIRInstruction *ExitIRI : ExitUsersToFix) {
9098- for (const auto &[Idx, Op] : enumerate(ExitIRI->operands ())) {
9099- assert (ExitIRI->getParent ()->getSinglePredecessor () == MiddleVPBB &&
9100- " exit values from early exits must be fixed when branch to "
9101- " early-exit is added" );
9102- LLVMContext &Ctx = ExitIRI->getInstruction ().getContext ();
9103- VPValue *Ext = B.createNaryOp (VPInstruction::ExtractFromEnd,
9104- {Op, Plan.getOrAddLiveIn (ConstantInt::get (
9105- IntegerType::get (Ctx, 32 ), 1 ))});
9106- ExitIRI->setOperand (Idx, Ext);
9107- }
9098+ assert (ExitIRI->getNumOperands () == 1 &&
9099+ ExitIRI->getParent ()->getSinglePredecessor () == MiddleVPBB &&
9100+ " exit values from early exits must be fixed when branch to "
9101+ " early-exit is added" );
9102+ ExitIRI->extractLastLaneOfOperand (B);
91089103 }
91099104}
91109105
Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ class RecurrenceDescriptor;
6060class SCEV ;
6161class Type ;
6262class VPBasicBlock ;
63+ class VPBuilder ;
6364class VPRegionBlock ;
6465class VPlan ;
6566class VPReplicateRecipe ;
@@ -1428,6 +1429,11 @@ class VPIRInstruction : public VPRecipeBase {
14281429 " Op must be an operand of the recipe" );
14291430 return true ;
14301431 }
1432+
1433+ // / Update the recipes single operand to the last lane of the operand using \p
1434+ // / Builder. Must only be used for single operand VPIRInstructions wrapping a
1435+ // / PHINode.
1436+ void extractLastLaneOfOperand (VPBuilder &Builder);
14311437};
14321438
14331439// / VPWidenRecipe is a recipe for producing a widened instruction using the
Original file line number Diff line number Diff line change 1111// /
1212// ===----------------------------------------------------------------------===//
1313
14+ #include " LoopVectorizationPlanner.h"
1415#include " VPlan.h"
1516#include " VPlanAnalysis.h"
1617#include " VPlanPatternMatch.h"
@@ -937,6 +938,22 @@ InstructionCost VPIRInstruction::computeCost(ElementCount VF,
937938 return 0 ;
938939}
939940
941+ void VPIRInstruction::extractLastLaneOfOperand (VPBuilder &Builder) {
942+ assert (isa<PHINode>(getInstruction ()) &&
943+ " can only add exiting operands to phi nodes" );
944+ assert (getNumOperands () == 1 && " must have a single operand" );
945+ VPValue *Exiting = getOperand (0 );
946+ if (!Exiting->isLiveIn ()) {
947+ LLVMContext &Ctx = getInstruction ().getContext ();
948+ auto &Plan = *getParent ()->getPlan ();
949+ Exiting = Builder.createNaryOp (
950+ VPInstruction::ExtractFromEnd,
951+ {Exiting,
952+ Plan.getOrAddLiveIn (ConstantInt::get (IntegerType::get (Ctx, 32 ), 1 ))});
953+ }
954+ setOperand (0 , Exiting);
955+ }
956+
940957#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
941958void VPIRInstruction::print (raw_ostream &O, const Twine &Indent,
942959 VPSlotTracker &SlotTracker) const {
Original file line number Diff line number Diff line change @@ -2114,7 +2114,7 @@ bool VPlanTransforms::handleUncountableEarlyExit(
21142114 VPValue *IncomingFromEarlyExit = RecipeBuilder.getVPValueOrAddLiveIn (
21152115 ExitPhi->getIncomingValueForBlock (UncountableExitingBlock));
21162116 // The incoming value from the early exit must be a live-in for now.
2117- if (!IncomingFromm EarlyExit ->isLiveIn ())
2117+ if (!IncomingFromEarlyExit ->isLiveIn ())
21182118 return false ;
21192119
21202120 if (OrigLoop->getUniqueExitBlock ()) {
@@ -2123,14 +2123,8 @@ bool VPlanTransforms::handleUncountableEarlyExit(
21232123 // which is coming from the original latch.
21242124 VPValue *IncomingFromLatch = RecipeBuilder.getVPValueOrAddLiveIn (
21252125 ExitPhi->getIncomingValueForBlock (OrigLoop->getLoopLatch ()));
2126- if (!IncomingFromLatch->isLiveIn ()) {
2127- LLVMContext &Ctx = ExitIRI->getInstruction ().getContext ();
2128- IncomingFromLatch = MiddleBuilder.createNaryOp (
2129- VPInstruction::ExtractFromEnd,
2130- {IncomingFromLatch, Plan.getOrAddLiveIn (ConstantInt::get (
2131- IntegerType::get (Ctx, 32 ), 1 ))});
2132- }
21332126 ExitIRI->addOperand (IncomingFromLatch);
2127+ ExitIRI->extractLastLaneOfOperand (MiddleBuilder);
21342128 }
21352129 // Add the incoming value from the early exit.
21362130 ExitIRI->addOperand (IncomingFromEarlyExit);
You can’t perform that action at this time.
0 commit comments