1 ; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+simd128 | FileCheck %s
3 ; Test that SIMD shifts can be lowered correctly even with shift
4 ; values that are more complex than plain splats.
6 target triple = "wasm32-unknown-unknown"
8 ;; TODO: Optimize this further by scalarizing the add
10 ; CHECK-LABEL: shl_add:
11 ; CHECK-NEXT: .functype shl_add (v128, i32, i32) -> (v128)
12 ; CHECK-NEXT: i8x16.splat $push1=, $1
13 ; CHECK-NEXT: i8x16.splat $push0=, $2
14 ; CHECK-NEXT: i8x16.add $push2=, $pop1, $pop0
15 ; CHECK-NEXT: i8x16.extract_lane_u $push3=, $pop2, 0
16 ; CHECK-NEXT: i8x16.shl $push4=, $0, $pop3
17 ; CHECK-NEXT: return $pop4
18 define <16 x i8> @shl_add(<16 x i8> %v, i8 %a, i8 %b) {
19 %t1 = insertelement <16 x i8> undef, i8 %a, i32 0
20 %va = shufflevector <16 x i8> %t1, <16 x i8> undef, <16 x i32> zeroinitializer
21 %t2 = insertelement <16 x i8> undef, i8 %b, i32 0
22 %vb = shufflevector <16 x i8> %t2, <16 x i8> undef, <16 x i32> zeroinitializer
23 %shift = add <16 x i8> %va, %vb
24 %r = shl <16 x i8> %v, %shift
28 ; CHECK-LABEL: shl_abs:
29 ; CHECK-NEXT: .functype shl_abs (v128, i32) -> (v128)
30 ; CHECK-NEXT: i8x16.splat $push0=, $1
31 ; CHECK-NEXT: i8x16.abs $push1=, $pop0
32 ; CHECK-NEXT: i8x16.extract_lane_u $push2=, $pop1, 0
33 ; CHECK-NEXT: i8x16.shl $push3=, $0, $pop2
34 ; CHECK-NEXT: return $pop3
35 define <16 x i8> @shl_abs(<16 x i8> %v, i8 %a) {
36 %t1 = insertelement <16 x i8> undef, i8 %a, i32 0
37 %va = shufflevector <16 x i8> %t1, <16 x i8> undef, <16 x i32> zeroinitializer
38 %nva = sub <16 x i8> zeroinitializer, %va
39 %c = icmp sgt <16 x i8> %va, zeroinitializer
40 %shift = select <16 x i1> %c, <16 x i8> %va, <16 x i8> %nva
41 %r = shl <16 x i8> %v, %shift
45 ; CHECK-LABEL: shl_abs_add:
46 ; CHECK-NEXT: .functype shl_abs_add (v128, i32, i32) -> (v128)
47 ; CHECK-NEXT: i8x16.splat $push1=, $1
48 ; CHECK-NEXT: i8x16.splat $push0=, $2
49 ; CHECK-NEXT: i8x16.add $push2=, $pop1, $pop0
50 ; CHECK-NEXT: i8x16.abs $push3=, $pop2
51 ; CHECK-NEXT: i8x16.extract_lane_u $push4=, $pop3, 0
52 ; CHECK-NEXT: i8x16.shl $push5=, $0, $pop4
53 ; CHECK-NEXT: return $pop5
54 define <16 x i8> @shl_abs_add(<16 x i8> %v, i8 %a, i8 %b) {
55 %t1 = insertelement <16 x i8> undef, i8 %a, i32 0
56 %va = shufflevector <16 x i8> %t1, <16 x i8> undef, <16 x i32> zeroinitializer
57 %t2 = insertelement <16 x i8> undef, i8 %b, i32 0
58 %vb = shufflevector <16 x i8> %t2, <16 x i8> undef, <16 x i32> zeroinitializer
59 %vadd = add <16 x i8> %va, %vb
60 %nvadd = sub <16 x i8> zeroinitializer, %vadd
61 %c = icmp sgt <16 x i8> %vadd, zeroinitializer
62 %shift = select <16 x i1> %c, <16 x i8> %vadd, <16 x i8> %nvadd
63 %r = shl <16 x i8> %v, %shift