1 ; RUN: llc < %s -march=nvptx64 -mcpu=sm_20 -verify-machineinstrs | FileCheck %s --check-prefix=SM20
2 ; RUN: llc < %s -march=nvptx64 -mcpu=sm_30 -verify-machineinstrs | FileCheck %s --check-prefix=SM30
3 ; RUN: %if ptxas %{ llc < %s -march=nvptx64 -mcpu=sm_20 -verify-machineinstrs | %ptxas-verify %}
4 ; RUN: %if ptxas %{ llc < %s -march=nvptx64 -mcpu=sm_30 -verify-machineinstrs | %ptxas-verify %}
7 target triple = "nvptx-unknown-cuda"
9 declare { float, float, float, float } @llvm.nvvm.tex.unified.1d.v4f32.s32(i64, i32)
10 declare i64 @llvm.nvvm.texsurf.handle.internal.p1(ptr addrspace(1))
12 ; SM20-LABEL: .entry foo
13 ; SM30-LABEL: .entry foo
14 define void @foo(i64 %img, ptr %red, i32 %idx) {
15 ; SM20: ld.param.u64 %rd[[TEXREG:[0-9]+]], [foo_param_0];
16 ; SM20: tex.1d.v4.f32.s32 {%f[[RED:[0-9]+]], %f[[GREEN:[0-9]+]], %f[[BLUE:[0-9]+]], %f[[ALPHA:[0-9]+]]}, [%rd[[TEXREG]], {%r{{[0-9]+}}}]
17 ; SM30: ld.param.u64 %rd[[TEXREG:[0-9]+]], [foo_param_0];
18 ; SM30: tex.1d.v4.f32.s32 {%f[[RED:[0-9]+]], %f[[GREEN:[0-9]+]], %f[[BLUE:[0-9]+]], %f[[ALPHA:[0-9]+]]}, [%rd[[TEXREG]], {%r{{[0-9]+}}}]
19 %val = tail call { float, float, float, float } @llvm.nvvm.tex.unified.1d.v4f32.s32(i64 %img, i32 %idx)
20 %ret = extractvalue { float, float, float, float } %val, 0
21 ; SM20: st.global.f32 [%rd{{[0-9]+}}], %f[[RED]]
22 ; SM30: st.global.f32 [%rd{{[0-9]+}}], %f[[RED]]
23 store float %ret, ptr %red
28 @tex0 = internal addrspace(1) global i64 0, align 8
30 ; SM20-LABEL: .entry bar
31 ; SM30-LABEL: .entry bar
32 define void @bar(ptr %red, i32 %idx) {
33 ; SM30: mov.u64 %rd[[TEXHANDLE:[0-9]+]], tex0
34 %texHandle = tail call i64 @llvm.nvvm.texsurf.handle.internal.p1(ptr addrspace(1) @tex0)
35 ; SM20: tex.1d.v4.f32.s32 {%f[[RED:[0-9]+]], %f[[GREEN:[0-9]+]], %f[[BLUE:[0-9]+]], %f[[ALPHA:[0-9]+]]}, [tex0, {%r{{[0-9]+}}}]
36 ; SM30: tex.1d.v4.f32.s32 {%f[[RED:[0-9]+]], %f[[GREEN:[0-9]+]], %f[[BLUE:[0-9]+]], %f[[ALPHA:[0-9]+]]}, [%rd[[TEXHANDLE]], {%r{{[0-9]+}}}]
37 %val = tail call { float, float, float, float } @llvm.nvvm.tex.unified.1d.v4f32.s32(i64 %texHandle, i32 %idx)
38 %ret = extractvalue { float, float, float, float } %val, 0
39 ; SM20: st.global.f32 [%rd{{[0-9]+}}], %f[[RED]]
40 ; SM30: st.global.f32 [%rd{{[0-9]+}}], %f[[RED]]
41 store float %ret, ptr %red
45 declare float @texfunc(i64)
47 ; SM20-LABEL: .entry baz
48 ; SM30-LABEL: .entry baz
49 define void @baz(ptr %red, i32 %idx) {
50 ; SM30: mov.u64 %rd[[TEXHANDLE:[0-9]+]], tex0
51 %texHandle = tail call i64 @llvm.nvvm.texsurf.handle.internal.p1(ptr addrspace(1) @tex0)
52 ; SM20: tex.1d.v4.f32.s32 {%f[[RED:[0-9]+]], %f[[GREEN:[0-9]+]], %f[[BLUE:[0-9]+]], %f[[ALPHA:[0-9]+]]}, [tex0, {%r{{[0-9]+}}}]
53 ; SM30: tex.1d.v4.f32.s32 {%f[[RED:[0-9]+]], %f[[GREEN:[0-9]+]], %f[[BLUE:[0-9]+]], %f[[ALPHA:[0-9]+]]}, [%rd[[TEXHANDLE]], {%r{{[0-9]+}}}]
54 %val = tail call { float, float, float, float } @llvm.nvvm.tex.unified.1d.v4f32.s32(i64 %texHandle, i32 %idx)
55 %ret = extractvalue { float, float, float, float } %val, 0
56 ; SM20: call.uni ([[RETVAL:.*]]),
57 ; SM30: call.uni ([[RETVAL:.*]]),
60 %texcall = tail call float @texfunc(i64 %texHandle)
61 ; SM20: ld.param.f32 %f[[TEXCALL:[0-9]+]], [[[RETVAL]]+0]
62 ; SM30: ld.param.f32 %f[[TEXCALL:[0-9]+]], [[[RETVAL]]+0]
63 ; SM20: add.rn.f32 %f[[RET2:[0-9]+]], %f[[RED]], %f[[TEXCALL]]
64 ; SM30: add.rn.f32 %f[[RET2:[0-9]+]], %f[[RED]], %f[[TEXCALL]]
65 %ret2 = fadd float %ret, %texcall
66 ; SM20: st.global.f32 [%rd{{[0-9]+}}], %f[[RET2]]
67 ; SM30: st.global.f32 [%rd{{[0-9]+}}], %f[[RET2]]
68 store float %ret2, ptr %red
72 !nvvm.annotations = !{!1, !2, !3, !4}
73 !1 = !{ptr @foo, !"kernel", i32 1}
74 !2 = !{ptr @bar, !"kernel", i32 1}
75 !3 = !{ptr addrspace(1) @tex0, !"texture", i32 1}
76 !4 = !{ptr @baz, !"kernel", i32 1}