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 3 4; Test that wasm select instruction is selected from LLVM select instruction. 5 6target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" 7target triple = "wasm32-unknown-unknown" 8 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{{$}} 13define i32 @select_i32_bool(i1 zeroext %a, i32 %b, i32 %c) { 14 %cond = select i1 %a, i32 %b, i32 %c 15 ret i32 %cond 16} 17 18; CHECK-LABEL: select_i32_bool_nozext: 19; CHECK-NEXT: .functype select_i32_bool_nozext (i32, i32, i32) -> (i32){{$}} 20; CHECK-NEXT: i32.const $push0=, 1{{$}} 21; CHECK-NEXT: i32.and $push1=, $0, $pop0{{$}} 22; CHECK-NEXT: i32.select $push2=, $1, $2, $pop1{{$}} 23; CHECK-NEXT: return $pop2{{$}} 24define i32 @select_i32_bool_nozext(i1 %a, i32 %b, i32 %c) { 25 %cond = select i1 %a, i32 %b, i32 %c 26 ret i32 %cond 27} 28 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{{$}} 33define 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 36 ret i32 %cond 37} 38 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{{$}} 43define 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 46 ret i32 %cond 47} 48 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{{$}} 53define i64 @select_i64_bool(i1 zeroext %a, i64 %b, i64 %c) { 54 %cond = select i1 %a, i64 %b, i64 %c 55 ret i64 %cond 56} 57 58; CHECK-LABEL: select_i64_bool_nozext: 59; CHECK-NEXT: .functype select_i64_bool_nozext (i32, i64, i64) -> (i64){{$}} 60; CHECK-NEXT: i32.const $push0=, 1{{$}} 61; CHECK-NEXT: i32.and $push1=, $0, $pop0{{$}} 62; CHECK-NEXT: i64.select $push2=, $1, $2, $pop1{{$}} 63; CHECK-NEXT: return $pop2{{$}} 64define i64 @select_i64_bool_nozext(i1 %a, i64 %b, i64 %c) { 65 %cond = select i1 %a, i64 %b, i64 %c 66 ret i64 %cond 67} 68 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{{$}} 73define 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 76 ret i64 %cond 77} 78 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{{$}} 83define 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 86 ret i64 %cond 87} 88 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{{$}} 93define float @select_f32_bool(i1 zeroext %a, float %b, float %c) { 94 %cond = select i1 %a, float %b, float %c 95 ret float %cond 96} 97 98; CHECK-LABEL: select_f32_bool_nozext: 99; CHECK-NEXT: .functype select_f32_bool_nozext (i32, f32, f32) -> (f32){{$}} 100; CHECK-NEXT: i32.const $push0=, 1{{$}} 101; CHECK-NEXT: i32.and $push1=, $0, $pop0{{$}} 102; CHECK-NEXT: f32.select $push2=, $1, $2, $pop1{{$}} 103; CHECK-NEXT: return $pop2{{$}} 104define float @select_f32_bool_nozext(i1 %a, float %b, float %c) { 105 %cond = select i1 %a, float %b, float %c 106 ret float %cond 107} 108 109; CHECK-LABEL: select_f32_eq: 110; CHECK-NEXT: .functype select_f32_eq (i32, f32, f32) -> (f32){{$}} 111; CHECK-NEXT: f32.select $push0=, $2, $1, $0{{$}} 112; CHECK-NEXT: return $pop0{{$}} 113define float @select_f32_eq(i32 %a, float %b, float %c) { 114 %cmp = icmp eq i32 %a, 0 115 %cond = select i1 %cmp, float %b, float %c 116 ret float %cond 117} 118 119; CHECK-LABEL: select_f32_ne: 120; CHECK-NEXT: .functype select_f32_ne (i32, f32, f32) -> (f32){{$}} 121; CHECK-NEXT: f32.select $push0=, $1, $2, $0{{$}} 122; CHECK-NEXT: return $pop0{{$}} 123define float @select_f32_ne(i32 %a, float %b, float %c) { 124 %cmp = icmp ne i32 %a, 0 125 %cond = select i1 %cmp, float %b, float %c 126 ret float %cond 127} 128 129; CHECK-LABEL: select_f64_bool: 130; CHECK-NEXT: .functype select_f64_bool (i32, f64, f64) -> (f64){{$}} 131; CHECK-NEXT: f64.select $push0=, $1, $2, $0{{$}} 132; CHECK-NEXT: return $pop0{{$}} 133define double @select_f64_bool(i1 zeroext %a, double %b, double %c) { 134 %cond = select i1 %a, double %b, double %c 135 ret double %cond 136} 137 138; CHECK-LABEL: select_f64_bool_nozext: 139; CHECK-NEXT: .functype select_f64_bool_nozext (i32, f64, f64) -> (f64){{$}} 140; CHECK-NEXT: i32.const $push0=, 1{{$}} 141; CHECK-NEXT: i32.and $push1=, $0, $pop0{{$}} 142; CHECK-NEXT: f64.select $push2=, $1, $2, $pop1{{$}} 143; CHECK-NEXT: return $pop2{{$}} 144define double @select_f64_bool_nozext(i1 %a, double %b, double %c) { 145 %cond = select i1 %a, double %b, double %c 146 ret double %cond 147} 148 149; CHECK-LABEL: select_f64_eq: 150; CHECK-NEXT: .functype select_f64_eq (i32, f64, f64) -> (f64){{$}} 151; CHECK-NEXT: f64.select $push0=, $2, $1, $0{{$}} 152; CHECK-NEXT: return $pop0{{$}} 153define double @select_f64_eq(i32 %a, double %b, double %c) { 154 %cmp = icmp eq i32 %a, 0 155 %cond = select i1 %cmp, double %b, double %c 156 ret double %cond 157} 158 159; CHECK-LABEL: select_f64_ne: 160; CHECK-NEXT: .functype select_f64_ne (i32, f64, f64) -> (f64){{$}} 161; CHECK-NEXT: f64.select $push0=, $1, $2, $0{{$}} 162; CHECK-NEXT: return $pop0{{$}} 163define double @select_f64_ne(i32 %a, double %b, double %c) { 164 %cmp = icmp ne i32 %a, 0 165 %cond = select i1 %cmp, double %b, double %c 166 ret double %cond 167} 168 169; CHECK-LABEL: pr40805_i32: 170; CHECK-NEXT: .functype pr40805_i32 (i32, i32, i32) -> (i32){{$}} 171; SLOW-NEXT: i32.const $push0=, 1{{$}} 172; SLOW-NEXT: i32.and $push1=, $0, $pop0{{$}} 173; SLOW-NEXT: i32.select $push2=, $1, $2, $pop1{{$}} 174; SLOW-NEXT: return $pop2{{$}} 175define i32 @pr40805_i32(i32 %x, i32 %y, i32 %z) { 176 %a = and i32 %x, 1 177 %b = icmp ne i32 %a, 0 178 %c = select i1 %b, i32 %y, i32 %z 179 ret i32 %c 180} 181 182; CHECK-LABEL: pr40805_i64: 183; CHECK-NEXT: .functype pr40805_i64 (i64, i64, i64) -> (i64){{$}} 184; SLOW-NEXT: i32.wrap_i64 $push0=, $0{{$}} 185; SLOW-NEXT: i32.const $push1=, 1{{$}} 186; SLOW-NEXT: i32.and $push2=, $pop0, $pop1{{$}} 187; SLOW-NEXT: i64.select $push3=, $1, $2, $pop2{{$}} 188; SLOW-NEXT: return $pop3{{$}} 189define i64 @pr40805_i64(i64 %x, i64 %y, i64 %z) { 190 %a = and i64 %x, 1 191 %b = icmp ne i64 %a, 0 192 %c = select i1 %b, i64 %y, i64 %z 193 ret i64 %c 194} 195 196; CHECK-LABEL: pr44012_i32: 197; CHECK-NEXT: .functype pr44012_i32 (i32, f32, f32) -> (f32){{$}} 198; SLOW-NEXT: i32.const $push0=, 1{{$}} 199; SLOW-NEXT: i32.and $push1=, $0, $pop0{{$}} 200; SLOW-NEXT: f32.select $push2=, $1, $2, $pop1{{$}} 201; SLOW-NEXT: return $pop2{{$}} 202define float @pr44012_i32(i32 %x, float %y, float %z) { 203 %a = and i32 %x, 1 204 %b = icmp ne i32 %a, 0 205 %c = select i1 %b, float %y, float %z 206 ret float %c 207} 208 209; CHECK-LABEL: pr44012_i64: 210; CHECK-NEXT: .functype pr44012_i64 (i64, f32, f32) -> (f32){{$}} 211; SLOW-NEXT: i32.wrap_i64 $push0=, $0{{$}} 212; SLOW-NEXT: i32.const $push1=, 1{{$}} 213; SLOW-NEXT: i32.and $push2=, $pop0, $pop1{{$}} 214; SLOW-NEXT: f32.select $push3=, $1, $2, $pop2{{$}} 215; SLOW-NEXT: return $pop3{{$}} 216define float @pr44012_i64(i64 %x, float %y, float %z) { 217 %a = and i64 %x, 1 218 %b = icmp ne i64 %a, 0 219 %c = select i1 %b, float %y, float %z 220 ret float %c 221} 222