[llvm] [LV] Extend FindFirstIV to unsigned case (PR #146386)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 8 04:40:34 PDT 2025


================
@@ -741,10 +739,9 @@ RecurrenceDescriptor::isFindIVPattern(RecurKind Kind, Loop *TheLoop,
                                   : APInt::getMinValue(NumBits);
         ValidRange = ConstantRange::getNonEmpty(Sentinel + 1, Sentinel);
       } else {
-        assert(IsSigned && "Only FindFirstIV with SMax is supported currently");
-        ValidRange =
-            ConstantRange::getNonEmpty(APInt::getSignedMinValue(NumBits),
-                                       APInt::getSignedMaxValue(NumBits) - 1);
+        APInt Sentinel = IsSigned ? APInt::getSignedMaxValue(NumBits)
+                                  : APInt::getMaxValue(NumBits);
+        ValidRange = ConstantRange::getNonEmpty(Sentinel + 1, Sentinel);
----------------
fhahn wrote:

On second thought, I think  the wrapped range isn't sufficient and this will need to initialize the range with min & max - 1 explicitly as suggested earlier (and also clearer)

Currently test coverage is missing for the case where the IV range includes both signed and unsigned sentinel values.

https://github.com/llvm/llvm-project/pull/146386


More information about the llvm-commits mailing list