Skip to content

Commit 6ce41db

Browse files
committed
[VPlan] Preserve DebugLoc for VPBranchOnMaskRecipe.
Update code to set and generate debug location for branch recipe
1 parent e5d9310 commit 6ce41db

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2502,11 +2502,11 @@ class VPReplicateRecipe : public VPRecipeWithIRFlags {
25022502
/// A recipe for generating conditional branches on the bits of a mask.
25032503
class VPBranchOnMaskRecipe : public VPRecipeBase {
25042504
public:
2505-
VPBranchOnMaskRecipe(VPValue *BlockInMask)
2506-
: VPRecipeBase(VPDef::VPBranchOnMaskSC, {BlockInMask}) {}
2505+
VPBranchOnMaskRecipe(VPValue *BlockInMask, DebugLoc DL)
2506+
: VPRecipeBase(VPDef::VPBranchOnMaskSC, {BlockInMask}, DL) {}
25072507

25082508
VPBranchOnMaskRecipe *clone() override {
2509-
return new VPBranchOnMaskRecipe(getOperand(0));
2509+
return new VPBranchOnMaskRecipe(getOperand(0), getDebugLoc());
25102510
}
25112511

25122512
VP_CLASSOF_IMPL(VPDef::VPBranchOnMaskSC)

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,6 +2469,7 @@ void VPScalarCastRecipe ::print(raw_ostream &O, const Twine &Indent,
24692469
#endif
24702470

24712471
void VPBranchOnMaskRecipe::execute(VPTransformState &State) {
2472+
State.setDebugLocFrom(getDebugLoc());
24722473
assert(State.Lane && "Branch on Mask works only on single instance.");
24732474

24742475
VPValue *BlockInMask = getOperand(0);
@@ -2479,9 +2480,10 @@ void VPBranchOnMaskRecipe::execute(VPTransformState &State) {
24792480
auto *CurrentTerminator = State.CFG.PrevBB->getTerminator();
24802481
assert(isa<UnreachableInst>(CurrentTerminator) &&
24812482
"Expected to replace unreachable terminator with conditional branch.");
2482-
auto *CondBr = BranchInst::Create(State.CFG.PrevBB, nullptr, ConditionBit);
2483+
auto CondBr =
2484+
State.Builder.CreateCondBr(ConditionBit, State.CFG.PrevBB, nullptr);
24832485
CondBr->setSuccessor(0, nullptr);
2484-
ReplaceInstWithInst(CurrentTerminator, CondBr);
2486+
CurrentTerminator->eraseFromParent();
24852487
}
24862488

24872489
InstructionCost VPBranchOnMaskRecipe::computeCost(ElementCount VF,

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,9 @@ static VPRegionBlock *createReplicateRegion(VPReplicateRecipe *PredRecipe,
309309
std::string RegionName = (Twine("pred.") + Instr->getOpcodeName()).str();
310310
assert(Instr->getParent() && "Predicated instruction not in any basic block");
311311
auto *BlockInMask = PredRecipe->getMask();
312-
auto *BOMRecipe = new VPBranchOnMaskRecipe(BlockInMask);
312+
auto *MaskDef = BlockInMask->getDefiningRecipe();
313+
auto *BOMRecipe = new VPBranchOnMaskRecipe(
314+
BlockInMask, MaskDef ? MaskDef->getDebugLoc() : DebugLoc());
313315
auto *Entry =
314316
Plan.createVPBasicBlock(Twine(RegionName) + ".entry", BOMRecipe);
315317

llvm/test/Transforms/LoopVectorize/debugloc.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ define i32 @test_debug_loc_on_branch_in_loop(ptr noalias %src, ptr noalias %dst)
6464
; CHECK-NEXT: [[CMP:%.+]] = icmp eq <2 x i32> [[LOAD]], splat (i32 10)
6565
; CHECK-NEXT: [[XOR:%.+]] = xor <2 x i1> [[CMP:%.+]], splat (i1 true), !dbg [[LOC3:!.+]]
6666
; CHECK-NEXT: [[EXT:%.+]] = extractelement <2 x i1> [[XOR]], i32 0, !dbg [[LOC3]]
67-
; CHECK-NEXT: br i1 [[EXT]], label %pred.store.if, label %pred.store.continue
68-
; CHECK-NOT: !dbg
67+
; CHECK-NEXT: br i1 [[EXT]], label %pred.store.if, label %pred.store.continue, !dbg [[LOC3]]
6968
; CHECK-EMPTY:
7069
; CHECK-NEXT: pred.store.if:
7170
; CHECK-NEXT: [[GEP:%.+]] = getelementptr inbounds i32, ptr %dst, i64 {{.+}}, !dbg [[LOC3]]
@@ -104,8 +103,7 @@ define i32 @test_different_debug_loc_on_replicate_recipe(ptr noalias %src, ptr n
104103
; CHECK-NEXT: [[CMP:%.+]] = icmp eq <2 x i32> [[LOAD]], splat (i32 10)
105104
; CHECK-NEXT: [[XOR:%.+]] = xor <2 x i1> [[CMP:%.+]], splat (i1 true), !dbg [[LOC4:!.+]]
106105
; CHECK-NEXT: [[EXT:%.+]] = extractelement <2 x i1> [[XOR]], i32 0, !dbg [[LOC4]]
107-
; CHECK-NEXT: br i1 [[EXT]], label %pred.store.if, label %pred.store.continue
108-
; CHECK-NOT: !dbg
106+
; CHECK-NEXT: br i1 [[EXT]], label %pred.store.if, label %pred.store.continue, !dbg [[LOC4]]
109107
; CHECK-EMPTY:
110108
; CHECK-NEXT: pred.store.if:
111109
; CHECK-NEXT: [[GEP:%.+]] = getelementptr inbounds i32, ptr %dst, i64 {{.+}}, !dbg [[LOC5:!.+]]

llvm/unittests/Transforms/Vectorize/VPlanTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ TEST_F(VPRecipeTest, CastVPBranchOnMaskRecipeToVPUser) {
10691069
VPlan &Plan = getPlan();
10701070
IntegerType *Int32 = IntegerType::get(C, 32);
10711071
VPValue *Mask = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
1072-
VPBranchOnMaskRecipe Recipe(Mask);
1072+
VPBranchOnMaskRecipe Recipe(Mask, {});
10731073
EXPECT_TRUE(isa<VPUser>(&Recipe));
10741074
VPRecipeBase *BaseR = &Recipe;
10751075
EXPECT_TRUE(isa<VPUser>(BaseR));
@@ -1157,7 +1157,7 @@ TEST_F(VPRecipeTest, MayHaveSideEffectsAndMayReadWriteMemory) {
11571157
{
11581158
VPValue *Mask = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
11591159

1160-
VPBranchOnMaskRecipe Recipe(Mask);
1160+
VPBranchOnMaskRecipe Recipe(Mask, {});
11611161
EXPECT_TRUE(Recipe.mayHaveSideEffects());
11621162
EXPECT_FALSE(Recipe.mayReadFromMemory());
11631163
EXPECT_FALSE(Recipe.mayWriteToMemory());

0 commit comments

Comments
 (0)