Skip to content

Commit 0b2f253

Browse files
committed
[LV] Separate AnyOf recurrence from getRecurrenceIdentity [NFC]
These recurrence types don't have a meaningful identity, and the routine was abused to return the start value instead. Out of the three callers to this routine, only one actually wants this behavior. This is a prep change for removing the routine entirely and commoning it with other copies of the same logic.
1 parent 9626e84 commit 0b2f253

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

llvm/include/llvm/Analysis/IVDescriptors.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class RecurrenceDescriptor {
156156
static InstDesc isConditionalRdxPattern(RecurKind Kind, Instruction *I);
157157

158158
/// Returns identity corresponding to the RecurrenceKind.
159-
Value *getRecurrenceIdentity(RecurKind K, Type *Tp, FastMathFlags FMF) const;
159+
static Value *getRecurrenceIdentity(RecurKind K, Type *Tp, FastMathFlags FMF);
160160

161161
/// Returns the opcode corresponding to the RecurrenceKind.
162162
static unsigned getOpcode(RecurKind Kind);

llvm/lib/Analysis/IVDescriptors.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ bool RecurrenceDescriptor::isFixedOrderRecurrence(PHINode *Phi, Loop *TheLoop,
10351035
/// This function returns the identity element (or neutral element) for
10361036
/// the operation K.
10371037
Value *RecurrenceDescriptor::getRecurrenceIdentity(RecurKind K, Type *Tp,
1038-
FastMathFlags FMF) const {
1038+
FastMathFlags FMF) {
10391039
switch (K) {
10401040
case RecurKind::Xor:
10411041
case RecurKind::Add:
@@ -1071,8 +1071,7 @@ Value *RecurrenceDescriptor::getRecurrenceIdentity(RecurKind K, Type *Tp,
10711071
return ConstantFP::getInfinity(Tp, true /*Negative*/);
10721072
case RecurKind::IAnyOf:
10731073
case RecurKind::FAnyOf:
1074-
return getRecurrenceStartValue();
1075-
break;
1074+
llvm_unreachable("No meaningful identity for recurrence kind");
10761075
default:
10771076
llvm_unreachable("Unknown recurrence kind");
10781077
}

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,13 +1829,18 @@ void VPReductionRecipe::execute(VPTransformState &State) {
18291829
Value *NewCond = State.get(Cond, Part, State.VF.isScalar());
18301830
VectorType *VecTy = dyn_cast<VectorType>(NewVecOp->getType());
18311831
Type *ElementTy = VecTy ? VecTy->getElementType() : NewVecOp->getType();
1832-
Value *Iden = RdxDesc.getRecurrenceIdentity(Kind, ElementTy,
1833-
RdxDesc.getFastMathFlags());
1834-
if (State.VF.isVector()) {
1835-
Iden = State.Builder.CreateVectorSplat(VecTy->getElementCount(), Iden);
1836-
}
18371832

1838-
Value *Select = State.Builder.CreateSelect(NewCond, NewVecOp, Iden);
1833+
Value *Start;
1834+
if (RecurrenceDescriptor::isAnyOfRecurrenceKind(Kind))
1835+
Start = RdxDesc.getRecurrenceStartValue();
1836+
else
1837+
Start = RdxDesc.getRecurrenceIdentity(Kind, ElementTy,
1838+
RdxDesc.getFastMathFlags());
1839+
if (State.VF.isVector())
1840+
Start = State.Builder.CreateVectorSplat(VecTy->getElementCount(),
1841+
Start);
1842+
1843+
Value *Select = State.Builder.CreateSelect(NewCond, NewVecOp, Start);
18391844
NewVecOp = Select;
18401845
}
18411846
Value *NewRed;

0 commit comments

Comments
 (0)