1 ; Check that various LLVM idioms get lowered to NVPTX as expected.
3 ; RUN: llc < %s -march=nvptx -mcpu=sm_20 | FileCheck %s
4 ; RUN: llc < %s -march=nvptx64 -mcpu=sm_20 | FileCheck %s
5 ; RUN: %if ptxas && !ptxas-12.0 %{ llc < %s -march=nvptx -mcpu=sm_20 | %ptxas-verify %}
6 ; RUN: %if ptxas %{ llc < %s -march=nvptx64 -mcpu=sm_20 | %ptxas-verify %}
8 %struct.S16 = type { i16, i16 }
9 %struct.S32 = type { i32, i32 }
11 ; CHECK-LABEL: abs_i16(
12 define i16 @abs_i16(i16 %a) {
15 %abs.cond = icmp sge i16 %a, 0
16 %abs = select i1 %abs.cond, i16 %a, i16 %neg
20 ; CHECK-LABEL: abs_i32(
21 define i32 @abs_i32(i32 %a) {
24 %abs.cond = icmp sge i32 %a, 0
25 %abs = select i1 %abs.cond, i32 %a, i32 %neg
29 ; CHECK-LABEL: abs_i64(
30 define i64 @abs_i64(i64 %a) {
33 %abs.cond = icmp sge i64 %a, 0
34 %abs = select i1 %abs.cond, i64 %a, i64 %neg
38 ; CHECK-LABEL: i32_to_2xi16(
39 define %struct.S16 @i32_to_2xi16(i32 noundef %in) {
40 %low = trunc i32 %in to i16
41 %high32 = lshr i32 %in, 16
42 %high = trunc i32 %high32 to i16
43 ; CHECK: ld.param.u32 %[[R32:r[0-9]+]], [i32_to_2xi16_param_0];
44 ; CHECK-DAG: cvt.u16.u32 %rs{{[0-9+]}}, %[[R32]];
45 ; CHECK-DAG mov.b32 {tmp, %rs{{[0-9+]}}}, %[[R32]];
46 %s1 = insertvalue %struct.S16 poison, i16 %low, 0
47 %s = insertvalue %struct.S16 %s1, i16 %high, 1
51 ; CHECK-LABEL: i32_to_2xi16_lh(
52 ; Same as above, but with rearranged order of low/high parts.
53 define %struct.S16 @i32_to_2xi16_lh(i32 noundef %in) {
54 %high32 = lshr i32 %in, 16
55 %high = trunc i32 %high32 to i16
56 %low = trunc i32 %in to i16
57 ; CHECK: ld.param.u32 %[[R32:r[0-9]+]], [i32_to_2xi16_lh_param_0];
58 ; CHECK-DAG: cvt.u16.u32 %rs{{[0-9+]}}, %[[R32]];
59 ; CHECK-DAG mov.b32 {tmp, %rs{{[0-9+]}}}, %[[R32]];
60 %s1 = insertvalue %struct.S16 poison, i16 %low, 0
61 %s = insertvalue %struct.S16 %s1, i16 %high, 1
66 ; CHECK-LABEL: i32_to_2xi16_not(
67 define %struct.S16 @i32_to_2xi16_not(i32 noundef %in) {
68 %low = trunc i32 %in to i16
69 ; Shift by any value other than 16 blocks the conversiopn to mov.
70 %high32 = lshr i32 %in, 15
71 %high = trunc i32 %high32 to i16
75 %s1 = insertvalue %struct.S16 poison, i16 %low, 0
76 %s = insertvalue %struct.S16 %s1, i16 %high, 1
80 ; CHECK-LABEL: i64_to_2xi32(
81 define %struct.S32 @i64_to_2xi32(i64 noundef %in) {
82 %low = trunc i64 %in to i32
83 %high64 = lshr i64 %in, 32
84 %high = trunc i64 %high64 to i32
85 ; CHECK: ld.param.u64 %[[R64:rd[0-9]+]], [i64_to_2xi32_param_0];
86 ; CHECK-DAG: cvt.u32.u64 %r{{[0-9+]}}, %[[R64]];
87 ; CHECK-DAG mov.b64 {tmp, %r{{[0-9+]}}}, %[[R64]];
88 %s1 = insertvalue %struct.S32 poison, i32 %low, 0
89 %s = insertvalue %struct.S32 %s1, i32 %high, 1
93 ; CHECK-LABEL: i64_to_2xi32_not(
94 define %struct.S32 @i64_to_2xi32_not(i64 noundef %in) {
95 %low = trunc i64 %in to i32
96 ; Shift by any value other than 32 blocks the conversiopn to mov.
97 %high64 = lshr i64 %in, 31
98 %high = trunc i64 %high64 to i32
102 %s1 = insertvalue %struct.S32 poison, i32 %low, 0
103 %s = insertvalue %struct.S32 %s1, i32 %high, 1
107 ; CHECK-LABEL: i32_to_2xi16_shr(
108 ; Make sure we do not get confused when our input itself is [al]shr.
109 define %struct.S16 @i32_to_2xi16_shr(i32 noundef %i){
110 call void @escape_int(i32 %i); // Force %i to be loaded completely.
111 %i1 = ashr i32 %i, 16
112 %l = trunc i32 %i1 to i16
113 %h32 = ashr i32 %i1, 16
114 %h = trunc i32 %h32 to i16
115 ; CHECK: ld.param.u32 %[[R32:r[0-9]+]], [i32_to_2xi16_shr_param_0];
116 ; CHECK: shr.s32 %[[R32H:r[0-9]+]], %[[R32]], 16;
117 ; CHECK-DAG mov.b32 {tmp, %rs{{[0-9+]}}}, %[[R32]];
118 ; CHECK-DAG mov.b32 {tmp, %rs{{[0-9+]}}}, %[[R32H]];
119 %s0 = insertvalue %struct.S16 poison, i16 %l, 0
120 %s1 = insertvalue %struct.S16 %s0, i16 %h, 1
123 declare dso_local void @escape_int(i32 noundef)