Skip to content

Commit 021e4bd

Browse files
committed
!fixup introduce and use VPIRInstruction::extractLastLaneOfOperand.
1 parent 8994cdf commit 021e4bd

File tree

4 files changed

+30
-18
lines changed

4 files changed

+30
-18
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff 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

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class RecurrenceDescriptor;
6060
class SCEV;
6161
class Type;
6262
class VPBasicBlock;
63+
class VPBuilder;
6364
class VPRegionBlock;
6465
class VPlan;
6566
class 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

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
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)
941958
void VPIRInstruction::print(raw_ostream &O, const Twine &Indent,
942959
VPSlotTracker &SlotTracker) const {

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff 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);

0 commit comments

Comments
 (0)