Skip to content

Commit b0ebf38

Browse files
committed
!fixup remove IVDesc changes.
1 parent 60e2caa commit b0ebf38

File tree

2 files changed

+34
-45
lines changed

2 files changed

+34
-45
lines changed

llvm/include/llvm/Analysis/IVDescriptors.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class Loop;
2828
class PredicatedScalarEvolution;
2929
class ScalarEvolution;
3030
class SCEV;
31-
class SCEVAddRecExpr;
3231
class StoreInst;
3332

3433
/// These are the kinds of recurrences that we support.
@@ -311,11 +310,6 @@ class RecurrenceDescriptor {
311310
isFindLastIVRecurrenceKind(Kind);
312311
}
313312

314-
/// Returns true if \p AR's range is valid for either FindFirstIV or
315-
/// FindLastIV reductions i.e. if the sentinel value is outside \p AR's range.
316-
static bool isValidIVRangeForFindIV(const SCEVAddRecExpr *AR, bool IsSigned,
317-
bool IsFindFirstIV, ScalarEvolution &SE);
318-
319313
/// Returns the type of the recurrence. This type can be narrower than the
320314
/// actual type of the Phi if the recurrence has been type-promoted.
321315
Type *getRecurrenceType() const { return RecurrenceType; }

llvm/lib/Analysis/IVDescriptors.cpp

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -715,36 +715,6 @@ RecurrenceDescriptor::isAnyOfPattern(Loop *Loop, PHINode *OrigPhi,
715715
return InstDesc(I, RecurKind::AnyOf);
716716
}
717717

718-
bool RecurrenceDescriptor::isValidIVRangeForFindIV(const SCEVAddRecExpr *AR,
719-
bool IsSigned,
720-
bool IsFindFirstIV,
721-
ScalarEvolution &SE) {
722-
const ConstantRange IVRange =
723-
IsSigned ? SE.getSignedRange(AR) : SE.getUnsignedRange(AR);
724-
unsigned NumBits = AR->getType()->getIntegerBitWidth();
725-
ConstantRange ValidRange = ConstantRange::getEmpty(NumBits);
726-
727-
if (IsFindFirstIV) {
728-
if (IsSigned)
729-
ValidRange =
730-
ConstantRange::getNonEmpty(APInt::getSignedMinValue(NumBits),
731-
APInt::getSignedMaxValue(NumBits) - 1);
732-
else
733-
ValidRange = ConstantRange::getNonEmpty(APInt::getMinValue(NumBits),
734-
APInt::getMaxValue(NumBits) - 1);
735-
} else {
736-
APInt Sentinel = IsSigned ? APInt::getSignedMinValue(NumBits)
737-
: APInt::getMinValue(NumBits);
738-
ValidRange = ConstantRange::getNonEmpty(Sentinel + 1, Sentinel);
739-
}
740-
741-
LLVM_DEBUG(dbgs() << "LV: " << (IsFindFirstIV ? "FindFirstIV" : "FindLastIV")
742-
<< " valid range is " << ValidRange << ", and the range of "
743-
<< *AR << " is " << IVRange << "\n");
744-
745-
return ValidRange.contains(IVRange);
746-
}
747-
748718
// We are looking for loops that do something like this:
749719
// int r = 0;
750720
// for (int i = 0; i < n; i++) {
@@ -822,24 +792,49 @@ RecurrenceDescriptor::isFindIVPattern(RecurKind Kind, Loop *TheLoop,
822792
// [Signed|Unsigned]Max(<recurrence type>) for FindFirstIV.
823793
// TODO: This range restriction can be lifted by adding an additional
824794
// virtual OR reduction.
825-
bool IsFindFirstIV = isFindFirstIVRecurrenceKind(Kind);
795+
auto CheckRange = [&](bool IsSigned) {
796+
const ConstantRange IVRange =
797+
IsSigned ? SE.getSignedRange(AR) : SE.getUnsignedRange(AR);
798+
unsigned NumBits = Ty->getIntegerBitWidth();
799+
ConstantRange ValidRange = ConstantRange::getEmpty(NumBits);
800+
if (isFindLastIVRecurrenceKind(Kind)) {
801+
APInt Sentinel = IsSigned ? APInt::getSignedMinValue(NumBits)
802+
: APInt::getMinValue(NumBits);
803+
ValidRange = ConstantRange::getNonEmpty(Sentinel + 1, Sentinel);
804+
} else {
805+
if (IsSigned)
806+
ValidRange =
807+
ConstantRange::getNonEmpty(APInt::getSignedMinValue(NumBits),
808+
APInt::getSignedMaxValue(NumBits) - 1);
809+
else
810+
ValidRange = ConstantRange::getNonEmpty(
811+
APInt::getMinValue(NumBits), APInt::getMaxValue(NumBits) - 1);
812+
}
813+
814+
LLVM_DEBUG(dbgs() << "LV: "
815+
<< (isFindLastIVRecurrenceKind(Kind) ? "FindLastIV"
816+
: "FindFirstIV")
817+
<< " valid range is " << ValidRange
818+
<< ", and the range of " << *AR << " is " << IVRange
819+
<< "\n");
820+
821+
// Ensure the induction variable does not wrap around by verifying that
822+
// its range is fully contained within the valid range.
823+
return ValidRange.contains(IVRange);
824+
};
826825
if (isFindLastIVRecurrenceKind(Kind)) {
827-
if (RecurrenceDescriptor::isValidIVRangeForFindIV(
828-
cast<SCEVAddRecExpr>(AR), /*IsSigned=*/true, IsFindFirstIV, SE))
826+
if (CheckRange(true))
829827
return RecurKind::FindLastIVSMax;
830-
if (RecurrenceDescriptor::isValidIVRangeForFindIV(
831-
cast<SCEVAddRecExpr>(AR), /*IsSigned=*/false, IsFindFirstIV, SE))
828+
if (CheckRange(false))
832829
return RecurKind::FindLastIVUMax;
833830
return std::nullopt;
834831
}
835832
assert(isFindFirstIVRecurrenceKind(Kind) &&
836833
"Kind must either be a FindLastIV or FindFirstIV");
837834

838-
if (RecurrenceDescriptor::isValidIVRangeForFindIV(
839-
cast<SCEVAddRecExpr>(AR), /*IsSigned=*/true, IsFindFirstIV, SE))
835+
if (CheckRange(true))
840836
return RecurKind::FindFirstIVSMin;
841-
if (RecurrenceDescriptor::isValidIVRangeForFindIV(
842-
cast<SCEVAddRecExpr>(AR), /*IsSigned=*/false, IsFindFirstIV, SE))
837+
if (CheckRange(false))
843838
return RecurKind::FindFirstIVUMin;
844839
return std::nullopt;
845840
};

0 commit comments

Comments
 (0)