10d7286a6SThomas Lively; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+simd128 | FileCheck %s
20d7286a6SThomas Lively
30d7286a6SThomas Lively; Test that SIMD shifts can be lowered correctly even with shift
40d7286a6SThomas Lively; values that are more complex than plain splats.
50d7286a6SThomas Lively
60d7286a6SThomas Livelytarget datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
70d7286a6SThomas Livelytarget triple = "wasm32-unknown-unknown"
80d7286a6SThomas Lively
90d7286a6SThomas Lively;; TODO: Optimize this further by scalarizing the add
100d7286a6SThomas Lively
110d7286a6SThomas Lively; CHECK-LABEL: shl_add:
120d7286a6SThomas Lively; CHECK-NEXT: .functype shl_add (v128, i32, i32) -> (v128)
130d7286a6SThomas Lively; CHECK-NEXT: i8x16.splat $push1=, $1
140d7286a6SThomas Lively; CHECK-NEXT: i8x16.splat $push0=, $2
150d7286a6SThomas Lively; CHECK-NEXT: i8x16.add $push2=, $pop1, $pop0
160d7286a6SThomas Lively; CHECK-NEXT: i8x16.extract_lane_u $push3=, $pop2, 0
170d7286a6SThomas Lively; CHECK-NEXT: i8x16.shl $push4=, $0, $pop3
180d7286a6SThomas Lively; CHECK-NEXT: return $pop4
190d7286a6SThomas Livelydefine <16 x i8> @shl_add(<16 x i8> %v, i8 %a, i8 %b) {
200d7286a6SThomas Lively  %t1 = insertelement <16 x i8> undef, i8 %a, i32 0
210d7286a6SThomas Lively  %va = shufflevector <16 x i8> %t1, <16 x i8> undef, <16 x i32> zeroinitializer
220d7286a6SThomas Lively  %t2 = insertelement <16 x i8> undef, i8 %b, i32 0
230d7286a6SThomas Lively  %vb = shufflevector <16 x i8> %t2, <16 x i8> undef, <16 x i32> zeroinitializer
240d7286a6SThomas Lively  %shift = add <16 x i8> %va, %vb
250d7286a6SThomas Lively  %r = shl <16 x i8> %v, %shift
260d7286a6SThomas Lively  ret <16 x i8> %r
270d7286a6SThomas Lively}
28043eaa9aSThomas Lively
29043eaa9aSThomas Lively; CHECK-LABEL: shl_abs:
30043eaa9aSThomas Lively; CHECK-NEXT: .functype shl_abs (v128, i32) -> (v128)
31043eaa9aSThomas Lively; CHECK-NEXT: i8x16.splat $push0=, $1
32*b1afa187SSimon Pilgrim; CHECK-NEXT: i8x16.abs $push1=, $pop0
33*b1afa187SSimon Pilgrim; CHECK-NEXT: i8x16.extract_lane_u $push2=, $pop1, 0
34*b1afa187SSimon Pilgrim; CHECK-NEXT: i8x16.shl $push3=, $0, $pop2
35*b1afa187SSimon Pilgrim; CHECK-NEXT: return $pop3
36043eaa9aSThomas Livelydefine <16 x i8> @shl_abs(<16 x i8> %v, i8 %a) {
37043eaa9aSThomas Lively  %t1 = insertelement <16 x i8> undef, i8 %a, i32 0
38043eaa9aSThomas Lively  %va = shufflevector <16 x i8> %t1, <16 x i8> undef, <16 x i32> zeroinitializer
39043eaa9aSThomas Lively  %nva = sub <16 x i8> zeroinitializer, %va
40043eaa9aSThomas Lively  %c = icmp sgt <16 x i8> %va, zeroinitializer
41043eaa9aSThomas Lively  %shift = select <16 x i1> %c, <16 x i8> %va, <16 x i8> %nva
42043eaa9aSThomas Lively  %r = shl <16 x i8> %v, %shift
43043eaa9aSThomas Lively  ret <16 x i8> %r
44043eaa9aSThomas Lively}
45043eaa9aSThomas Lively
46043eaa9aSThomas Lively; CHECK-LABEL: shl_abs_add:
47043eaa9aSThomas Lively; CHECK-NEXT: .functype shl_abs_add (v128, i32, i32) -> (v128)
48043eaa9aSThomas Lively; CHECK-NEXT: i8x16.splat $push1=, $1
49043eaa9aSThomas Lively; CHECK-NEXT: i8x16.splat $push0=, $2
50043eaa9aSThomas Lively; CHECK-NEXT: i8x16.add $push2=, $pop1, $pop0
51a781a706SThomas Lively; CHECK-NEXT: i8x16.shuffle $push3=, $pop2, $0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
52*b1afa187SSimon Pilgrim; CHECK-NEXT: i8x16.abs $push4=, $pop3
53*b1afa187SSimon Pilgrim; CHECK-NEXT: i8x16.extract_lane_u $push5=, $pop4, 0
54*b1afa187SSimon Pilgrim; CHECK-NEXT: i8x16.shl $push6=, $0, $pop5
55*b1afa187SSimon Pilgrim; CHECK-NEXT: return $pop6
56043eaa9aSThomas Livelydefine <16 x i8> @shl_abs_add(<16 x i8> %v, i8 %a, i8 %b) {
57043eaa9aSThomas Lively  %t1 = insertelement <16 x i8> undef, i8 %a, i32 0
58043eaa9aSThomas Lively  %va = shufflevector <16 x i8> %t1, <16 x i8> undef, <16 x i32> zeroinitializer
59043eaa9aSThomas Lively  %t2 = insertelement <16 x i8> undef, i8 %b, i32 0
60043eaa9aSThomas Lively  %vb = shufflevector <16 x i8> %t2, <16 x i8> undef, <16 x i32> zeroinitializer
61043eaa9aSThomas Lively  %vadd = add <16 x i8> %va, %vb
62043eaa9aSThomas Lively  %nvadd = sub <16 x i8> zeroinitializer, %vadd
63043eaa9aSThomas Lively  %c = icmp sgt <16 x i8> %vadd, zeroinitializer
64043eaa9aSThomas Lively  %shift = select <16 x i1> %c, <16 x i8> %vadd, <16 x i8> %nvadd
65043eaa9aSThomas Lively  %r = shl <16 x i8> %v, %shift
66043eaa9aSThomas Lively  ret <16 x i8> %r
67043eaa9aSThomas Lively}
68