Skip to content

Commit 62bcfcb

Browse files
committed
[AMDGPU] Add llvm.amdgcn.s.setprio intrinsic
Reviewed By: rampitec, arsenm Differential Revision: https://reviews.llvm.org/D120976
1 parent e825f49 commit 62bcfcb

File tree

6 files changed

+74
-1
lines changed

6 files changed

+74
-1
lines changed

clang/include/clang/Basic/BuiltinsAMDGPU.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ BUILTIN(__builtin_amdgcn_cubema, "ffff", "nc")
116116
BUILTIN(__builtin_amdgcn_s_sleep, "vIi", "n")
117117
BUILTIN(__builtin_amdgcn_s_incperflevel, "vIi", "n")
118118
BUILTIN(__builtin_amdgcn_s_decperflevel, "vIi", "n")
119+
BUILTIN(__builtin_amdgcn_s_setprio, "vIs", "n")
119120
BUILTIN(__builtin_amdgcn_uicmp, "WUiUiUiIi", "nc")
120121
BUILTIN(__builtin_amdgcn_uicmpl, "WUiWUiWUiIi", "nc")
121122
BUILTIN(__builtin_amdgcn_sicmp, "WUiiiIi", "nc")

clang/test/CodeGenOpenCL/builtins-amdgcn.cl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,15 @@ void test_s_decperflevel()
423423
__builtin_amdgcn_s_decperflevel(15);
424424
}
425425

426+
// CHECK-LABEL: @test_s_setprio
427+
// CHECK: call void @llvm.amdgcn.s.setprio(i16 0)
428+
// CHECK: call void @llvm.amdgcn.s.setprio(i16 3)
429+
void test_s_setprio()
430+
{
431+
__builtin_amdgcn_s_setprio(0);
432+
__builtin_amdgcn_s_setprio(3);
433+
}
434+
426435
// CHECK-LABEL: @test_cubeid(
427436
// CHECK: call float @llvm.amdgcn.cubeid(float %a, float %b, float %c)
428437
void test_cubeid(global float* out, float a, float b, float c) {

clang/test/SemaOpenCL/builtins-amdgcn-error.cl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ void test_s_decperflevel(int x)
5454
__builtin_amdgcn_s_decperflevel(x); // expected-error {{argument to '__builtin_amdgcn_s_decperflevel' must be a constant integer}}
5555
}
5656

57+
void test_s_setprio(int x)
58+
{
59+
__builtin_amdgcn_s_setprio(x); // expected-error {{argument to '__builtin_amdgcn_s_setprio' must be a constant integer}}
60+
__builtin_amdgcn_s_setprio(65536); // expected-warning {{implicit conversion from 'int' to 'short' changes value from 65536 to 0}}
61+
}
62+
5763
void test_sicmp_i32(global ulong* out, int a, int b, uint c)
5864
{
5965
*out = __builtin_amdgcn_sicmp(a, b, c); // expected-error {{argument to '__builtin_amdgcn_sicmp' must be a constant integer}}

llvm/include/llvm/IR/IntrinsicsAMDGPU.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,11 @@ def int_amdgcn_s_sethalt :
13291329
Intrinsic<[], [llvm_i32_ty], [ImmArg<ArgIndex<0>>, IntrNoMem,
13301330
IntrHasSideEffects, IntrWillReturn]>;
13311331

1332+
def int_amdgcn_s_setprio :
1333+
GCCBuiltin<"__builtin_amdgcn_s_setprio">,
1334+
Intrinsic<[], [llvm_i16_ty], [ImmArg<ArgIndex<0>>, IntrNoMem,
1335+
IntrHasSideEffects, IntrWillReturn]>;
1336+
13321337
def int_amdgcn_s_getreg :
13331338
GCCBuiltin<"__builtin_amdgcn_s_getreg">,
13341339
Intrinsic<[llvm_i32_ty], [llvm_i32_ty],

llvm/lib/Target/AMDGPU/SOPInstructions.td

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,10 @@ def S_SLEEP : SOPP_Pseudo <"s_sleep", (ins i32imm:$simm16),
12781278
let hasSideEffects = 1;
12791279
}
12801280

1281-
def S_SETPRIO : SOPP_Pseudo <"s_setprio" , (ins i16imm:$simm16), "$simm16">;
1281+
def S_SETPRIO : SOPP_Pseudo <"s_setprio", (ins i16imm:$simm16), "$simm16",
1282+
[(int_amdgcn_s_setprio timm:$simm16)]> {
1283+
let hasSideEffects = 1;
1284+
}
12821285

12831286
let Uses = [EXEC, M0] in {
12841287
// FIXME: Should this be mayLoad+mayStore?
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -march=amdgcn -mcpu=gfx90a -show-mc-encoding -verify-machineinstrs < %s | FileCheck -check-prefix=GFX9 %s
3+
; RUN: llc -march=amdgcn -show-mc-encoding -verify-machineinstrs < %s | FileCheck -check-prefix=SI %s
4+
; RUN: llc -global-isel -march=amdgcn -show-mc-encoding -verify-machineinstrs < %s | FileCheck -check-prefix=SI %s
5+
; RUN: llc -global-isel -march=amdgcn -mcpu=gfx90a -show-mc-encoding -verify-machineinstrs < %s | FileCheck -check-prefix=GFX9 %s
6+
7+
declare void @llvm.amdgcn.s.setprio(i16) #0
8+
9+
define void @test_llvm_amdgcn_s_setprio() #0 {
10+
; GFX9-LABEL: test_llvm_amdgcn_s_setprio:
11+
; GFX9: ; %bb.0:
12+
; GFX9-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) ; encoding: [0x00,0x00,0x8c,0xbf]
13+
; GFX9-NEXT: s_setprio 0 ; encoding: [0x00,0x00,0x8f,0xbf]
14+
; GFX9-NEXT: s_setprio 1 ; encoding: [0x01,0x00,0x8f,0xbf]
15+
; GFX9-NEXT: s_setprio 2 ; encoding: [0x02,0x00,0x8f,0xbf]
16+
; GFX9-NEXT: s_setprio 3 ; encoding: [0x03,0x00,0x8f,0xbf]
17+
; GFX9-NEXT: s_setprio 10 ; encoding: [0x0a,0x00,0x8f,0xbf]
18+
; GFX9-NEXT: s_setprio -1 ; encoding: [0xff,0xff,0x8f,0xbf]
19+
; GFX9-NEXT: s_setprio 0 ; encoding: [0x00,0x00,0x8f,0xbf]
20+
; GFX9-NEXT: s_setprio 1 ; encoding: [0x01,0x00,0x8f,0xbf]
21+
; GFX9-NEXT: s_setprio -1 ; encoding: [0xff,0xff,0x8f,0xbf]
22+
; GFX9-NEXT: s_setpc_b64 s[30:31] ; encoding: [0x1e,0x1d,0x80,0xbe]
23+
;
24+
; SI-LABEL: test_llvm_amdgcn_s_setprio:
25+
; SI: ; %bb.0:
26+
; SI-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) ; encoding: [0x00,0x00,0x8c,0xbf]
27+
; SI-NEXT: s_setprio 0 ; encoding: [0x00,0x00,0x8f,0xbf]
28+
; SI-NEXT: s_setprio 1 ; encoding: [0x01,0x00,0x8f,0xbf]
29+
; SI-NEXT: s_setprio 2 ; encoding: [0x02,0x00,0x8f,0xbf]
30+
; SI-NEXT: s_setprio 3 ; encoding: [0x03,0x00,0x8f,0xbf]
31+
; SI-NEXT: s_setprio 10 ; encoding: [0x0a,0x00,0x8f,0xbf]
32+
; SI-NEXT: s_setprio -1 ; encoding: [0xff,0xff,0x8f,0xbf]
33+
; SI-NEXT: s_setprio 0 ; encoding: [0x00,0x00,0x8f,0xbf]
34+
; SI-NEXT: s_setprio 1 ; encoding: [0x01,0x00,0x8f,0xbf]
35+
; SI-NEXT: s_setprio -1 ; encoding: [0xff,0xff,0x8f,0xbf]
36+
; SI-NEXT: s_setpc_b64 s[30:31] ; encoding: [0x1e,0x20,0x80,0xbe]
37+
call void @llvm.amdgcn.s.setprio(i16 0)
38+
call void @llvm.amdgcn.s.setprio(i16 1)
39+
call void @llvm.amdgcn.s.setprio(i16 2)
40+
call void @llvm.amdgcn.s.setprio(i16 3)
41+
call void @llvm.amdgcn.s.setprio(i16 10)
42+
call void @llvm.amdgcn.s.setprio(i16 65535)
43+
call void @llvm.amdgcn.s.setprio(i16 65536)
44+
call void @llvm.amdgcn.s.setprio(i16 65537)
45+
call void @llvm.amdgcn.s.setprio(i16 -1)
46+
ret void
47+
}
48+
49+
attributes #0 = { nounwind }

0 commit comments

Comments
 (0)