Skip to content

Commit b70d6e3

Browse files
committed
IVDescriptors: strip FAnyOf altogether
1 parent feaf59e commit b70d6e3

File tree

6 files changed

+25
-32
lines changed

6 files changed

+25
-32
lines changed

llvm/include/llvm/Analysis/IVDescriptors.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,8 @@ enum class RecurKind {
4848
FMinimum, ///< FP min with llvm.minimum semantics
4949
FMaximum, ///< FP max with llvm.maximum semantics
5050
FMulAdd, ///< Sum of float products with llvm.fmuladd(a * b + sum).
51-
IAnyOf, ///< Any_of reduction with select(icmp(),x,y) where one of (x,y) is
52-
///< loop invariant, and both x and y are integer type.
53-
FAnyOf ///< Any_of reduction with select(fcmp(),x,y) where one of (x,y) is
54-
///< loop invariant, and both x and y are integer type.
51+
AnyOf, ///< Any_of reduction with select(cmp(),x,y) where one of (x,y) is
52+
///< loop invariant.
5553
// TODO: Any_of reduction need not be restricted to integer type only.
5654
};
5755

@@ -156,7 +154,7 @@ class RecurrenceDescriptor {
156154
static InstDesc isConditionalRdxPattern(RecurKind Kind, Instruction *I);
157155

158156
/// Returns the opcode corresponding to the RecurrenceKind.
159-
static unsigned getOpcode(RecurKind Kind);
157+
static unsigned getOpcode(RecurKind Kind, Type *Ty);
160158

161159
/// Returns true if Phi is a reduction of type Kind and adds it to the
162160
/// RecurrenceDescriptor. If either \p DB is non-null or \p AC and \p DT are
@@ -192,7 +190,9 @@ class RecurrenceDescriptor {
192190

193191
RecurKind getRecurrenceKind() const { return Kind; }
194192

195-
unsigned getOpcode() const { return getOpcode(getRecurrenceKind()); }
193+
unsigned getOpcode() const {
194+
return getOpcode(getRecurrenceKind(), getRecurrenceType());
195+
}
196196

197197
FastMathFlags getFastMathFlags() const { return FMF; }
198198

@@ -233,7 +233,7 @@ class RecurrenceDescriptor {
233233
/// Returns true if the recurrence kind is of the form
234234
/// select(cmp(),x,y) where one of (x,y) is loop invariant.
235235
static bool isAnyOfRecurrenceKind(RecurKind Kind) {
236-
return Kind == RecurKind::IAnyOf || Kind == RecurKind::FAnyOf;
236+
return Kind == RecurKind::AnyOf;
237237
}
238238

239239
/// Returns the type of the recurrence. This type can be narrower than the

llvm/lib/Analysis/IVDescriptors.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ bool RecurrenceDescriptor::isIntegerRecurrenceKind(RecurKind Kind) {
4949
case RecurKind::SMin:
5050
case RecurKind::UMax:
5151
case RecurKind::UMin:
52-
case RecurKind::IAnyOf:
53-
case RecurKind::FAnyOf:
52+
case RecurKind::AnyOf:
5453
return true;
5554
}
5655
return false;
@@ -651,8 +650,7 @@ RecurrenceDescriptor::isAnyOfPattern(Loop *Loop, PHINode *OrigPhi,
651650
if (!Loop->isLoopInvariant(NonPhi))
652651
return InstDesc(false, I);
653652

654-
return InstDesc(I, isa<ICmpInst>(I->getOperand(0)) ? RecurKind::IAnyOf
655-
: RecurKind::FAnyOf);
653+
return InstDesc(I, RecurKind::AnyOf);
656654
}
657655

658656
RecurrenceDescriptor::InstDesc
@@ -884,7 +882,7 @@ bool RecurrenceDescriptor::isReductionPHI(PHINode *Phi, Loop *TheLoop,
884882
LLVM_DEBUG(dbgs() << "Found a UMIN reduction PHI." << *Phi << "\n");
885883
return true;
886884
}
887-
if (AddReductionVar(Phi, RecurKind::IAnyOf, TheLoop, FMF, RedDes, DB, AC, DT,
885+
if (AddReductionVar(Phi, RecurKind::AnyOf, TheLoop, FMF, RedDes, DB, AC, DT,
888886
SE)) {
889887
LLVM_DEBUG(dbgs() << "Found an conditional select reduction PHI." << *Phi
890888
<< "\n");
@@ -1017,7 +1015,7 @@ bool RecurrenceDescriptor::isFixedOrderRecurrence(PHINode *Phi, Loop *TheLoop,
10171015
return true;
10181016
}
10191017

1020-
unsigned RecurrenceDescriptor::getOpcode(RecurKind Kind) {
1018+
unsigned RecurrenceDescriptor::getOpcode(RecurKind Kind, Type *Ty) {
10211019
switch (Kind) {
10221020
case RecurKind::Add:
10231021
return Instruction::Add;
@@ -1038,14 +1036,14 @@ unsigned RecurrenceDescriptor::getOpcode(RecurKind Kind) {
10381036
case RecurKind::SMin:
10391037
case RecurKind::UMax:
10401038
case RecurKind::UMin:
1041-
case RecurKind::IAnyOf:
10421039
return Instruction::ICmp;
10431040
case RecurKind::FMax:
10441041
case RecurKind::FMin:
10451042
case RecurKind::FMaximum:
10461043
case RecurKind::FMinimum:
1047-
case RecurKind::FAnyOf:
10481044
return Instruction::FCmp;
1045+
case RecurKind::AnyOf:
1046+
return Ty->isIntegerTy() ? Instruction::ICmp : Instruction::FCmp;
10491047
default:
10501048
llvm_unreachable("Unknown recurrence operation");
10511049
}
@@ -1054,7 +1052,7 @@ unsigned RecurrenceDescriptor::getOpcode(RecurKind Kind) {
10541052
SmallVector<Instruction *, 4>
10551053
RecurrenceDescriptor::getReductionOpChain(PHINode *Phi, Loop *L) const {
10561054
SmallVector<Instruction *, 4> ReductionOperations;
1057-
unsigned RedOp = getOpcode(Kind);
1055+
unsigned RedOp = getOpcode();
10581056

10591057
// Search down from the Phi to the LoopExitInstr, looking for instructions
10601058
// with a single user of the correct type for the reduction.

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4180,8 +4180,7 @@ bool AArch64TTIImpl::isLegalToVectorizeReduction(
41804180
case RecurKind::FMin:
41814181
case RecurKind::FMax:
41824182
case RecurKind::FMulAdd:
4183-
case RecurKind::IAnyOf:
4184-
case RecurKind::FAnyOf:
4183+
case RecurKind::AnyOf:
41854184
return true;
41864185
default:
41874186
return false;

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,7 @@ class RISCVTTIImpl : public BasicTTIImplBase<RISCVTTIImpl> {
348348
case RecurKind::FMin:
349349
case RecurKind::FMax:
350350
case RecurKind::FMulAdd:
351-
case RecurKind::IAnyOf:
352-
case RecurKind::FAnyOf:
351+
case RecurKind::AnyOf:
353352
return true;
354353
default:
355354
return false;

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19241,7 +19241,7 @@ class HorizontalReduction {
1924119241
/// Creates reduction operation with the current opcode.
1924219242
static Value *createOp(IRBuilderBase &Builder, RecurKind Kind, Value *LHS,
1924319243
Value *RHS, const Twine &Name, bool UseSelect) {
19244-
unsigned RdxOpcode = RecurrenceDescriptor::getOpcode(Kind);
19244+
unsigned RdxOpcode = RecurrenceDescriptor::getOpcode(Kind, LHS->getType());
1924519245
switch (Kind) {
1924619246
case RecurKind::Or:
1924719247
if (UseSelect &&
@@ -20384,7 +20384,7 @@ class HorizontalReduction {
2038420384
case RecurKind::Xor:
2038520385
case RecurKind::FAdd:
2038620386
case RecurKind::FMul: {
20387-
unsigned RdxOpcode = RecurrenceDescriptor::getOpcode(RdxKind);
20387+
unsigned RdxOpcode = RecurrenceDescriptor::getOpcode(RdxKind, ScalarTy);
2038820388
if (!AllConsts) {
2038920389
if (auto *VecTy = dyn_cast<FixedVectorType>(ScalarTy)) {
2039020390
assert(SLPReVec && "FixedVectorType is not expected.");
@@ -20513,8 +20513,7 @@ class HorizontalReduction {
2051320513
case RecurKind::Mul:
2051420514
case RecurKind::FMul:
2051520515
case RecurKind::FMulAdd:
20516-
case RecurKind::IAnyOf:
20517-
case RecurKind::FAnyOf:
20516+
case RecurKind::AnyOf:
2051820517
case RecurKind::None:
2051920518
llvm_unreachable("Unexpected reduction kind for repeated scalar.");
2052020519
}
@@ -20610,8 +20609,7 @@ class HorizontalReduction {
2061020609
case RecurKind::Mul:
2061120610
case RecurKind::FMul:
2061220611
case RecurKind::FMulAdd:
20613-
case RecurKind::IAnyOf:
20614-
case RecurKind::FAnyOf:
20612+
case RecurKind::AnyOf:
2061520613
case RecurKind::None:
2061620614
llvm_unreachable("Unexpected reduction kind for reused scalars.");
2061720615
}

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ Value *VPInstruction::generate(VPTransformState &State) {
550550
}
551551
// Reduce all of the unrolled parts into a single vector.
552552
Value *ReducedPartRdx = RdxParts[0];
553-
unsigned Op = RecurrenceDescriptor::getOpcode(RK);
553+
unsigned Op = RdxDesc.getOpcode();
554554
if (RecurrenceDescriptor::isAnyOfRecurrenceKind(RK))
555555
Op = Instruction::Or;
556556

@@ -2130,8 +2130,7 @@ void VPReductionRecipe::execute(VPTransformState &State) {
21302130
createOrderedReduction(State.Builder, RdxDesc, NewVecOp, PrevInChain);
21312131
else
21322132
NewRed = State.Builder.CreateBinOp(
2133-
(Instruction::BinaryOps)RdxDesc.getOpcode(Kind), PrevInChain,
2134-
NewVecOp);
2133+
(Instruction::BinaryOps)RdxDesc.getOpcode(), PrevInChain, NewVecOp);
21352134
PrevInChain = NewRed;
21362135
NextInChain = NewRed;
21372136
} else {
@@ -2142,7 +2141,7 @@ void VPReductionRecipe::execute(VPTransformState &State) {
21422141
NewRed, PrevInChain);
21432142
else
21442143
NextInChain = State.Builder.CreateBinOp(
2145-
(Instruction::BinaryOps)RdxDesc.getOpcode(Kind), NewRed, PrevInChain);
2144+
(Instruction::BinaryOps)RdxDesc.getOpcode(), NewRed, PrevInChain);
21462145
}
21472146
State.set(this, NextInChain, /*IsScalar*/ true);
21482147
}
@@ -2179,8 +2178,8 @@ void VPReductionEVLRecipe::execute(VPTransformState &State) {
21792178
if (RecurrenceDescriptor::isMinMaxRecurrenceKind(Kind))
21802179
NewRed = createMinMaxOp(Builder, Kind, NewRed, Prev);
21812180
else
2182-
NewRed = Builder.CreateBinOp(
2183-
(Instruction::BinaryOps)RdxDesc.getOpcode(Kind), NewRed, Prev);
2181+
NewRed = Builder.CreateBinOp((Instruction::BinaryOps)RdxDesc.getOpcode(),
2182+
NewRed, Prev);
21842183
}
21852184
State.set(this, NewRed, /*IsScalar*/ true);
21862185
}

0 commit comments

Comments
 (0)