1; RUN: llc < %s -march=nvptx | FileCheck %s
2; RUN: %if ptxas %{ llc < %s -march=nvptx | %ptxas-verify %}
3
4; CHECK: .b8 half_array[8] = {1, 2, 3, 4, 5, 6, 7, 8};
5@"half_array" = addrspace(1) constant [4 x half]
6                [half 0xH0201, half 0xH0403, half 0xH0605, half 0xH0807]
7
8define void @test_load_store(half addrspace(1)* %in, half addrspace(1)* %out) {
9; CHECK-LABEL: @test_load_store
10; CHECK: ld.global.b16 [[TMP:%h[0-9]+]], [{{%r[0-9]+}}]
11; CHECK: st.global.b16 [{{%r[0-9]+}}], [[TMP]]
12  %val = load half, half addrspace(1)* %in
13  store half %val, half addrspace(1) * %out
14  ret void
15}
16
17define void @test_bitcast_from_half(half addrspace(1)* %in, i16 addrspace(1)* %out) {
18; CHECK-LABEL: @test_bitcast_from_half
19; CHECK: ld.global.b16 [[TMP:%h[0-9]+]], [{{%r[0-9]+}}]
20; CHECK: st.global.b16 [{{%r[0-9]+}}], [[TMP]]
21  %val = load half, half addrspace(1) * %in
22  %val_int = bitcast half %val to i16
23  store i16 %val_int, i16 addrspace(1)* %out
24  ret void
25}
26
27define void @test_bitcast_to_half(half addrspace(1)* %out, i16 addrspace(1)* %in) {
28; CHECK-LABEL: @test_bitcast_to_half
29; CHECK: ld.global.u16 [[TMP:%rs[0-9]+]], [{{%r[0-9]+}}]
30; CHECK: st.global.u16 [{{%r[0-9]+}}], [[TMP]]
31  %val = load i16, i16 addrspace(1)* %in
32  %val_fp = bitcast i16 %val to half
33  store half %val_fp, half addrspace(1)* %out
34  ret void
35}
36
37define void @test_extend32(half addrspace(1)* %in, float addrspace(1)* %out) {
38; CHECK-LABEL: @test_extend32
39; CHECK: cvt.f32.f16
40
41  %val16 = load half, half addrspace(1)* %in
42  %val32 = fpext half %val16 to float
43  store float %val32, float addrspace(1)* %out
44  ret void
45}
46
47define void @test_extend64(half addrspace(1)* %in, double addrspace(1)* %out) {
48; CHECK-LABEL: @test_extend64
49; CHECK: cvt.f64.f16
50
51  %val16 = load half, half addrspace(1)* %in
52  %val64 = fpext half %val16 to double
53  store double %val64, double addrspace(1)* %out
54  ret void
55}
56
57define void @test_trunc32(float addrspace(1)* %in, half addrspace(1)* %out) {
58; CHECK-LABEL: test_trunc32
59; CHECK: cvt.rn.f16.f32
60
61  %val32 = load float, float addrspace(1)* %in
62  %val16 = fptrunc float %val32 to half
63  store half %val16, half addrspace(1)* %out
64  ret void
65}
66
67define void @test_trunc64(double addrspace(1)* %in, half addrspace(1)* %out) {
68; CHECK-LABEL: @test_trunc64
69; CHECK: cvt.rn.f16.f64
70
71  %val32 = load double, double addrspace(1)* %in
72  %val16 = fptrunc double %val32 to half
73  store half %val16, half addrspace(1)* %out
74  ret void
75}
76