Skip to content

Commit 590f451

Browse files
committed
[VPlan] Allow setting IR name for VPDerivedIVRecipe (NFCI).
Allow setting the name to use for the generated IR value of the derived IV in preparations for #112145. This is analogous to VPInstruction::Name.
1 parent 1cd6275 commit 590f451

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,9 @@ class VPBuilder {
234234
VPDerivedIVRecipe *createDerivedIV(InductionDescriptor::InductionKind Kind,
235235
FPMathOperator *FPBinOp, VPValue *Start,
236236
VPCanonicalIVPHIRecipe *CanonicalIV,
237-
VPValue *Step) {
237+
VPValue *Step, const Twine &Name = "") {
238238
return tryInsertInstruction(
239-
new VPDerivedIVRecipe(Kind, FPBinOp, Start, CanonicalIV, Step));
239+
new VPDerivedIVRecipe(Kind, FPBinOp, Start, CanonicalIV, Step, Name));
240240
}
241241

242242
VPScalarCastRecipe *createScalarCast(Instruction::CastOps Opcode, VPValue *Op,

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9603,7 +9603,7 @@ void VPDerivedIVRecipe::execute(VPTransformState &State) {
96039603
Value *DerivedIV = emitTransformedIndex(
96049604
State.Builder, CanonicalIV, getStartValue()->getLiveInIRValue(), Step,
96059605
Kind, cast_if_present<BinaryOperator>(FPBinOp));
9606-
DerivedIV->setName("offset.idx");
9606+
DerivedIV->setName(Name);
96079607
assert(DerivedIV != CanonicalIV && "IV didn't need transforming?");
96089608

96099609
State.set(this, DerivedIV, VPLane(0));

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3301,19 +3301,23 @@ class VPDerivedIVRecipe : public VPSingleDefRecipe {
33013301
/// for floating point inductions.
33023302
const FPMathOperator *FPBinOp;
33033303

3304+
/// Name to use for the generated IR instruction for the derived IV.
3305+
std::string Name;
3306+
33043307
public:
33053308
VPDerivedIVRecipe(const InductionDescriptor &IndDesc, VPValue *Start,
3306-
VPCanonicalIVPHIRecipe *CanonicalIV, VPValue *Step)
3309+
VPCanonicalIVPHIRecipe *CanonicalIV, VPValue *Step,
3310+
const Twine &Name = "")
33073311
: VPDerivedIVRecipe(
33083312
IndDesc.getKind(),
33093313
dyn_cast_or_null<FPMathOperator>(IndDesc.getInductionBinOp()),
3310-
Start, CanonicalIV, Step) {}
3314+
Start, CanonicalIV, Step, Name) {}
33113315

33123316
VPDerivedIVRecipe(InductionDescriptor::InductionKind Kind,
33133317
const FPMathOperator *FPBinOp, VPValue *Start, VPValue *IV,
3314-
VPValue *Step)
3318+
VPValue *Step, const Twine &Name = "")
33153319
: VPSingleDefRecipe(VPDef::VPDerivedIVSC, {Start, IV, Step}), Kind(Kind),
3316-
FPBinOp(FPBinOp) {}
3320+
FPBinOp(FPBinOp), Name(Name.str()) {}
33173321

33183322
~VPDerivedIVRecipe() override = default;
33193323

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,8 @@ createScalarIVSteps(VPlan &Plan, InductionDescriptor::InductionKind Kind,
528528
VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV();
529529
VPSingleDefRecipe *BaseIV = CanonicalIV;
530530
if (!CanonicalIV->isCanonical(Kind, StartV, Step)) {
531-
BaseIV = Builder.createDerivedIV(Kind, FPBinOp, StartV, CanonicalIV, Step);
531+
BaseIV = Builder.createDerivedIV(Kind, FPBinOp, StartV, CanonicalIV, Step,
532+
"offset.idx");
532533
}
533534

534535
// Truncate base induction if needed.

llvm/test/Transforms/LoopVectorize/branch-weights.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
; CHECK: br label %vector.body
1919
;
2020
; CHECK: vector.body:
21-
; CHECK: br i1 %8, label %middle.block, label %vector.body, !prof [[PROF_F0_VECTOR_BODY:![0-9]+]]
21+
; CHECK: br i1 {{.+}}, label %middle.block, label %vector.body, !prof [[PROF_F0_VECTOR_BODY:![0-9]+]]
2222
;
2323
; CHECK: middle.block:
2424
; CHECK: br i1 %cmp.n, label %exit.loopexit, label %vec.epilog.iter.check, !prof [[PROF_F0_MIDDLE_BLOCKS:![0-9]+]]
@@ -30,10 +30,10 @@
3030
; CHECK: br label %vec.epilog.vector.body
3131
;
3232
; CHECK: vec.epilog.vector.body:
33-
; CHECK: br i1 %12, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !prof [[PROF_F0_VEC_EPILOG_VECTOR_BODY:![0-9]+]]
33+
; CHECK: br i1 {{.+}}, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !prof [[PROF_F0_VEC_EPILOG_VECTOR_BODY:![0-9]+]]
3434
;
3535
; CHECK: vec.epilog.middle.block:
36-
; CHECK: br i1 %cmp.n12, label %exit.loopexit, label %vec.epilog.scalar.ph, !prof [[PROF_F0_MIDDLE_BLOCKS:![0-9]+]]
36+
; CHECK: br i1 %cmp.n11, label %exit.loopexit, label %vec.epilog.scalar.ph, !prof [[PROF_F0_MIDDLE_BLOCKS:![0-9]+]]
3737
;
3838
; CHECK: vec.epilog.scalar.ph:
3939
; CHECK: br label %loop

0 commit comments

Comments
 (0)