Skip to content

Commit 6c9885e

Browse files
committed
[mlir] Check for int limits when converting gpu dims
Signed-off-by: Max Dawkins <[email protected]>
1 parent 10d198b commit 6c9885e

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

mlir/lib/Conversion/GPUCommon/IndexIntrinsicsOpLowering.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ struct OpLowering : public ConvertOpToLLVMPattern<Op> {
116116

117117
if (upperBound && intrType != IntrType::None) {
118118
int32_t min = (intrType == IntrType::Dim ? 1 : 0);
119-
int32_t max = *upperBound + (intrType == IntrType::Id ? 0 : 1);
119+
int32_t max = *upperBound == INT_MAX
120+
? *upperBound
121+
: *upperBound + (intrType == IntrType::Id ? 0 : 1);
120122
newOp->setAttr("range", LLVM::ConstantRangeAttr::get(
121123
rewriter.getContext(), 32, min, max));
122124
}

mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl.mlir

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,3 +763,16 @@ gpu.module @test_module {
763763
gpu.module @test_custom_data_layout attributes {llvm.data_layout = "e"} {
764764

765765
}
766+
767+
// -----
768+
769+
gpu.module @test_module {
770+
// CHECK32-LABEL: func @gpu_dim_int_max_upper_bound()
771+
func.func @gpu_dim_int_max_upper_bound()
772+
-> (index) {
773+
774+
// CHECK32: rocdl.workgroup.dim.x range <i32, 1, 2147483647> : i32
775+
%bDimX = gpu.block_dim x upper_bound 2147483647
776+
func.return %bDimX : index
777+
}
778+
}

0 commit comments

Comments
 (0)