Skip to content

Commit bfee625

Browse files
authored
[NVPTX] Attach Range attr to setmaxnreg and fence intrinsics (#144120)
This patch attaches the range attribute to the setmaxnreg and fence.proxy.tensormap.* intrinsics. The range checks are now handled generically in the Verifier. So, this patch removes the per-intrinsic error-handling for range-checks from the Verifier. This patch also adds more coverage tests for these cases. Signed-off-by: Durgadoss R <[email protected]>
1 parent faf9295 commit bfee625

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

llvm/include/llvm/IR/IntrinsicsNVVM.td

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,9 +1341,11 @@ foreach scope = ["cta", "cluster", "gpu", "sys"] in {
13411341
Intrinsic<[], [], [IntrNoCallback],
13421342
"llvm.nvvm.fence.proxy.tensormap_generic.release." # scope>;
13431343

1344+
// The imm-arg 'size' can only be 128.
13441345
def int_nvvm_fence_proxy_tensormap_generic_acquire_ # scope :
13451346
Intrinsic<[], [llvm_ptr_ty, llvm_i32_ty],
1346-
[IntrNoCallback, IntrArgMemOnly, ImmArg<ArgIndex<1>>],
1347+
[IntrNoCallback, IntrArgMemOnly, ImmArg<ArgIndex<1>>,
1348+
Range<ArgIndex<1>, 128, 129>],
13471349
"llvm.nvvm.fence.proxy.tensormap_generic.acquire." # scope>;
13481350
}
13491351

@@ -1989,10 +1991,12 @@ def int_nvvm_is_explicit_cluster
19891991
"llvm.nvvm.is_explicit_cluster">;
19901992

19911993
// Setmaxnreg inc/dec intrinsics
1994+
// The imm-arg should be in the range: 24 <= val <= 256
19921995
foreach op = ["dec", "inc"] in
19931996
def int_nvvm_setmaxnreg_ # op # _sync_aligned_u32
19941997
: DefaultAttrsIntrinsic<[], [llvm_i32_ty],
1995-
[IntrConvergent, IntrNoMem, IntrHasSideEffects, ImmArg<ArgIndex<0>>]>;
1998+
[IntrConvergent, IntrNoMem, IntrHasSideEffects,
1999+
ImmArg<ArgIndex<0>>, Range<ArgIndex<0>, 24, 257>]>;
19962000

19972001
// Exit
19982002
def int_nvvm_exit : NVVMBuiltin,

llvm/lib/IR/Verifier.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6557,8 +6557,6 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
65576557
unsigned RegCount = cast<ConstantInt>(V)->getZExtValue();
65586558
Check(RegCount % 8 == 0,
65596559
"reg_count argument to nvvm.setmaxnreg must be in multiples of 8");
6560-
Check((RegCount >= 24 && RegCount <= 256),
6561-
"reg_count argument to nvvm.setmaxnreg must be within [24, 256]");
65626560
break;
65636561
}
65646562
case Intrinsic::experimental_convergence_entry:
@@ -6605,14 +6603,6 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
66056603
"llvm.threadlocal.address operand isThreadLocal() must be true");
66066604
break;
66076605
}
6608-
case Intrinsic::nvvm_fence_proxy_tensormap_generic_acquire_cta:
6609-
case Intrinsic::nvvm_fence_proxy_tensormap_generic_acquire_cluster:
6610-
case Intrinsic::nvvm_fence_proxy_tensormap_generic_acquire_gpu:
6611-
case Intrinsic::nvvm_fence_proxy_tensormap_generic_acquire_sys: {
6612-
unsigned size = cast<ConstantInt>(Call.getArgOperand(1))->getZExtValue();
6613-
Check(size == 128, " The only supported value for size operand is 128");
6614-
break;
6615-
}
66166606
};
66176607

66186608
// Verify that there aren't any unmediated control transfers between funclets.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; RUN: not llvm-as %s -o /dev/null 2>&1 | FileCheck %s
2+
3+
define void @test_fence_proxy_tensormap_generic_acquire(ptr addrspace(0) %addr) {
4+
; CHECK: immarg value 127 out of range [128, 129)
5+
call void @llvm.nvvm.fence.proxy.tensormap_generic.acquire.cta(ptr addrspace(0) %addr, i32 127);
6+
7+
; CHECK: immarg value 129 out of range [128, 129)
8+
call void @llvm.nvvm.fence.proxy.tensormap_generic.acquire.cluster(ptr addrspace(0) %addr, i32 129);
9+
10+
; CHECK: immarg value 127 out of range [128, 129)
11+
call void @llvm.nvvm.fence.proxy.tensormap_generic.acquire.gpu(ptr addrspace(0) %addr, i32 127);
12+
13+
; CHECK: immarg value 129 out of range [128, 129)
14+
call void @llvm.nvvm.fence.proxy.tensormap_generic.acquire.sys(ptr addrspace(0) %addr, i32 129);
15+
16+
ret void
17+
}

llvm/test/Verifier/NVPTX/setmaxnreg.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ define void @test_set_maxn_reg() {
77
; CHECK: reg_count argument to nvvm.setmaxnreg must be in multiples of 8
88
call void @llvm.nvvm.setmaxnreg.inc.sync.aligned.u32(i32 95)
99

10-
; CHECK: reg_count argument to nvvm.setmaxnreg must be within [24, 256]
10+
; CHECK: immarg value 16 out of range [24, 257)
1111
call void @llvm.nvvm.setmaxnreg.dec.sync.aligned.u32(i32 16)
1212

13+
; CHECK: immarg value 264 out of range [24, 257)
14+
call void @llvm.nvvm.setmaxnreg.dec.sync.aligned.u32(i32 264)
1315
ret void
1416
}

0 commit comments

Comments
 (0)