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 triple = "wasm32-unknown-unknown" 70d7286a6SThomas Lively 80d7286a6SThomas Lively;; TODO: Optimize this further by scalarizing the add 90d7286a6SThomas Lively 100d7286a6SThomas Lively; CHECK-LABEL: shl_add: 110d7286a6SThomas Lively; CHECK-NEXT: .functype shl_add (v128, i32, i32) -> (v128) 120d7286a6SThomas Lively; CHECK-NEXT: i8x16.splat $push1=, $1 130d7286a6SThomas Lively; CHECK-NEXT: i8x16.splat $push0=, $2 140d7286a6SThomas Lively; CHECK-NEXT: i8x16.add $push2=, $pop1, $pop0 150d7286a6SThomas Lively; CHECK-NEXT: i8x16.extract_lane_u $push3=, $pop2, 0 160d7286a6SThomas Lively; CHECK-NEXT: i8x16.shl $push4=, $0, $pop3 170d7286a6SThomas Lively; CHECK-NEXT: return $pop4 180d7286a6SThomas Livelydefine <16 x i8> @shl_add(<16 x i8> %v, i8 %a, i8 %b) { 190d7286a6SThomas Lively %t1 = insertelement <16 x i8> undef, i8 %a, i32 0 200d7286a6SThomas Lively %va = shufflevector <16 x i8> %t1, <16 x i8> undef, <16 x i32> zeroinitializer 210d7286a6SThomas Lively %t2 = insertelement <16 x i8> undef, i8 %b, i32 0 220d7286a6SThomas Lively %vb = shufflevector <16 x i8> %t2, <16 x i8> undef, <16 x i32> zeroinitializer 230d7286a6SThomas Lively %shift = add <16 x i8> %va, %vb 240d7286a6SThomas Lively %r = shl <16 x i8> %v, %shift 250d7286a6SThomas Lively ret <16 x i8> %r 260d7286a6SThomas Lively} 27043eaa9aSThomas Lively 28043eaa9aSThomas Lively; CHECK-LABEL: shl_abs: 29043eaa9aSThomas Lively; CHECK-NEXT: .functype shl_abs (v128, i32) -> (v128) 30043eaa9aSThomas Lively; CHECK-NEXT: i8x16.splat $push0=, $1 31*b1afa187SSimon Pilgrim; CHECK-NEXT: i8x16.abs $push1=, $pop0 32*b1afa187SSimon Pilgrim; CHECK-NEXT: i8x16.extract_lane_u $push2=, $pop1, 0 33*b1afa187SSimon Pilgrim; CHECK-NEXT: i8x16.shl $push3=, $0, $pop2 34*b1afa187SSimon Pilgrim; CHECK-NEXT: return $pop3 35043eaa9aSThomas Livelydefine <16 x i8> @shl_abs(<16 x i8> %v, i8 %a) { 36043eaa9aSThomas Lively %t1 = insertelement <16 x i8> undef, i8 %a, i32 0 37043eaa9aSThomas Lively %va = shufflevector <16 x i8> %t1, <16 x i8> undef, <16 x i32> zeroinitializer 38043eaa9aSThomas Lively %nva = sub <16 x i8> zeroinitializer, %va 39043eaa9aSThomas Lively %c = icmp sgt <16 x i8> %va, zeroinitializer 40043eaa9aSThomas Lively %shift = select <16 x i1> %c, <16 x i8> %va, <16 x i8> %nva 41043eaa9aSThomas Lively %r = shl <16 x i8> %v, %shift 42043eaa9aSThomas Lively ret <16 x i8> %r 43043eaa9aSThomas Lively} 44043eaa9aSThomas Lively 45043eaa9aSThomas Lively; CHECK-LABEL: shl_abs_add: 46043eaa9aSThomas Lively; CHECK-NEXT: .functype shl_abs_add (v128, i32, i32) -> (v128) 47043eaa9aSThomas Lively; CHECK-NEXT: i8x16.splat $push1=, $1 48043eaa9aSThomas Lively; CHECK-NEXT: i8x16.splat $push0=, $2 49043eaa9aSThomas Lively; CHECK-NEXT: i8x16.add $push2=, $pop1, $pop0 50a781a706SThomas Lively; CHECK-NEXT: i8x16.shuffle $push3=, $pop2, $0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 51*b1afa187SSimon Pilgrim; CHECK-NEXT: i8x16.abs $push4=, $pop3 52*b1afa187SSimon Pilgrim; CHECK-NEXT: i8x16.extract_lane_u $push5=, $pop4, 0 53*b1afa187SSimon Pilgrim; CHECK-NEXT: i8x16.shl $push6=, $0, $pop5 54*b1afa187SSimon Pilgrim; CHECK-NEXT: return $pop6 55043eaa9aSThomas Livelydefine <16 x i8> @shl_abs_add(<16 x i8> %v, i8 %a, i8 %b) { 56043eaa9aSThomas Lively %t1 = insertelement <16 x i8> undef, i8 %a, i32 0 57043eaa9aSThomas Lively %va = shufflevector <16 x i8> %t1, <16 x i8> undef, <16 x i32> zeroinitializer 58043eaa9aSThomas Lively %t2 = insertelement <16 x i8> undef, i8 %b, i32 0 59043eaa9aSThomas Lively %vb = shufflevector <16 x i8> %t2, <16 x i8> undef, <16 x i32> zeroinitializer 60043eaa9aSThomas Lively %vadd = add <16 x i8> %va, %vb 61043eaa9aSThomas Lively %nvadd = sub <16 x i8> zeroinitializer, %vadd 62043eaa9aSThomas Lively %c = icmp sgt <16 x i8> %vadd, zeroinitializer 63043eaa9aSThomas Lively %shift = select <16 x i1> %c, <16 x i8> %vadd, <16 x i8> %nvadd 64043eaa9aSThomas Lively %r = shl <16 x i8> %v, %shift 65043eaa9aSThomas Lively ret <16 x i8> %r 66043eaa9aSThomas Lively} 67