Skip to content

Commit f92d1a3

Browse files
committed
[IVDesc] Simplify with lambda (NFC)
1 parent 3cd18d3 commit f92d1a3

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

llvm/lib/Analysis/IVDescriptors.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -717,32 +717,32 @@ RecurrenceDescriptor::isFindLastIVPattern(Loop *TheLoop, PHINode *OrigPhi,
717717
if (!SE.isKnownPositive(Step))
718718
return std::nullopt;
719719

720-
const ConstantRange SignedIVRange = SE.getSignedRange(AR);
721-
const ConstantRange UnsignedIVRange = SE.getUnsignedRange(AR);
722-
unsigned NumBits = Ty->getIntegerBitWidth();
723720
// Keep the minimum value of the recurrence type as the sentinel value.
724721
// The maximum acceptable range for the increasing induction variable,
725722
// called the valid range, will be defined as
726723
// [<sentinel value> + 1, <sentinel value>)
727724
// where <sentinel value> is [Signed|Unsigned]Min(<recurrence type>)
728725
// TODO: This range restriction can be lifted by adding an additional
729726
// virtual OR reduction.
730-
const APInt SignedSentinel = APInt::getSignedMinValue(NumBits);
731-
const APInt UnsignedSentinel = APInt::getMinValue(NumBits);
732-
const ConstantRange ValidSignedRange =
733-
ConstantRange::getNonEmpty(SignedSentinel + 1, SignedSentinel);
734-
const ConstantRange ValidUnsignedRange =
735-
ConstantRange::getNonEmpty(UnsignedSentinel + 1, UnsignedSentinel);
736-
LLVM_DEBUG(dbgs() << "LV: FindLastIV valid signed range is "
737-
<< ValidSignedRange << ", valid unsigned range is "
738-
<< ValidUnsignedRange << ", " << *AR
739-
<< " signed range is " << SignedIVRange
740-
<< ", and unsigned range is " << UnsignedIVRange << "\n");
741-
// Ensure the induction variable does not wrap around by verifying that its
742-
// range is fully contained within the valid range.
743-
if (ValidSignedRange.contains(SignedIVRange))
727+
auto CheckRange = [&](bool IsSigned) {
728+
const ConstantRange IVRange =
729+
IsSigned ? SE.getSignedRange(AR) : SE.getUnsignedRange(AR);
730+
unsigned NumBits = Ty->getIntegerBitWidth();
731+
const APInt Sentinel = IsSigned ? APInt::getSignedMinValue(NumBits)
732+
: APInt::getMinValue(NumBits);
733+
const ConstantRange ValidRange =
734+
ConstantRange::getNonEmpty(Sentinel + 1, Sentinel);
735+
LLVM_DEBUG(dbgs() << "LV: FindLastIV valid range is " << ValidRange
736+
<< ", and the range of " << *AR << " is " << IVRange
737+
<< "\n");
738+
739+
// Ensure the induction variable does not wrap around by verifying that
740+
// its range is fully contained within the valid range.
741+
return ValidRange.contains(IVRange);
742+
};
743+
if (CheckRange(true))
744744
return true;
745-
if (ValidUnsignedRange.contains(UnsignedIVRange))
745+
if (CheckRange(false))
746746
return false;
747747
return std::nullopt;
748748
};

0 commit comments

Comments
 (0)