1 ; RUN: opt -S -instcombine < %s | FileCheck %s 2 3 ; CHECK-LABEL: @test_FoldShiftByConstant_CreateSHL 4 ; CHECK: mul <4 x i32> %in, <i32 0, i32 -32, i32 0, i32 -32> 5 ; CHECK-NEXT: ret 6 define <4 x i32> @test_FoldShiftByConstant_CreateSHL(<4 x i32> %in) { 7 %mul.i = mul <4 x i32> %in, <i32 0, i32 -1, i32 0, i32 -1> 8 %vshl_n = shl <4 x i32> %mul.i, <i32 5, i32 5, i32 5, i32 5> 9 ret <4 x i32> %vshl_n 10 } 11 12 ; CHECK-LABEL: @test_FoldShiftByConstant_CreateSHL2 13 ; CHECK: mul <8 x i16> %in, <i16 0, i16 -32, i16 0, i16 -32, i16 0, i16 -32, i16 0, i16 -32> 14 ; CHECK-NEXT: ret 15 define <8 x i16> @test_FoldShiftByConstant_CreateSHL2(<8 x i16> %in) { 16 %mul.i = mul <8 x i16> %in, <i16 0, i16 -1, i16 0, i16 -1, i16 0, i16 -1, i16 0, i16 -1> 17 %vshl_n = shl <8 x i16> %mul.i, <i16 5, i16 5, i16 5, i16 5, i16 5, i16 5, i16 5, i16 5> 18 ret <8 x i16> %vshl_n 19 } 20 21 ; CHECK-LABEL: @test_FoldShiftByConstant_CreateAnd 22 ; CHECK: mul <16 x i8> %in0, <i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33, i8 33> 23 ; CHECK-NEXT: and <16 x i8> %vsra_n2, <i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32, i8 -32> 24 ; CHECK-NEXT: ret 25 define <16 x i8> @test_FoldShiftByConstant_CreateAnd(<16 x i8> %in0) { 26 %vsra_n = ashr <16 x i8> %in0, <i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5> 27 %tmp = add <16 x i8> %in0, %vsra_n 28 %vshl_n = shl <16 x i8> %tmp, <i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5> 29 ret <16 x i8> %vshl_n 30 } 31 32 33 define i32 @bar(i32 %x, i32 %y) { 34 %a = lshr i32 %x, 4 35 %b = add i32 %a, %y 36 %c = shl i32 %b, 4 37 ret i32 %c 38 } 39 40 define <2 x i32> @bar_v2i32(<2 x i32> %x, <2 x i32> %y) { 41 %a = lshr <2 x i32> %x, <i32 5, i32 5> 42 %b = add <2 x i32> %a, %y 43 %c = shl <2 x i32> %b, <i32 5, i32 5> 44 ret <2 x i32> %c 45 } 46 47 48 49 50 define i32 @foo(i32 %x, i32 %y) { 51 %a = lshr i32 %x, 4 52 %b = and i32 %a, 8 53 %c = add i32 %b, %y 54 %d = shl i32 %c, 4 55 ret i32 %d 56 } 57 58 define <2 x i32> @foo_v2i32(<2 x i32> %x, <2 x i32> %y) { 59 %a = lshr <2 x i32> %x, <i32 4, i32 4> 60 %b = and <2 x i32> %a, <i32 8, i32 8> 61 %c = add <2 x i32> %b, %y 62 %d = shl <2 x i32> %c, <i32 4, i32 4> 63 ret <2 x i32> %d 64 } 65 66 67 68