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

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 6 11:37:31 PDT 2025


================
@@ -741,10 +742,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, Sentinel - 1);
----------------
artagnon wrote:

As a compromise, I've clarified it in the header comment and kept (Sentinel + 1, Sentinel) for uniformity.

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


More information about the llvm-commits mailing list