1 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s --check-prefixes CHECK,SLOW
2 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -fast-isel -fast-isel-abort=1 | FileCheck %s
4 ; Test that wasm select instruction is selected from LLVM select instruction.
6 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
7 target triple = "wasm32-unknown-unknown"
9 ; CHECK-LABEL: select_i32_bool:
10 ; CHECK-NEXT: .functype select_i32_bool (i32, i32, i32) -> (i32){{$}}
11 ; CHECK-NEXT: i32.select $push0=, $1, $2, $0{{$}}
12 ; CHECK-NEXT: return $pop0{{$}}
13 define i32 @select_i32_bool(i1 zeroext %a, i32 %b, i32 %c) {
14 %cond = select i1 %a, i32 %b, i32 %c
18 ; CHECK-LABEL: select_i32_bool_nozext:
19 ; CHECK-NEXT: .functype select_i32_bool_nozext (i32, i32, i32) -> (i32){{$}}
20 ; SLOW-NEXT: i32.const $push0=, 1{{$}}
21 ; SLOW-NEXT: i32.and $push1=, $0, $pop0{{$}}
22 ; SLOW-NEXT: i32.select $push2=, $1, $2, $pop1{{$}}
23 ; SLOW-NEXT: return $pop2{{$}}
24 define i32 @select_i32_bool_nozext(i1 %a, i32 %b, i32 %c) {
25 %cond = select i1 %a, i32 %b, i32 %c
29 ; CHECK-LABEL: select_i32_eq:
30 ; CHECK-NEXT: .functype select_i32_eq (i32, i32, i32) -> (i32){{$}}
31 ; CHECK-NEXT: i32.select $push0=, $2, $1, $0{{$}}
32 ; CHECK-NEXT: return $pop0{{$}}
33 define i32 @select_i32_eq(i32 %a, i32 %b, i32 %c) {
34 %cmp = icmp eq i32 %a, 0
35 %cond = select i1 %cmp, i32 %b, i32 %c
39 ; CHECK-LABEL: select_i32_ne:
40 ; CHECK-NEXT: .functype select_i32_ne (i32, i32, i32) -> (i32){{$}}
41 ; CHECK-NEXT: i32.select $push0=, $1, $2, $0{{$}}
42 ; CHECK-NEXT: return $pop0{{$}}
43 define i32 @select_i32_ne(i32 %a, i32 %b, i32 %c) {
44 %cmp = icmp ne i32 %a, 0
45 %cond = select i1 %cmp, i32 %b, i32 %c
49 ; CHECK-LABEL: select_i64_bool:
50 ; CHECK-NEXT: .functype select_i64_bool (i32, i64, i64) -> (i64){{$}}
51 ; CHECK-NEXT: i64.select $push0=, $1, $2, $0{{$}}
52 ; CHECK-NEXT: return $pop0{{$}}
53 define i64 @select_i64_bool(i1 zeroext %a, i64 %b, i64 %c) {
54 %cond = select i1 %a, i64 %b, i64 %c
58 ; CHECK-LABEL: select_i64_bool_nozext:
59 ; CHECK-NEXT: .functype select_i64_bool_nozext (i32, i64, i64) -> (i64){{$}}
60 ; SLOW-NEXT: i32.const $push0=, 1{{$}}
61 ; SLOW-NEXT: i32.and $push1=, $0, $pop0{{$}}
62 ; SLOW-NEXT: i64.select $push2=, $1, $2, $pop1{{$}}
63 ; SLOW-NEXT: return $pop2{{$}}
64 define i64 @select_i64_bool_nozext(i1 %a, i64 %b, i64 %c) {
65 %cond = select i1 %a, i64 %b, i64 %c
69 ; CHECK-LABEL: select_i64_eq:
70 ; CHECK-NEXT: .functype select_i64_eq (i32, i64, i64) -> (i64){{$}}
71 ; CHECK-NEXT: i64.select $push0=, $2, $1, $0{{$}}
72 ; CHECK-NEXT: return $pop0{{$}}
73 define i64 @select_i64_eq(i32 %a, i64 %b, i64 %c) {
74 %cmp = icmp eq i32 %a, 0
75 %cond = select i1 %cmp, i64 %b, i64 %c
79 ; CHECK-LABEL: select_i64_ne:
80 ; CHECK-NEXT: .functype select_i64_ne (i32, i64, i64) -> (i64){{$}}
81 ; CHECK-NEXT: i64.select $push0=, $1, $2, $0{{$}}
82 ; CHECK-NEXT: return $pop0{{$}}
83 define i64 @select_i64_ne(i32 %a, i64 %b, i64 %c) {
84 %cmp = icmp ne i32 %a, 0
85 %cond = select i1 %cmp, i64 %b, i64 %c
89 ; CHECK-LABEL: select_f32_bool:
90 ; CHECK-NEXT: .functype select_f32_bool (i32, f32, f32) -> (f32){{$}}
91 ; CHECK-NEXT: f32.select $push0=, $1, $2, $0{{$}}
92 ; CHECK-NEXT: return $pop0{{$}}
93 define float @select_f32_bool(i1 zeroext %a, float %b, float %c) {
94 %cond = select i1 %a, float %b, float %c
98 ; CHECK-LABEL: select_f32_bool_nozext:
99 ; CHECK-NEXT: .functype select_f32_bool_nozext (i32, f32, f32) -> (f32){{$}}
100 ; SLOW-NEXT: f32.select $push0=, $1, $2, $0{{$}}
101 ; SLOW-NEXT: return $pop0{{$}}
102 define float @select_f32_bool_nozext(i1 %a, float %b, float %c) {
103 %cond = select i1 %a, float %b, float %c
107 ; CHECK-LABEL: select_f32_eq:
108 ; CHECK-NEXT: .functype select_f32_eq (i32, f32, f32) -> (f32){{$}}
109 ; CHECK-NEXT: f32.select $push0=, $2, $1, $0{{$}}
110 ; CHECK-NEXT: return $pop0{{$}}
111 define float @select_f32_eq(i32 %a, float %b, float %c) {
112 %cmp = icmp eq i32 %a, 0
113 %cond = select i1 %cmp, float %b, float %c
117 ; CHECK-LABEL: select_f32_ne:
118 ; CHECK-NEXT: .functype select_f32_ne (i32, f32, f32) -> (f32){{$}}
119 ; CHECK-NEXT: f32.select $push0=, $1, $2, $0{{$}}
120 ; CHECK-NEXT: return $pop0{{$}}
121 define float @select_f32_ne(i32 %a, float %b, float %c) {
122 %cmp = icmp ne i32 %a, 0
123 %cond = select i1 %cmp, float %b, float %c
127 ; CHECK-LABEL: select_f64_bool:
128 ; CHECK-NEXT: .functype select_f64_bool (i32, f64, f64) -> (f64){{$}}
129 ; CHECK-NEXT: f64.select $push0=, $1, $2, $0{{$}}
130 ; CHECK-NEXT: return $pop0{{$}}
131 define double @select_f64_bool(i1 zeroext %a, double %b, double %c) {
132 %cond = select i1 %a, double %b, double %c
136 ; CHECK-LABEL: select_f64_bool_nozext:
137 ; CHECK-NEXT: .functype select_f64_bool_nozext (i32, f64, f64) -> (f64){{$}}
138 ; SLOW-NEXT: f64.select $push0=, $1, $2, $0{{$}}
139 ; SLOW-NEXT: return $pop0{{$}}
140 define double @select_f64_bool_nozext(i1 %a, double %b, double %c) {
141 %cond = select i1 %a, double %b, double %c
145 ; CHECK-LABEL: select_f64_eq:
146 ; CHECK-NEXT: .functype select_f64_eq (i32, f64, f64) -> (f64){{$}}
147 ; CHECK-NEXT: f64.select $push0=, $2, $1, $0{{$}}
148 ; CHECK-NEXT: return $pop0{{$}}
149 define double @select_f64_eq(i32 %a, double %b, double %c) {
150 %cmp = icmp eq i32 %a, 0
151 %cond = select i1 %cmp, double %b, double %c
155 ; CHECK-LABEL: select_f64_ne:
156 ; CHECK-NEXT: .functype select_f64_ne (i32, f64, f64) -> (f64){{$}}
157 ; CHECK-NEXT: f64.select $push0=, $1, $2, $0{{$}}
158 ; CHECK-NEXT: return $pop0{{$}}
159 define double @select_f64_ne(i32 %a, double %b, double %c) {
160 %cmp = icmp ne i32 %a, 0
161 %cond = select i1 %cmp, double %b, double %c
165 ; CHECK-LABEL: pr40805:
166 ; CHECK-NEXT: .functype pr40805 (i32, i32, i32) -> (i32){{$}}
167 ; SLOW-NEXT: i32.const $push0=, 1{{$}}
168 ; SLOW-NEXT: i32.and $push1=, $0, $pop0{{$}}
169 ; SLOW-NEXT: i32.select $push2=, $1, $2, $pop1{{$}}
170 ; SLOW-NEXT: return $pop2{{$}}
171 define i32 @pr40805(i32 %x, i32 %y, i32 %z) {
173 %b = icmp ne i32 %a, 0
174 %c = select i1 %b, i32 %y, i32 %z