@@ -717,32 +717,32 @@ RecurrenceDescriptor::isFindLastIVPattern(Loop *TheLoop, PHINode *OrigPhi,
717
717
if (!SE.isKnownPositive (Step))
718
718
return std::nullopt;
719
719
720
- const ConstantRange SignedIVRange = SE.getSignedRange (AR);
721
- const ConstantRange UnsignedIVRange = SE.getUnsignedRange (AR);
722
- unsigned NumBits = Ty->getIntegerBitWidth ();
723
720
// Keep the minimum value of the recurrence type as the sentinel value.
724
721
// The maximum acceptable range for the increasing induction variable,
725
722
// called the valid range, will be defined as
726
723
// [<sentinel value> + 1, <sentinel value>)
727
724
// where <sentinel value> is [Signed|Unsigned]Min(<recurrence type>)
728
725
// TODO: This range restriction can be lifted by adding an additional
729
726
// 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 ))
744
744
return true ;
745
- if (ValidUnsignedRange. contains (UnsignedIVRange ))
745
+ if (CheckRange ( false ))
746
746
return false ;
747
747
return std::nullopt;
748
748
};
0 commit comments