Skip to content

Commit 4a13e06

Browse files
committed
[LV] Allow VPWidenPHI in non-native path and copy DebugLoc
We can reuse VPWidenPHI in llvm#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 0adab6b commit 4a13e06

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
@@ -511,7 +511,7 @@ class InnerLoopVectorizer {
511511
VPTransformState &State);
512512

513513
/// Fix the non-induction PHIs in \p Plan.
514-
void fixNonInductionPHIs(VPTransformState &State);
514+
void fixWidenedPHIs(VPTransformState &State);
515515

516516
/// Create a new phi node for the induction variable \p OrigPhi to resume
517517
/// iteration count in the scalar epilogue, from where the vectorized loop
@@ -2931,9 +2931,8 @@ LoopVectorizationCostModel::getVectorIntrinsicCost(CallInst *CI,
29312931
}
29322932

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

29382937
// Forget the original basic block.
29392938
PSE.getSE()->forgetLoop(OrigLoop);
@@ -3070,7 +3069,7 @@ void InnerLoopVectorizer::sinkScalarOperands(Instruction *PredInst) {
30703069
} while (Changed);
30713070
}
30723071

3073-
void InnerLoopVectorizer::fixNonInductionPHIs(VPTransformState &State) {
3072+
void InnerLoopVectorizer::fixWidenedPHIs(VPTransformState &State) {
30743073
auto Iter = vp_depth_first_deep(Plan.getEntry());
30753074
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(Iter)) {
30763075
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
@@ -2285,10 +2285,16 @@ class VPWidenPHIRecipe : public VPSingleDefRecipe {
22852285
/// List of incoming blocks. Only used in the VPlan native path.
22862286
SmallVector<VPBasicBlock *, 2> IncomingBlocks;
22872287

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

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

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

34193419
void VPWidenPHIRecipe::execute(VPTransformState &State) {
3420-
assert(EnableVPlanNativePath &&
3421-
"Non-native vplans are not expected to have VPWidenPHIRecipes.");
3422-
3420+
State.setDebugLocFrom(getDebugLoc());
34233421
Value *Op0 = State.get(getOperand(0));
34243422
Type *VecTy = Op0->getType();
3425-
Value *VecPhi = State.Builder.CreatePHI(VecTy, 2, "vec.phi");
3423+
Value *VecPhi = State.Builder.CreatePHI(VecTy, 2, Name);
34263424
State.set(this, VecPhi);
34273425
}
34283426

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)