Skip to content

Commit 9b496de

Browse files
committed
[VPlan] Set and use debug location for VPPredInstPHIRecipe.
Update the recipe it always set its debug location and use it during IR generation.
1 parent fd78472 commit 9b496de

File tree

5 files changed

+41
-8
lines changed

5 files changed

+41
-8
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2839,12 +2839,12 @@ class VPPredInstPHIRecipe : public VPSingleDefRecipe {
28392839
public:
28402840
/// Construct a VPPredInstPHIRecipe given \p PredInst whose value needs a phi
28412841
/// nodes after merging back from a Branch-on-Mask.
2842-
VPPredInstPHIRecipe(VPValue *PredV)
2843-
: VPSingleDefRecipe(VPDef::VPPredInstPHISC, PredV) {}
2842+
VPPredInstPHIRecipe(VPValue *PredV, DebugLoc DL)
2843+
: VPSingleDefRecipe(VPDef::VPPredInstPHISC, PredV, DL) {}
28442844
~VPPredInstPHIRecipe() override = default;
28452845

28462846
VPPredInstPHIRecipe *clone() override {
2847-
return new VPPredInstPHIRecipe(getOperand(0));
2847+
return new VPPredInstPHIRecipe(getOperand(0), getDebugLoc());
28482848
}
28492849

28502850
VP_CLASSOF_IMPL(VPDef::VPPredInstPHISC)

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2392,6 +2392,7 @@ InstructionCost VPBranchOnMaskRecipe::computeCost(ElementCount VF,
23922392
}
23932393

23942394
void VPPredInstPHIRecipe::execute(VPTransformState &State) {
2395+
State.setDebugLocFrom(getDebugLoc());
23952396
assert(State.Lane && "Predicated instruction PHI works per instance.");
23962397
Instruction *ScalarPredInst =
23972398
cast<Instruction>(State.get(getOperand(0), *State.Lane));

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ static VPRegionBlock *createReplicateRegion(VPReplicateRecipe *PredRecipe,
322322

323323
VPPredInstPHIRecipe *PHIRecipe = nullptr;
324324
if (PredRecipe->getNumUsers() != 0) {
325-
PHIRecipe = new VPPredInstPHIRecipe(RecipeWithoutMask);
325+
PHIRecipe = new VPPredInstPHIRecipe(RecipeWithoutMask,
326+
RecipeWithoutMask->getDebugLoc());
326327
PredRecipe->replaceAllUsesWith(PHIRecipe);
327328
PHIRecipe->setOperand(0, RecipeWithoutMask);
328329
}

llvm/test/Transforms/LoopVectorize/preserve-dbg-loc-and-loop-metadata.ll

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
; RUN: opt < %s -passes=loop-vectorize -force-vector-width=4 -S 2>&1 | FileCheck %s
2-
; RUN: opt < %s -passes=debugify,loop-vectorize -force-vector-width=4 -S | FileCheck %s -check-prefix DEBUGLOC
3-
; RUN: opt < %s -passes=debugify,loop-vectorize -force-vector-width=4 -S --try-experimental-debuginfo-iterators | FileCheck %s -check-prefix DEBUGLOC
1+
; RUN: opt < %s -passes=loop-vectorize -force-vector-width=4 -force-widen-divrem-via-safe-divisor=0 -S 2>&1 | FileCheck %s
2+
; RUN: opt < %s -passes=debugify,loop-vectorize -force-vector-width=4 -force-widen-divrem-via-safe-divisor=0 -S | FileCheck %s -check-prefix DEBUGLOC
3+
; RUN: opt < %s -passes=debugify,loop-vectorize -force-vector-width=4 -force-widen-divrem-via-safe-divisor=0 -S --try-experimental-debuginfo-iterators | FileCheck %s -check-prefix DEBUGLOC
44
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
55

66
; This test makes sure we don't duplicate the loop vectorizer's metadata
@@ -54,6 +54,37 @@ exit:
5454
ret void
5555
}
5656

57+
define void @predicated_phi_dbg(i64 %n, ptr %x) {
58+
; DEBUGLOC-LABEL: define void @predicated_phi_dbg(
59+
; DEBUGLOC: pred.udiv.continue{{.+}}:
60+
; DEBUGLOC-NEXT: = phi <4 x i64> {{.+}}, !dbg [[PREDPHILOC:![0-9]+]]
61+
;
62+
; DEBUGLOC: for.body:
63+
; DEBUGLOC: %tmp4 = udiv i64 %n, %i, !dbg [[PREDPHILOC]]
64+
;
65+
entry:
66+
br label %for.body
67+
68+
for.body:
69+
%i = phi i64 [ 0, %entry ], [ %i.next, %for.inc ]
70+
%cmp = icmp ult i64 %i, 5
71+
br i1 %cmp, label %if.then, label %for.inc
72+
73+
if.then:
74+
%tmp4 = udiv i64 %n, %i
75+
br label %for.inc
76+
77+
for.inc:
78+
%d = phi i64 [ 0, %for.body ], [ %tmp4, %if.then ]
79+
%idx = getelementptr i64, ptr %x, i64 %i
80+
store i64 %d, ptr %idx
81+
%i.next = add nuw nsw i64 %i, 1
82+
%cond = icmp slt i64 %i.next, %n
83+
br i1 %cond, label %for.body, label %for.end
84+
85+
for.end:
86+
ret void
87+
}
5788

5889
!0 = !{!0, !1}
5990
!1 = !{!"llvm.loop.vectorize.width", i32 4}

llvm/unittests/Transforms/Vectorize/VPlanTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ TEST(VPRecipeTest, MayHaveSideEffectsAndMayReadWriteMemory) {
12871287
}
12881288
{
12891289
VPValue Op1;
1290-
VPPredInstPHIRecipe Recipe(&Op1);
1290+
VPPredInstPHIRecipe Recipe(&Op1, {});
12911291
EXPECT_FALSE(Recipe.mayHaveSideEffects());
12921292
EXPECT_FALSE(Recipe.mayReadFromMemory());
12931293
EXPECT_FALSE(Recipe.mayWriteToMemory());

0 commit comments

Comments
 (0)