1 ; RUN: llc < %s -march=nvptx64 -mcpu=sm_20 -verify-machineinstrs | FileCheck %s
2 ; RUN: %if ptxas %{ llc < %s -march=nvptx64 -mcpu=sm_20 -verify-machineinstrs | %ptxas-verify %}
4 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64"
6 declare i16 @llvm.ctlz.i16(i16, i1) readnone
7 declare i32 @llvm.ctlz.i32(i32, i1) readnone
8 declare i64 @llvm.ctlz.i64(i64, i1) readnone
10 ; There should be no difference between llvm.ctlz.i32(%a, true) and
11 ; llvm.ctlz.i32(%a, false), as ptx's clz(0) is defined to return 0.
13 ; CHECK-LABEL: myctlz(
14 define i32 @myctlz(i32 %a) {
17 ; CHECK-NEXT: st.param.
19 %val = call i32 @llvm.ctlz.i32(i32 %a, i1 false) readnone
22 ; CHECK-LABEL: myctlz_2(
23 define i32 @myctlz_2(i32 %a) {
26 ; CHECK-NEXT: st.param.
28 %val = call i32 @llvm.ctlz.i32(i32 %a, i1 true) readnone
32 ; PTX's clz.b64 returns a 32-bit value, but LLVM's intrinsic returns a 64-bit
33 ; value, so here we have to zero-extend it.
34 ; CHECK-LABEL: myctlz64(
35 define i64 @myctlz64(i64 %a) {
38 ; CHECK-NEXT: cvt.u64.u32
39 ; CHECK-NEXT: st.param.
41 %val = call i64 @llvm.ctlz.i64(i64 %a, i1 false) readnone
44 ; CHECK-LABEL: myctlz64_2(
45 define i64 @myctlz64_2(i64 %a) {
48 ; CHECK-NEXT: cvt.u64.u32
49 ; CHECK-NEXT: st.param.
51 %val = call i64 @llvm.ctlz.i64(i64 %a, i1 true) readnone
55 ; Here we truncate the 64-bit value of LLVM's ctlz intrinsic to 32 bits, the
56 ; natural return width of ptx's clz.b64 instruction. No conversions should be
57 ; necessary in the PTX.
58 ; CHECK-LABEL: myctlz64_as_32(
59 define i32 @myctlz64_as_32(i64 %a) {
62 ; CHECK-NEXT: st.param.
64 %val = call i64 @llvm.ctlz.i64(i64 %a, i1 false) readnone
65 %trunc = trunc i64 %val to i32
68 ; CHECK-LABEL: myctlz64_as_32_2(
69 define i32 @myctlz64_as_32_2(i64 %a) {
72 ; CHECK-NEXT: st.param.
74 %val = call i64 @llvm.ctlz.i64(i64 %a, i1 false) readnone
75 %trunc = trunc i64 %val to i32
79 ; ctlz.i16 is implemented by extending the input to i32, computing the result,
80 ; and then truncating the result back down to i16. But the NVPTX ABI
81 ; zero-extends i16 return values to i32, so the final truncation doesn't appear
83 ; CHECK-LABEL: myctlz_ret16(
84 define i16 @myctlz_ret16(i16 %a) {
86 ; CHECK-NEXT: cvt.u32.u16
89 ; CHECK-NEXT: st.param.
91 %val = call i16 @llvm.ctlz.i16(i16 %a, i1 false) readnone
94 ; CHECK-LABEL: myctlz_ret16_2(
95 define i16 @myctlz_ret16_2(i16 %a) {
97 ; CHECK-NEXT: cvt.u32.u16
100 ; CHECK-NEXT: st.param.
102 %val = call i16 @llvm.ctlz.i16(i16 %a, i1 true) readnone
106 ; Here we store the result of ctlz.16 into an i16 pointer, so the trunc should
108 ; CHECK-LABEL: myctlz_store16(
109 define void @myctlz_store16(i16 %a, ptr %b) {
111 ; CHECK-NEXT: cvt.u32.u16
112 ; CHECK-NEXT: clz.b32
113 ; CHECK-DAG: cvt.u16.u32
115 ; CHECK: st.{{[a-z]}}16
117 %val = call i16 @llvm.ctlz.i16(i16 %a, i1 false) readnone
118 store i16 %val, ptr %b
121 ; CHECK-LABEL: myctlz_store16_2(
122 define void @myctlz_store16_2(i16 %a, ptr %b) {
124 ; CHECK-NEXT: cvt.u32.u16
125 ; CHECK-NEXT: clz.b32
126 ; CHECK-DAG: cvt.u16.u32
128 ; CHECK: st.{{[a-z]}}16
130 %val = call i16 @llvm.ctlz.i16(i16 %a, i1 false) readnone
131 store i16 %val, ptr %b