Skip to content

Commit 92163e9

Browse files
committed
!fixup, address comments.
1 parent ff7c797 commit 92163e9

File tree

4 files changed

+37
-31
lines changed

4 files changed

+37
-31
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

+18-14
Original file line numberDiff line numberDiff line change
@@ -1265,8 +1265,8 @@ class VPWidenRecipe : public VPRecipeWithIRFlags, public VPIRMetadata {
12651265
Opcode(I.getOpcode()) {}
12661266

12671267
template <typename IterT>
1268-
VPWidenRecipe(unsigned VPDefOpcode, unsigned Opcode,
1269-
iterator_range<IterT> Operands, bool NUW, bool NSW, DebugLoc DL)
1268+
VPWidenRecipe(unsigned VPDefOpcode, unsigned Opcode, ArrayRef<IterT> Operands,
1269+
bool NUW, bool NSW, DebugLoc DL)
12701270
: VPRecipeWithIRFlags(VPDefOpcode, Operands, WrapFlagsTy(NUW, NSW), DL),
12711271
Opcode(Opcode) {}
12721272

@@ -1275,8 +1275,8 @@ class VPWidenRecipe : public VPRecipeWithIRFlags, public VPIRMetadata {
12751275
: VPWidenRecipe(VPDef::VPWidenSC, I, Operands) {}
12761276

12771277
template <typename IterT>
1278-
VPWidenRecipe(unsigned Opcode, iterator_range<IterT> Operands, bool NUW,
1279-
bool NSW, DebugLoc DL)
1278+
VPWidenRecipe(unsigned Opcode, ArrayRef<IterT> Operands, bool NUW, bool NSW,
1279+
DebugLoc DL)
12801280
: VPWidenRecipe(VPDef::VPWidenSC, Opcode, Operands, NUW, NSW, DL) {}
12811281

12821282
~VPWidenRecipe() override = default;
@@ -2558,9 +2558,10 @@ class VPReductionEVLRecipe : public VPReductionRecipe {
25582558
/// concrete recipes before codegen. The operands are {ChainOp, VecOp,
25592559
/// [Condition]}.
25602560
class VPExtendedReductionRecipe : public VPReductionRecipe {
2561-
/// Opcode of the extend recipe will be lowered to.
2561+
/// Opcode of the extend for VecOp.
25622562
Instruction::CastOps ExtOp;
25632563

2564+
/// The scalar type after extending.
25642565
Type *ResultTy;
25652566

25662567
/// For cloning VPExtendedReductionRecipe.
@@ -2581,7 +2582,7 @@ class VPExtendedReductionRecipe : public VPReductionRecipe {
25812582
ExtOp(Ext->getOpcode()), ResultTy(Ext->getResultType()) {
25822583
assert((ExtOp == Instruction::CastOps::ZExt ||
25832584
ExtOp == Instruction::CastOps::SExt) &&
2584-
"VPExtendedReductionRecipe only support zext and sext.");
2585+
"VPExtendedReductionRecipe only supports zext and sext.");
25852586

25862587
// Not all WidenCastRecipes contain nneg flag. Need to transfer flags from
25872588
// the original recipe to prevent setting wrong flags.
@@ -2614,7 +2615,7 @@ class VPExtendedReductionRecipe : public VPReductionRecipe {
26142615
/// Is the extend ZExt?
26152616
bool isZExt() const { return getExtOpcode() == Instruction::ZExt; }
26162617

2617-
/// The opcode of extend recipe.
2618+
/// Get the opcode of the extend for VecOp.
26182619
Instruction::CastOps getExtOpcode() const { return ExtOp; }
26192620
};
26202621

@@ -2624,12 +2625,13 @@ class VPExtendedReductionRecipe : public VPReductionRecipe {
26242625
/// recipe is abstract and needs to be lowered to concrete recipes before
26252626
/// codegen. The operands are {ChainOp, VecOp1, VecOp2, [Condition]}.
26262627
class VPMulAccumulateReductionRecipe : public VPReductionRecipe {
2627-
/// Opcode of the extend recipe.
2628+
/// Opcode of the extend for VecOp1 and VecOp2.
26282629
Instruction::CastOps ExtOp;
26292630

26302631
/// Non-neg flag of the extend recipe.
26312632
bool IsNonNeg = false;
26322633

2634+
/// The scalar type after extending.
26332635
Type *ResultTy;
26342636

26352637
/// For cloning VPMulAccumulateReductionRecipe.
@@ -2660,7 +2662,7 @@ class VPMulAccumulateReductionRecipe : public VPReductionRecipe {
26602662
"be Add");
26612663
assert((ExtOp == Instruction::CastOps::ZExt ||
26622664
ExtOp == Instruction::CastOps::SExt) &&
2663-
"VPMulAccumulateReductionRecipe only support zext and sext.");
2665+
"VPMulAccumulateReductionRecipe only supports zext and sext.");
26642666
setUnderlyingValue(R->getUnderlyingValue());
26652667
// Only set the non-negative flag if the original recipe contains.
26662668
if (Ext0->hasNonNegFlag())
@@ -2706,24 +2708,26 @@ class VPMulAccumulateReductionRecipe : public VPReductionRecipe {
27062708

27072709
Type *getResultType() const {
27082710
assert(isExtended() && "Only support getResultType when this recipe "
2709-
"contains implicit extend.");
2711+
"is implicitly extend.");
27102712
return ResultTy;
27112713
}
27122714

2713-
/// The VPValue of the vector value to be extended and reduced.
2715+
/// The first vector value to be extended and reduced.
27142716
VPValue *getVecOp0() const { return getOperand(1); }
2717+
2718+
/// The second vector value to be extended and reduced.
27152719
VPValue *getVecOp1() const { return getOperand(2); }
27162720

2717-
/// Return if this MulAcc recipe contains extended operands.
2721+
/// Return true if this recipe contains extended operands.
27182722
bool isExtended() const { return ExtOp != Instruction::CastOps::CastOpsEnd; }
27192723

27202724
/// Return the opcode of the extends for the operands.
27212725
Instruction::CastOps getExtOpcode() const { return ExtOp; }
27222726

2723-
/// Return if the operands are zero extended.
2727+
/// Return if the operands are zero-extended.
27242728
bool isZExt() const { return ExtOp == Instruction::CastOps::ZExt; }
27252729

2726-
/// Return the non negative flag of the ext recipe.
2730+
/// Return true if the operand extends have the non-negative flag.
27272731
bool isNonNeg() const { return IsNonNeg; }
27282732
};
27292733

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -2563,7 +2563,8 @@ void VPExtendedReductionRecipe::print(raw_ostream &O, const Twine &Indent,
25632563
RecurrenceDescriptor::getOpcode(getRecurrenceKind()))
25642564
<< " (";
25652565
getVecOp()->printAsOperand(O, SlotTracker);
2566-
O << " extended to " << *getResultType();
2566+
printFlags(O);
2567+
O << Instruction::getOpcodeName(ExtOp) << " to " << *getResultType();
25672568
if (isConditional()) {
25682569
O << ", ";
25692570
getCondOp()->printAsOperand(O, SlotTracker);
@@ -2588,12 +2589,14 @@ void VPMulAccumulateReductionRecipe::print(raw_ostream &O, const Twine &Indent,
25882589
O << "(";
25892590
getVecOp0()->printAsOperand(O, SlotTracker);
25902591
if (isExtended())
2591-
O << " extended to " << *getResultType() << "), (";
2592+
O << " " << Instruction::getOpcodeName(ExtOp) << " to " << *getResultType()
2593+
<< "), (";
25922594
else
25932595
O << ", ";
25942596
getVecOp1()->printAsOperand(O, SlotTracker);
25952597
if (isExtended())
2596-
O << " extended to " << *getResultType() << ")";
2598+
O << " " << Instruction::getOpcodeName(ExtOp) << " to " << *getResultType()
2599+
<< ")";
25972600
if (isConditional()) {
25982601
O << ", ";
25992602
getCondOp()->printAsOperand(O, SlotTracker);

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

+11-12
Original file line numberDiff line numberDiff line change
@@ -2446,7 +2446,7 @@ static void expandVPExtendedReduction(VPExtendedReductionRecipe *ExtRed) {
24462446
static void
24472447
expandVPMulAccumulateReduction(VPMulAccumulateReductionRecipe *MulAcc) {
24482448
// Generate inner VPWidenCastRecipes if necessary.
2449-
// Note that we will drop the extend after mul which transform
2449+
// Note that we will drop the extend after mul which transforms
24502450
// reduce.add(ext(mul(ext, ext))) to reduce.add(mul(ext, ext)).
24512451
VPValue *Op0, *Op1;
24522452
if (MulAcc->isExtended()) {
@@ -2481,9 +2481,8 @@ expandVPMulAccumulateReduction(VPMulAccumulateReductionRecipe *MulAcc) {
24812481

24822482
std::array<VPValue *, 2> MulOps = {Op0, Op1};
24832483
auto *Mul = new VPWidenRecipe(
2484-
Instruction::Mul, make_range(MulOps.begin(), MulOps.end()),
2485-
MulAcc->hasNoUnsignedWrap(), MulAcc->hasNoSignedWrap(),
2486-
MulAcc->getDebugLoc());
2484+
Instruction::Mul, ArrayRef(MulOps), MulAcc->hasNoUnsignedWrap(),
2485+
MulAcc->hasNoSignedWrap(), MulAcc->getDebugLoc());
24872486
Mul->insertBefore(MulAcc);
24882487

24892488
auto *Red = new VPReductionRecipe(
@@ -2722,6 +2721,10 @@ tryToMatchAndCreateMulAccumulateReduction(VPReductionRecipe *Red,
27222721
VPCostContext &Ctx, VFRange &Range) {
27232722
using namespace VPlanPatternMatch;
27242723

2724+
unsigned Opcode = RecurrenceDescriptor::getOpcode(Red->getRecurrenceKind());
2725+
if (Opcode != Instruction::Add)
2726+
return nullptr;
2727+
27252728
Type *RedTy = Ctx.Types.inferScalarType(Red);
27262729

27272730
// Clamp the range if using multiply-accumulate-reduction is profitable.
@@ -2752,21 +2755,17 @@ tryToMatchAndCreateMulAccumulateReduction(VPReductionRecipe *Red,
27522755
Range);
27532756
};
27542757

2755-
unsigned Opcode = RecurrenceDescriptor::getOpcode(Red->getRecurrenceKind());
2756-
if (Opcode != Instruction::Add)
2757-
return nullptr;
2758-
27592758
VPValue *VecOp = Red->getVecOp();
27602759
VPValue *A, *B;
2761-
// Try to match reduce.add(mul(...))
2760+
// Try to match reduce.add(mul(...)).
27622761
if (match(VecOp, m_Mul(m_VPValue(A), m_VPValue(B)))) {
27632762
auto *RecipeA =
27642763
dyn_cast_if_present<VPWidenCastRecipe>(A->getDefiningRecipe());
27652764
auto *RecipeB =
27662765
dyn_cast_if_present<VPWidenCastRecipe>(B->getDefiningRecipe());
27672766
auto *Mul = cast<VPWidenRecipe>(VecOp->getDefiningRecipe());
27682767

2769-
// Match reduce.add(mul(ext, ext))
2768+
// Match reduce.add(mul(ext, ext)).
27702769
if (RecipeA && RecipeB &&
27712770
(RecipeA->getOpcode() == RecipeB->getOpcode() || A == B) &&
27722771
match(RecipeA, m_ZExtOrSExt(m_VPValue())) &&
@@ -2776,11 +2775,11 @@ tryToMatchAndCreateMulAccumulateReduction(VPReductionRecipe *Red,
27762775
Mul, RecipeA, RecipeB, nullptr))
27772776
return new VPMulAccumulateReductionRecipe(Red, Mul, RecipeA, RecipeB,
27782777
RecipeA->getResultType());
2779-
// Match reduce.add(mul)
2778+
// Match reduce.add(mul).
27802779
if (IsMulAccValidAndClampRange(true, Mul, nullptr, nullptr, nullptr))
27812780
return new VPMulAccumulateReductionRecipe(Red, Mul);
27822781
}
2783-
// Match reduce.add(ext(mul(ext(A), ext(B))))
2782+
// Match reduce.add(ext(mul(ext(A), ext(B)))).
27842783
// All extend recipes must have same opcode or A == B
27852784
// which can be transform to reduce.add(zext(mul(sext(A), sext(B)))).
27862785
if (match(VecOp, m_ZExtOrSExt(m_Mul(m_ZExtOrSExt(m_VPValue()),

llvm/test/Transforms/LoopVectorize/vplan-printing-reductions.ll

+2-2
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ define i64 @print_extended_reduction(ptr nocapture readonly %x, ptr nocapture re
288288
; CHECK-NEXT: CLONE ir<%arrayidx> = getelementptr inbounds ir<%x>, vp<[[STEPS]]>
289289
; CHECK-NEXT: vp<[[ADDR:%.+]]> = vector-pointer ir<%arrayidx>
290290
; CHECK-NEXT: WIDEN ir<[[LOAD:%.+]]> = load vp<[[ADDR]]>
291-
; CHECK-NEXT: EXTENDED-REDUCE ir<[[RDX_NEXT:%.+]]> = ir<[[RDX]]> + reduce.add (ir<[[LOAD]]> extended to i64)
291+
; CHECK-NEXT: EXTENDED-REDUCE ir<[[RDX_NEXT:%.+]]> = ir<[[RDX]]> + reduce.add (ir<[[LOAD]]> zext to i64)
292292
; CHECK-NEXT: EMIT vp<[[IV_NEXT]]> = add nuw vp<[[IV]]>, vp<[[VFxUF]]>
293293
; CHECK-NEXT: EMIT branch-on-count vp<[[IV_NEXT]]>, vp<[[VTC]]>
294294
; CHECK-NEXT: No successors
@@ -384,7 +384,7 @@ define i64 @print_mulacc_extended(ptr nocapture readonly %x, ptr nocapture reado
384384
; CHECK-NEXT: CLONE ir<[[ARRAYIDX1:%.+]]> = getelementptr inbounds ir<%y>, vp<[[STEPS]]>
385385
; CHECK-NEXT: vp<[[ADDR1:%.+]]> = vector-pointer ir<[[ARRAYIDX1]]>
386386
; CHECK-NEXT: WIDEN ir<[[LOAD1:%.+]]> = load vp<[[ADDR1]]>
387-
; CHECK-NEXT: MULACC-REDUCE ir<[[RDX_NEXT:%.+]]> = ir<[[RDX]]> + reduce.add (mul nsw (ir<[[LOAD0]]> extended to i64), (ir<[[LOAD1]]> extended to i64))
387+
; CHECK-NEXT: MULACC-REDUCE ir<[[RDX_NEXT:%.+]]> = ir<[[RDX]]> + reduce.add (mul nsw (ir<[[LOAD0]]> sext to i64), (ir<[[LOAD1]]> sext to i64))
388388
; CHECK-NEXT: EMIT vp<[[IV_NEXT]]> = add nuw vp<[[IV]]>, vp<[[VFxUF]]>
389389
; CHECK-NEXT: EMIT branch-on-count vp<[[IV_NEXT]]>, vp<[[VTC]]>
390390
; CHECK-NEXT: No successors

0 commit comments

Comments
 (0)