Skip to content

Commit 431d6d9

Browse files
committed
[LV] Allow VPWidenPHI in non-native path and copy DebugLoc
We can reuse VPWidenPHI in #118638, but it requires us to allow it in the non-native path. We also need to propagate the DebugLoc and use a different name in the generated PHI, so this splits these parts off in case we want it. We lose some debug info in dbg-outer-loop-vect.ll, but I think this is because the underlying phi node didn't have a DebugLoc to begin with. I think the current version is just carrying over the DebugLoc from the previous state.
1 parent e4372c4 commit 431d6d9

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ class InnerLoopVectorizer {
516516
VPTransformState &State);
517517

518518
/// Fix the non-induction PHIs in \p Plan.
519-
void fixNonInductionPHIs(VPTransformState &State);
519+
void fixWidenedPHIs(VPTransformState &State);
520520

521521
/// Returns the original loop trip count.
522522
Value *getTripCount() const { return TripCount; }
@@ -2977,9 +2977,8 @@ LoopVectorizationCostModel::getVectorIntrinsicCost(CallInst *CI,
29772977
}
29782978

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

29842983
// Forget the original basic block.
29852984
PSE.getSE()->forgetLoop(OrigLoop);
@@ -3116,7 +3115,7 @@ void InnerLoopVectorizer::sinkScalarOperands(Instruction *PredInst) {
31163115
} while (Changed);
31173116
}
31183117

3119-
void InnerLoopVectorizer::fixNonInductionPHIs(VPTransformState &State) {
3118+
void InnerLoopVectorizer::fixWidenedPHIs(VPTransformState &State) {
31203119
auto Iter = vp_depth_first_deep(Plan.getEntry());
31213120
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(Iter)) {
31223121
for (VPRecipeBase &P : VPBB->phis()) {

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,10 +2287,16 @@ class VPWidenPHIRecipe : public VPSingleDefRecipe {
22872287
/// List of incoming blocks. Only used in the VPlan native path.
22882288
SmallVector<VPBasicBlock *, 2> IncomingBlocks;
22892289

2290+
/// Name to use for the generated IR instruction for the widened IV.
2291+
std::string Name;
2292+
22902293
public:
22912294
/// Create a new VPWidenPHIRecipe for \p Phi with start value \p Start.
2292-
VPWidenPHIRecipe(PHINode *Phi, VPValue *Start = nullptr)
2293-
: VPSingleDefRecipe(VPDef::VPWidenPHISC, ArrayRef<VPValue *>(), Phi) {
2295+
VPWidenPHIRecipe(PHINode *Phi, VPValue *Start = nullptr,
2296+
const Twine &Name = "vec.phi")
2297+
: VPSingleDefRecipe(VPDef::VPWidenPHISC, ArrayRef<VPValue *>(), Phi,
2298+
Phi->getDebugLoc()),
2299+
Name(Name.str()) {
22942300
if (Start)
22952301
addOperand(Start);
22962302
}

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3440,12 +3440,10 @@ void VPReductionPHIRecipe::print(raw_ostream &O, const Twine &Indent,
34403440
#endif
34413441

34423442
void VPWidenPHIRecipe::execute(VPTransformState &State) {
3443-
assert(EnableVPlanNativePath &&
3444-
"Non-native vplans are not expected to have VPWidenPHIRecipes.");
3445-
3443+
State.setDebugLocFrom(getDebugLoc());
34463444
Value *Op0 = State.get(getOperand(0));
34473445
Type *VecTy = Op0->getType();
3448-
Value *VecPhi = State.Builder.CreatePHI(VecTy, 2, "vec.phi");
3446+
Value *VecPhi = State.Builder.CreatePHI(VecTy, 2, Name);
34493447
State.set(this, VecPhi);
34503448
}
34513449

llvm/test/Transforms/LoopVectorize/dbg-outer-loop-vect.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ define void @foo(ptr %h) !dbg !4 {
1515
; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[FOR_COND_CLEANUP32:%.*]] ]
1616
; CHECK-NEXT: br label [[FOR_COND5_PREHEADER1:%.*]], !dbg [[DBG21]]
1717
; CHECK: for.cond5.preheader1:
18-
; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <4 x i64> [ zeroinitializer, [[VECTOR_BODY]] ], [ [[TMP4:%.*]], [[FOR_COND5_PREHEADER1]] ], !dbg [[DBG21]]
19-
; CHECK-NEXT: [[TMP0:%.*]] = getelementptr i32, ptr [[H]], <4 x i64> [[VEC_PHI]], !dbg [[DBG21]]
18+
; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <4 x i64> [ zeroinitializer, [[VECTOR_BODY]] ], [ [[TMP4:%.*]], [[FOR_COND5_PREHEADER1]] ]
19+
; CHECK-NEXT: [[TMP0:%.*]] = getelementptr i32, ptr [[H]], <4 x i64> [[VEC_PHI]]
2020
; CHECK-NEXT: call void @llvm.masked.scatter.v4i32.v4p0(<4 x i32> zeroinitializer, <4 x ptr> [[TMP0]], i32 4, <4 x i1> splat (i1 true)), !dbg [[DBG22:![0-9]+]]
2121
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr i32, <4 x ptr> [[TMP0]], i64 1, !dbg [[DBG22]]
2222
; CHECK-NEXT: call void @llvm.masked.scatter.v4i32.v4p0(<4 x i32> splat (i32 1), <4 x ptr> [[TMP1]], i32 4, <4 x i1> splat (i1 true)), !dbg [[DBG22]]

0 commit comments

Comments
 (0)