[Mlir-commits] [mlir] [mlir][NVVM] Fix signed and unsigned inference of register ranges (PR #237116)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Nov 1 19:48:58 PST 2026


================
@@ -5950,11 +5951,23 @@ void mlir::NVVM::nvvmInferResultRanges(
     ArrayRef<::mlir::ConstantIntRanges> argRanges,
     SetIntRangeFn setResultRanges) {
   if (range) {
-    setResultRanges(result, {range->getLower(), range->getUpper(),
-                             range->getLower(), range->getUpper()});
-  } else {
-    setResultRanges(result, IntegerValueRange::getMaxRange(result).getValue());
+    // ConstantRange uses a half-open interval of bit patterns, whereas
+    // ConstantIntRanges uses inclusive signed and unsigned bounds. Derive
+    // each interpretation separately to handle wrapping and sign boundaries.
+    llvm::ConstantRange valueRange(range->getLower(), range->getUpper());
+    if (!valueRange.isEmptySet()) {
+      setResultRanges(result,
+                      {valueRange.getUnsignedMin(), valueRange.getUnsignedMax(),
+                       valueRange.getSignedMin(), valueRange.getSignedMax()});
+      return;
+    }
   }
+  // An empty ConstantRange has no values and cannot be represented by the
+  // inclusive bounds in ConstantIntRanges. Its endpoints must not be treated as
+  // valid minima/maxima. Fall back to the full signed and unsigned ranges, as
+  // when no range attribute is present, to record an unknown value explicitly
+  // and avoid folding comparisons based on inconsistent empty-set bounds.
----------------
frokaikan wrote:

The comment can be shortened, but the empty-set guard is intentional. For the empty range [0, 0), getSignedMin() returns 0 and getSignedMax() returns -1, which would produce inconsistent inclusive bounds. Since ConstantIntRanges cannot represent an empty set, this conservatively falls back to the full range, matching the behavior when no range attribute is present.

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


More information about the Mlir-commits mailing list