[Mlir-commits] [mlir] [mlir][scf] Fix unsigned narrow type trip count calculation (PR #178060)

Mehdi Amini llvmlistbot at llvm.org
Tue Jan 27 05:21:08 PST 2026


================
@@ -336,7 +336,10 @@ std::optional<APInt> constantTripCount(
       // case applies, so the static trip count is unknown.
       return std::nullopt;
     }
-    if (stepCst.isNegative())
+    // For unsigned values, negative step is impossible; for signed, check the
+    // sign bit properly using APSInt.
+    APSInt stepSInt(stepCst, /*isUnsigned=*/!isSigned);
+    if (stepSInt.isNegative())
       return APInt(bitwidth, 0);
----------------
joker-eph wrote:

A negative step with LB>UB should not yield a 0 trip count should it?

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


More information about the Mlir-commits mailing list