Skip to content

Commit c26f5db

Browse files
committed
Added more tests for rangeable register ops, clarified error msg
1 parent 6d128fd commit c26f5db

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,13 @@ class NVVM_PureSpecialRangeableRegisterOp<string mnemonic, list<Trait> traits =
291291
const ::llvm::APInt &upper = rangeAttr->getUpper();
292292

293293
// Check LLVM ConstantRange constructor condition
294-
if (!(lower != upper || (lower.isMaxValue() || lower.isMinValue()))) {
295-
return emitOpError("invalid range attribute: range must be a valid constant range");
294+
if (lower == upper && !lower.isMaxValue() && !lower.isMinValue()) {
295+
unsigned bitWidth = lower.getBitWidth();
296+
::llvm::APInt minVal = ::llvm::APInt::getMinValue(bitWidth);
297+
::llvm::APInt maxVal = ::llvm::APInt::getMaxValue(bitWidth);
298+
return emitOpError("invalid range attribute: Lower == Upper, but they aren't min (")
299+
<< ::llvm::toString(minVal, 10, false) << ") or max ("
300+
<< ::llvm::toString(maxVal, 10, false) << ") value! This is an invalid constant range.";
296301
}
297302

298303
return ::mlir::success();

mlir/test/Target/LLVMIR/nvvmir-invalid.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ llvm.func @clusterlaunchcontrol_query_cancel_get_first_cta_id_invalid_return_typ
565565

566566
// Test for range validation - invalid range where lower == upper but not at extremes
567567
func.func @invalid_range_equal_bounds() {
568-
// expected-error @below {{invalid range attribute: range must be a valid constant range}}
568+
// expected-error @below {{invalid range attribute: Lower == Upper, but they aren't min (0) or max (4294967295) value! This is an invalid constant range.}}
569569
%0 = nvvm.read.ptx.sreg.warpsize range <i32, 32, 32> : i32
570570
return
571571
}

mlir/test/Target/LLVMIR/nvvmir.mlir

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ llvm.func @nvvm_special_regs() -> i32 {
152152
%74 = nvvm.read.ptx.sreg.lanemask.ge : i32
153153
//CHECK: call i32 @llvm.nvvm.read.ptx.sreg.lanemask.gt
154154
%75 = nvvm.read.ptx.sreg.lanemask.gt : i32
155+
// CHECK: %76 = call range(i32 0, 0) i32 @llvm.nvvm.read.ptx.sreg.tid.x()
156+
%76 = nvvm.read.ptx.sreg.tid.x range <i32, 0, 0> : i32
157+
// CHECK: %77 = call i32 @llvm.nvvm.read.ptx.sreg.tid.x()
158+
%77 = nvvm.read.ptx.sreg.tid.x range <i32, 4294967295, 4294967295> : i32
155159
llvm.return %1 : i32
156160
}
157161

0 commit comments

Comments
 (0)