[Mlir-commits] [mlir] [MLIR][NVVM] Fixed assertion failure for insufficient parsing validation of nvvm dialect PureSpecialRangeableRegisterOp (PR #163434)
Stefan Mada
llvmlistbot at llvm.org
Tue Oct 14 12:05:02 PDT 2025
https://github.com/smada3 created https://github.com/llvm/llvm-project/pull/163434
The nvvm dialect instruction PureSpecialRangeableRegisterOp will trigger an assertion failure in LLVM's constant range class when the lower and upper range bounds are equal, but not equal to the integer minimum or max (as required by constant ranges). This requirement is at [line 56 of ConstantRange.cpp](https://llvm.org/doxygen/ConstantRange_8cpp_source.html#l00056):
`assert((Lower != Upper || (Lower.isMaxValue() || Lower.isMinValue())) && "Lower == Upper, but they aren't min or max value!");`
However, you can write an NVVM dialect operation such as:
`%0 = nvvm.read.ptx.sreg.warpsize range <i32, 32, 32> : i32`
which triggers this assertion. This change adds a fix to ensure that this requirement is also enforced by NVVM.
>From ba87fab55f460014ab0d07667e93404b05b21546 Mon Sep 17 00:00:00 2001
From: Stefan Mada <smada at nvidia.com>
Date: Tue, 14 Oct 2025 19:02:01 +0000
Subject: [PATCH] Fixed assertion failure for insufficient parsing validation
of nvvm dialect with PureSpecialRangeableRegisterOp
---
mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td | 17 +++++++++++++++++
mlir/test/Target/LLVMIR/nvvmir-invalid.mlir | 10 ++++++++++
2 files changed, 27 insertions(+)
diff --git a/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
index 89fbeb7270a38..e4e23ecf77d8b 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
@@ -279,6 +279,23 @@ class NVVM_PureSpecialRangeableRegisterOp<string mnemonic, list<Trait> traits =
SetIntRangeFn setResultRanges) {
nvvmInferResultRanges(getOperation(), getResult(), argRanges, setResultRanges);
}
+
+ // Verify the range attribute satisfies LLVM ConstantRange constructor requirements.
+ ::llvm::LogicalResult $cppClass::verify() {
+ auto rangeAttr = getRange();
+ if (!rangeAttr)
+ return ::mlir::success(); // No range specified, validation passes
+
+ const ::llvm::APInt &lower = rangeAttr->getLower();
+ const ::llvm::APInt &upper = rangeAttr->getUpper();
+
+ // Check LLVM ConstantRange constructor condition
+ if (!(lower != upper || (lower.isMaxValue() || lower.isMinValue()))) {
+ return emitOpError("invalid range attribute: range must be a valid constant range");
+ }
+
+ return ::mlir::success();
+ }
}];
}
diff --git a/mlir/test/Target/LLVMIR/nvvmir-invalid.mlir b/mlir/test/Target/LLVMIR/nvvmir-invalid.mlir
index 0b3615487716d..27727d9bb5836 100644
--- a/mlir/test/Target/LLVMIR/nvvmir-invalid.mlir
+++ b/mlir/test/Target/LLVMIR/nvvmir-invalid.mlir
@@ -559,3 +559,13 @@ llvm.func @clusterlaunchcontrol_query_cancel_get_first_cta_id_invalid_return_typ
%res = nvvm.clusterlaunchcontrol.query.cancel query = get_first_cta_id_x, %try_cancel_response : i1
llvm.return
}
+
+
+// -----
+
+// Test for range validation - invalid range where lower == upper but not at extremes
+func.func @invalid_range_equal_bounds() {
+ // expected-error @below {{invalid range attribute: range must be a valid constant range}}
+ %0 = nvvm.read.ptx.sreg.warpsize range <i32, 32, 32> : i32
+ return
+}
More information about the Mlir-commits
mailing list