Skip to content

Commit 3c6664e

Browse files
committed
!fixup dont transform reductions with intermediate stores.
1 parent 4fedac4 commit 3c6664e

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

llvm/include/llvm/Analysis/TargetTransformInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,8 @@ class TargetTransformInfo {
638638
/// Fall back to the generic logic to determine whether multi-exit unrolling
639639
/// is profitable if set to false.
640640
bool RuntimeUnrollMultiExit;
641+
642+
DenseMap<PHINode *, RecurrenceDescriptor> ParallelizeReductions;
641643
};
642644

643645
/// Get target-customized preferences for the generic loop unrolling

llvm/lib/Transforms/Utils/LoopUnroll.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,12 +1210,12 @@ MDNode *llvm::GetUnrollMetadata(MDNode *LoopID, StringRef Name) {
12101210
std::optional<RecurrenceDescriptor>
12111211
llvm::canParallelizeReductionWhenUnrolling(PHINode &Phi, Loop *L,
12121212
ScalarEvolution *SE) {
1213-
RecurrenceDescriptor RedDes;
1214-
if (!RecurrenceDescriptor::isReductionPHI(&Phi, L, RedDes,
1213+
RecurrenceDescriptor RdxDesc;
1214+
if (!RecurrenceDescriptor::isReductionPHI(&Phi, L, RdxDesc,
12151215
/*DemandedBits=*/nullptr,
12161216
/*AC=*/nullptr, /*DT=*/nullptr, SE))
12171217
return std::nullopt;
1218-
RecurKind RK = RedDes.getRecurrenceKind();
1218+
RecurKind RK = RdxDesc.getRecurrenceKind();
12191219
// Skip unsupported reductions.
12201220
// TODO: Handle additional reductions, including FP and min-max
12211221
// reductions.
@@ -1225,6 +1225,9 @@ llvm::canParallelizeReductionWhenUnrolling(PHINode &Phi, Loop *L,
12251225
RecurrenceDescriptor::isMinMaxRecurrenceKind(RK))
12261226
return std::nullopt;
12271227

1228+
if (RdxDesc.IntermediateStore)
1229+
return std::nullopt;
1230+
12281231
// Don't unroll reductions with constant ops; those can be folded to a
12291232
// single induction update.
12301233
if (any_of(cast<Instruction>(Phi.getIncomingValueForBlock(L->getLoopLatch()))
@@ -1239,5 +1242,5 @@ llvm::canParallelizeReductionWhenUnrolling(PHINode &Phi, Loop *L,
12391242
&Phi))
12401243
return std::nullopt;
12411244

1242-
return RedDes;
1245+
return RdxDesc;
12431246
}

0 commit comments

Comments
 (0)