Skip to content

Commit ba87fab

Browse files
committed
Fixed assertion failure for insufficient parsing validation of nvvm dialect with PureSpecialRangeableRegisterOp
1 parent b358af1 commit ba87fab

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,23 @@ class NVVM_PureSpecialRangeableRegisterOp<string mnemonic, list<Trait> traits =
279279
SetIntRangeFn setResultRanges) {
280280
nvvmInferResultRanges(getOperation(), getResult(), argRanges, setResultRanges);
281281
}
282+
283+
// Verify the range attribute satisfies LLVM ConstantRange constructor requirements.
284+
::llvm::LogicalResult $cppClass::verify() {
285+
auto rangeAttr = getRange();
286+
if (!rangeAttr)
287+
return ::mlir::success(); // No range specified, validation passes
288+
289+
const ::llvm::APInt &lower = rangeAttr->getLower();
290+
const ::llvm::APInt &upper = rangeAttr->getUpper();
291+
292+
// Check LLVM ConstantRange constructor condition
293+
if (!(lower != upper || (lower.isMaxValue() || lower.isMinValue()))) {
294+
return emitOpError("invalid range attribute: range must be a valid constant range");
295+
}
296+
297+
return ::mlir::success();
298+
}
282299
}];
283300

284301
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,3 +559,13 @@ llvm.func @clusterlaunchcontrol_query_cancel_get_first_cta_id_invalid_return_typ
559559
%res = nvvm.clusterlaunchcontrol.query.cancel query = get_first_cta_id_x, %try_cancel_response : i1
560560
llvm.return
561561
}
562+
563+
564+
// -----
565+
566+
// Test for range validation - invalid range where lower == upper but not at extremes
567+
func.func @invalid_range_equal_bounds() {
568+
// expected-error @below {{invalid range attribute: range must be a valid constant range}}
569+
%0 = nvvm.read.ptx.sreg.warpsize range <i32, 32, 32> : i32
570+
return
571+
}

0 commit comments

Comments
 (0)