Skip to content

Commit 118d349

Browse files
lukel97pawosm-arm
authored andcommitted
[LV] Split RecurrenceDescriptor into RecurKind + FastMathFlags in LoopUtils. NFC (llvm#132014)
Split off from llvm#131300, this splits up RecurrenceDescriptor arguments so that arbitrary recurrence kinds may be used down the line.
1 parent 7e73b7a commit 118d349

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
lines changed

llvm/include/llvm/Transforms/Utils/LoopUtils.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,8 @@ Value *createSimpleReduction(IRBuilderBase &B, Value *Src,
409409
RecurKind RdxKind);
410410
/// Overloaded function to generate vector-predication intrinsics for
411411
/// reduction.
412-
Value *createSimpleReduction(VectorBuilder &VB, Value *Src,
413-
const RecurrenceDescriptor &Desc);
412+
Value *createSimpleReduction(VectorBuilder &VB, Value *Src, RecurKind RdxKind,
413+
FastMathFlags FMFs);
414414

415415
/// Create a reduction of the given vector \p Src for a reduction of the
416416
/// kind RecurKind::IAnyOf or RecurKind::FAnyOf. The reduction operation is
@@ -426,14 +426,12 @@ Value *createFindLastIVReduction(IRBuilderBase &B, Value *Src,
426426
const RecurrenceDescriptor &Desc);
427427

428428
/// Create an ordered reduction intrinsic using the given recurrence
429-
/// descriptor \p Desc.
430-
Value *createOrderedReduction(IRBuilderBase &B,
431-
const RecurrenceDescriptor &Desc, Value *Src,
429+
/// kind \p RdxKind.
430+
Value *createOrderedReduction(IRBuilderBase &B, RecurKind RdxKind, Value *Src,
432431
Value *Start);
433432
/// Overloaded function to generate vector-predication intrinsics for ordered
434433
/// reduction.
435-
Value *createOrderedReduction(VectorBuilder &VB,
436-
const RecurrenceDescriptor &Desc, Value *Src,
434+
Value *createOrderedReduction(VectorBuilder &VB, RecurKind RdxKind, Value *Src,
437435
Value *Start);
438436

439437
/// Get the intersection (logical and) of all of the potential IR flags

llvm/lib/Transforms/Utils/LoopUtils.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,36 +1308,31 @@ Value *llvm::createSimpleReduction(IRBuilderBase &Builder, Value *Src,
13081308
}
13091309

13101310
Value *llvm::createSimpleReduction(VectorBuilder &VBuilder, Value *Src,
1311-
const RecurrenceDescriptor &Desc) {
1312-
RecurKind Kind = Desc.getRecurrenceKind();
1311+
RecurKind Kind, FastMathFlags FMFs) {
13131312
assert(!RecurrenceDescriptor::isAnyOfRecurrenceKind(Kind) &&
13141313
!RecurrenceDescriptor::isFindLastIVRecurrenceKind(Kind) &&
13151314
"AnyOf or FindLastIV reductions are not supported.");
13161315
Intrinsic::ID Id = getReductionIntrinsicID(Kind);
13171316
auto *SrcTy = cast<VectorType>(Src->getType());
13181317
Type *SrcEltTy = SrcTy->getElementType();
1319-
Value *Iden = getRecurrenceIdentity(Kind, SrcEltTy, Desc.getFastMathFlags());
1318+
Value *Iden = getRecurrenceIdentity(Kind, SrcEltTy, FMFs);
13201319
Value *Ops[] = {Iden, Src};
13211320
return VBuilder.createSimpleReduction(Id, SrcTy, Ops);
13221321
}
13231322

1324-
Value *llvm::createOrderedReduction(IRBuilderBase &B,
1325-
const RecurrenceDescriptor &Desc,
1323+
Value *llvm::createOrderedReduction(IRBuilderBase &B, RecurKind Kind,
13261324
Value *Src, Value *Start) {
1327-
assert((Desc.getRecurrenceKind() == RecurKind::FAdd ||
1328-
Desc.getRecurrenceKind() == RecurKind::FMulAdd) &&
1325+
assert((Kind == RecurKind::FAdd || Kind == RecurKind::FMulAdd) &&
13291326
"Unexpected reduction kind");
13301327
assert(Src->getType()->isVectorTy() && "Expected a vector type");
13311328
assert(!Start->getType()->isVectorTy() && "Expected a scalar type");
13321329

13331330
return B.CreateFAddReduce(Start, Src);
13341331
}
13351332

1336-
Value *llvm::createOrderedReduction(VectorBuilder &VBuilder,
1337-
const RecurrenceDescriptor &Desc,
1333+
Value *llvm::createOrderedReduction(VectorBuilder &VBuilder, RecurKind Kind,
13381334
Value *Src, Value *Start) {
1339-
assert((Desc.getRecurrenceKind() == RecurKind::FAdd ||
1340-
Desc.getRecurrenceKind() == RecurKind::FMulAdd) &&
1335+
assert((Kind == RecurKind::FAdd || Kind == RecurKind::FMulAdd) &&
13411336
"Unexpected reduction kind");
13421337
assert(Src->getType()->isVectorTy() && "Expected a vector type");
13431338
assert(!Start->getType()->isVectorTy() && "Expected a scalar type");

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,7 +2257,7 @@ void VPReductionRecipe::execute(VPTransformState &State) {
22572257
if (IsOrdered) {
22582258
if (State.VF.isVector())
22592259
NewRed =
2260-
createOrderedReduction(State.Builder, RdxDesc, NewVecOp, PrevInChain);
2260+
createOrderedReduction(State.Builder, Kind, NewVecOp, PrevInChain);
22612261
else
22622262
NewRed = State.Builder.CreateBinOp(
22632263
(Instruction::BinaryOps)RdxDesc.getOpcode(), PrevInChain, NewVecOp);
@@ -2302,9 +2302,9 @@ void VPReductionEVLRecipe::execute(VPTransformState &State) {
23022302

23032303
Value *NewRed;
23042304
if (isOrdered()) {
2305-
NewRed = createOrderedReduction(VBuilder, RdxDesc, VecOp, Prev);
2305+
NewRed = createOrderedReduction(VBuilder, Kind, VecOp, Prev);
23062306
} else {
2307-
NewRed = createSimpleReduction(VBuilder, VecOp, RdxDesc);
2307+
NewRed = createSimpleReduction(VBuilder, VecOp, Kind, getFastMathFlags());
23082308
if (RecurrenceDescriptor::isMinMaxRecurrenceKind(Kind))
23092309
NewRed = createMinMaxOp(Builder, Kind, NewRed, Prev);
23102310
else

0 commit comments

Comments
 (0)