Skip to content

Commit 3277f6c

Browse files
authored
[LV] Explicitly disable in-loop reductions for AnyOf and FindIV. nfc (#163541)
Currently, in-loop reductions for AnyOf and FindIV are not supported. They were implicitly blocked. This happened because RecurrenceDescriptor::getReductionOpChain could not detect their recurrence chain. The reason is that RecurrenceDescriptor::getOpcode was set to Instruction::Or, but the recurrence chains of AnyOf and FindIV do not actually contain an Instruction::Or. This patch explicitly disables in-loop reductions for AnyOf and FindIV instead of relying on getReductionOpChain to implicitly prevent them.
1 parent bf07226 commit 3277f6c

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

llvm/lib/Analysis/IVDescriptors.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,11 +1220,6 @@ unsigned RecurrenceDescriptor::getOpcode(RecurKind Kind) {
12201220
return Instruction::Add;
12211221
case RecurKind::Mul:
12221222
return Instruction::Mul;
1223-
case RecurKind::AnyOf:
1224-
case RecurKind::FindFirstIVSMin:
1225-
case RecurKind::FindFirstIVUMin:
1226-
case RecurKind::FindLastIVSMax:
1227-
case RecurKind::FindLastIVUMax:
12281223
case RecurKind::Or:
12291224
return Instruction::Or;
12301225
case RecurKind::And:
@@ -1248,6 +1243,13 @@ unsigned RecurrenceDescriptor::getOpcode(RecurKind Kind) {
12481243
case RecurKind::FMaximumNum:
12491244
case RecurKind::FMinimumNum:
12501245
return Instruction::FCmp;
1246+
case RecurKind::AnyOf:
1247+
case RecurKind::FindFirstIVSMin:
1248+
case RecurKind::FindFirstIVUMin:
1249+
case RecurKind::FindLastIVSMax:
1250+
case RecurKind::FindLastIVUMax:
1251+
// TODO: Set AnyOf and FindIV to Instruction::Select once in-loop reductions
1252+
// are supported.
12511253
default:
12521254
llvm_unreachable("Unknown recurrence operation");
12531255
}

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6591,9 +6591,14 @@ void LoopVectorizationCostModel::collectInLoopReductions() {
65916591
if (RdxDesc.getRecurrenceType() != Phi->getType())
65926592
continue;
65936593

6594+
// In-loop AnyOf and FindIV reductions are not yet supported.
6595+
RecurKind Kind = RdxDesc.getRecurrenceKind();
6596+
if (RecurrenceDescriptor::isAnyOfRecurrenceKind(Kind) ||
6597+
RecurrenceDescriptor::isFindIVRecurrenceKind(Kind))
6598+
continue;
6599+
65946600
// If the target would prefer this reduction to happen "in-loop", then we
65956601
// want to record it as such.
6596-
RecurKind Kind = RdxDesc.getRecurrenceKind();
65976602
if (!PreferInLoopReductions && !useOrderedReductions(RdxDesc) &&
65986603
!TTI.preferInLoopReduction(Kind, Phi->getType()))
65996604
continue;

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -821,10 +821,9 @@ Value *VPInstruction::generate(VPTransformState &State) {
821821
auto *OrigPhi = cast<PHINode>(PhiR->getUnderlyingValue());
822822
Value *ReducedPartRdx = State.get(getOperand(2));
823823
for (unsigned Idx = 3; Idx < getNumOperands(); ++Idx)
824-
ReducedPartRdx = Builder.CreateBinOp(
825-
(Instruction::BinaryOps)RecurrenceDescriptor::getOpcode(
826-
RecurKind::AnyOf),
827-
State.get(getOperand(Idx)), ReducedPartRdx, "bin.rdx");
824+
ReducedPartRdx =
825+
Builder.CreateBinOp(Instruction::Or, State.get(getOperand(Idx)),
826+
ReducedPartRdx, "bin.rdx");
828827
return createAnyOfReduction(Builder, ReducedPartRdx,
829828
State.get(getOperand(1), VPLane(0)), OrigPhi);
830829
}

0 commit comments

Comments
 (0)