Skip to content

[VPlan] Allow VPWidenPHI in non-native path. NFC #118662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2978,8 +2978,7 @@ LoopVectorizationCostModel::getVectorIntrinsicCost(CallInst *CI,

void InnerLoopVectorizer::fixVectorizedLoop(VPTransformState &State) {
// Fix widened non-induction PHIs by setting up the PHI operands.
if (EnableVPlanNativePath)
fixNonInductionPHIs(State);
fixNonInductionPHIs(State);

// Forget the original basic block.
PSE.getSE()->forgetLoop(OrigLoop);
Expand Down
16 changes: 12 additions & 4 deletions llvm/lib/Transforms/Vectorize/VPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -2287,10 +2287,16 @@ class VPWidenPHIRecipe : public VPSingleDefRecipe {
/// List of incoming blocks. Only used in the VPlan native path.
SmallVector<VPBasicBlock *, 2> IncomingBlocks;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe update the comments above re: usage in vplan native? Given this is now used in both paths, do these need delete or clarified?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IncomingBlocks should still only be used in the vplan native path, so I've added more comments to the other methods that should only be called from it


/// Name to use for the generated IR instruction for the widened IV.
std::string Name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use SmallString or Twine?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::string seems to be what everything else in VPlan.h uses, and it doesn't look like Twine can be stored


public:
/// Create a new VPWidenPHIRecipe for \p Phi with start value \p Start.
VPWidenPHIRecipe(PHINode *Phi, VPValue *Start = nullptr)
: VPSingleDefRecipe(VPDef::VPWidenPHISC, ArrayRef<VPValue *>(), Phi) {
VPWidenPHIRecipe(PHINode *Phi, VPValue *Start = nullptr,
const Twine &Name = "vec.phi")
: VPSingleDefRecipe(VPDef::VPWidenPHISC, ArrayRef<VPValue *>(), Phi,
Phi->getDebugLoc()),
Name(Name.str()) {
if (Start)
addOperand(Start);
}
Expand All @@ -2312,13 +2318,15 @@ class VPWidenPHIRecipe : public VPSingleDefRecipe {
VPSlotTracker &SlotTracker) const override;
#endif

/// Adds a pair (\p IncomingV, \p IncomingBlock) to the phi.
/// Adds a pair (\p IncomingV, \p IncomingBlock) to the phi. Only used in the
/// VPlan native path.
void addIncoming(VPValue *IncomingV, VPBasicBlock *IncomingBlock) {
addOperand(IncomingV);
IncomingBlocks.push_back(IncomingBlock);
}

/// Returns the \p I th incoming VPBasicBlock.
/// Returns the \p I th incoming VPBasicBlock. Only used in the VPlan native
/// path.
VPBasicBlock *getIncomingBlock(unsigned I) { return IncomingBlocks[I]; }

/// Returns the \p I th incoming VPValue.
Expand Down
7 changes: 4 additions & 3 deletions llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3440,12 +3440,13 @@ void VPReductionPHIRecipe::print(raw_ostream &O, const Twine &Indent,
#endif

void VPWidenPHIRecipe::execute(VPTransformState &State) {
assert(EnableVPlanNativePath &&
"Non-native vplans are not expected to have VPWidenPHIRecipes.");
assert((EnableVPlanNativePath || IncomingBlocks.empty()) &&
"Non-native vplans are not expected to have VPWidenPHIRecipes with "
"incoming blocks.");

Value *Op0 = State.get(getOperand(0));
Type *VecTy = Op0->getType();
Value *VecPhi = State.Builder.CreatePHI(VecTy, 2, "vec.phi");
Value *VecPhi = State.Builder.CreatePHI(VecTy, 2, Name);
State.set(this, VecPhi);
}

Expand Down
Loading