Skip to content

Commit a87ebd6

Browse files
committed
!fixup address latest comments, thanks!
1 parent 3d8d79a commit a87ebd6

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

llvm/lib/Analysis/IVDescriptors.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -715,11 +715,8 @@ RecurrenceDescriptor::isFindIVPattern(RecurKind Kind, Loop *TheLoop,
715715
return std::nullopt;
716716

717717
const SCEV *Step = AR->getStepRecurrence(SE);
718-
719-
if (isFindFirstIVRecurrenceKind(Kind)) {
720-
if (!SE.isKnownNegative(Step))
721-
return std::nullopt;
722-
} else if (!SE.isKnownPositive(Step))
718+
if ((isFindFirstIVRecurrenceKind(Kind) && !SE.isKnownNegative(Step)) ||
719+
(isFindLastIVRecurrenceKind(Kind) && !SE.isKnownPositive(Step)))
723720
return std::nullopt;
724721

725722
// Keep the minimum value of the recurrence type as the sentinel value.
@@ -744,8 +741,6 @@ RecurrenceDescriptor::isFindIVPattern(RecurKind Kind, Loop *TheLoop,
744741
: APInt::getMinValue(NumBits);
745742
ValidRange = ConstantRange::getNonEmpty(Sentinel + 1, Sentinel);
746743
} else {
747-
assert(isFindFirstIVRecurrenceKind(Kind) &&
748-
"Kind must either be FindLastIV or FindFirstIV");
749744
assert(IsSigned && "Only FindFirstIV with SMax is supported currently");
750745
ValidRange =
751746
ConstantRange::getNonEmpty(APInt::getSignedMinValue(NumBits),

llvm/lib/Transforms/Utils/LoopUtils.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,12 +1227,11 @@ Value *llvm::createFindLastIVReduction(IRBuilderBase &Builder, Value *Src,
12271227
RecurKind RdxKind, Value *Start,
12281228
Value *Sentinel) {
12291229
bool IsSigned = RecurrenceDescriptor::isSignedRecurrenceKind(RdxKind);
1230-
Value *MaxRdx =
1231-
Src->getType()->isVectorTy()
1232-
? (RecurrenceDescriptor::isFindLastIVRecurrenceKind(RdxKind)
1233-
? Builder.CreateIntMaxReduce(Src, IsSigned)
1234-
: Builder.CreateIntMinReduce(Src, IsSigned))
1235-
: Src;
1230+
bool IsMaxRdx = RecurrenceDescriptor::isFindLastIVRecurrenceKind(RdxKind);
1231+
Value *MaxRdx = Src->getType()->isVectorTy()
1232+
? (IsMaxRdx ? Builder.CreateIntMaxReduce(Src, IsSigned)
1233+
: Builder.CreateIntMinReduce(Src, IsSigned))
1234+
: Src;
12361235
// Correct the final reduction result back to the start value if the maximum
12371236
// reduction is sentinel value.
12381237
Value *Cmp =
@@ -1328,7 +1327,7 @@ Value *llvm::createSimpleReduction(IRBuilderBase &Builder, Value *Src,
13281327
RecurKind Kind, Value *Mask, Value *EVL) {
13291328
assert(!RecurrenceDescriptor::isAnyOfRecurrenceKind(Kind) &&
13301329
!RecurrenceDescriptor::isFindIVRecurrenceKind(Kind) &&
1331-
"AnyOf, FindFirstIV and FindLastIV reductions are not supported.");
1330+
"AnyOf and FindIV reductions are not supported.");
13321331
Intrinsic::ID Id = getReductionIntrinsicID(Kind);
13331332
auto VPID = VPIntrinsic::getForIntrinsic(Id);
13341333
assert(VPReductionIntrinsic::isVPReduction(VPID) &&

0 commit comments

Comments
 (0)