| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408 |
- ; RUN: opt < %s -instcombine -S | FileCheck %s
- ; Check that instcombine rewrites multiply by a vector
- ; of known constant power-of-2 elements with vector shift.
- define <4 x i8> @Zero_i8(<4 x i8> %InVec) {
- entry:
- %mul = mul <4 x i8> %InVec, <i8 0, i8 0, i8 0, i8 0>
- ret <4 x i8> %mul
- }
- ; CHECK-LABEL: @Zero_i8(
- ; CHECK: ret <4 x i8> zeroinitializer
- define <4 x i8> @Identity_i8(<4 x i8> %InVec) {
- entry:
- %mul = mul <4 x i8> %InVec, <i8 1, i8 1, i8 1, i8 1>
- ret <4 x i8> %mul
- }
- ; CHECK-LABEL: @Identity_i8(
- ; CHECK: ret <4 x i8> %InVec
- define <4 x i8> @AddToSelf_i8(<4 x i8> %InVec) {
- entry:
- %mul = mul <4 x i8> %InVec, <i8 2, i8 2, i8 2, i8 2>
- ret <4 x i8> %mul
- }
- ; CHECK-LABEL: @AddToSelf_i8(
- ; CHECK: shl <4 x i8> %InVec, <i8 1, i8 1, i8 1, i8 1>
- ; CHECK: ret
- define <4 x i8> @SplatPow2Test1_i8(<4 x i8> %InVec) {
- entry:
- %mul = mul <4 x i8> %InVec, <i8 4, i8 4, i8 4, i8 4>
- ret <4 x i8> %mul
- }
- ; CHECK-LABEL: @SplatPow2Test1_i8(
- ; CHECK: shl <4 x i8> %InVec, <i8 2, i8 2, i8 2, i8 2>
- ; CHECK: ret
- define <4 x i8> @SplatPow2Test2_i8(<4 x i8> %InVec) {
- entry:
- %mul = mul <4 x i8> %InVec, <i8 8, i8 8, i8 8, i8 8>
- ret <4 x i8> %mul
- }
- ; CHECK-LABEL: @SplatPow2Test2_i8(
- ; CHECK: shl <4 x i8> %InVec, <i8 3, i8 3, i8 3, i8 3>
- ; CHECK: ret
- define <4 x i8> @MulTest1_i8(<4 x i8> %InVec) {
- entry:
- %mul = mul <4 x i8> %InVec, <i8 1, i8 2, i8 4, i8 8>
- ret <4 x i8> %mul
- }
- ; CHECK-LABEL: @MulTest1_i8(
- ; CHECK: shl <4 x i8> %InVec, <i8 0, i8 1, i8 2, i8 3>
- ; CHECK: ret
- define <4 x i8> @MulTest2_i8(<4 x i8> %InVec) {
- entry:
- %mul = mul <4 x i8> %InVec, <i8 3, i8 3, i8 3, i8 3>
- ret <4 x i8> %mul
- }
- ; CHECK-LABEL: @MulTest2_i8(
- ; CHECK: mul <4 x i8> %InVec, <i8 3, i8 3, i8 3, i8 3>
- ; CHECK: ret
- define <4 x i8> @MulTest3_i8(<4 x i8> %InVec) {
- entry:
- %mul = mul <4 x i8> %InVec, <i8 4, i8 4, i8 2, i8 2>
- ret <4 x i8> %mul
- }
- ; CHECK-LABEL: @MulTest3_i8(
- ; CHECK: shl <4 x i8> %InVec, <i8 2, i8 2, i8 1, i8 1>
- ; CHECK: ret
- define <4 x i8> @MulTest4_i8(<4 x i8> %InVec) {
- entry:
- %mul = mul <4 x i8> %InVec, <i8 4, i8 4, i8 0, i8 1>
- ret <4 x i8> %mul
- }
- ; CHECK-LABEL: @MulTest4_i8(
- ; CHECK: mul <4 x i8> %InVec, <i8 4, i8 4, i8 0, i8 1>
- ; CHECK: ret
- define <4 x i16> @Zero_i16(<4 x i16> %InVec) {
- entry:
- %mul = mul <4 x i16> %InVec, <i16 0, i16 0, i16 0, i16 0>
- ret <4 x i16> %mul
- }
- ; CHECK-LABEL: @Zero_i16(
- ; CHECK: ret <4 x i16> zeroinitializer
- define <4 x i16> @Identity_i16(<4 x i16> %InVec) {
- entry:
- %mul = mul <4 x i16> %InVec, <i16 1, i16 1, i16 1, i16 1>
- ret <4 x i16> %mul
- }
- ; CHECK-LABEL: @Identity_i16(
- ; CHECK: ret <4 x i16> %InVec
- define <4 x i16> @AddToSelf_i16(<4 x i16> %InVec) {
- entry:
- %mul = mul <4 x i16> %InVec, <i16 2, i16 2, i16 2, i16 2>
- ret <4 x i16> %mul
- }
- ; CHECK-LABEL: @AddToSelf_i16(
- ; CHECK: shl <4 x i16> %InVec, <i16 1, i16 1, i16 1, i16 1>
- ; CHECK: ret
- define <4 x i16> @SplatPow2Test1_i16(<4 x i16> %InVec) {
- entry:
- %mul = mul <4 x i16> %InVec, <i16 4, i16 4, i16 4, i16 4>
- ret <4 x i16> %mul
- }
- ; CHECK-LABEL: @SplatPow2Test1_i16(
- ; CHECK: shl <4 x i16> %InVec, <i16 2, i16 2, i16 2, i16 2>
- ; CHECK: ret
- define <4 x i16> @SplatPow2Test2_i16(<4 x i16> %InVec) {
- entry:
- %mul = mul <4 x i16> %InVec, <i16 8, i16 8, i16 8, i16 8>
- ret <4 x i16> %mul
- }
- ; CHECK-LABEL: @SplatPow2Test2_i16(
- ; CHECK: shl <4 x i16> %InVec, <i16 3, i16 3, i16 3, i16 3>
- ; CHECK: ret
- define <4 x i16> @MulTest1_i16(<4 x i16> %InVec) {
- entry:
- %mul = mul <4 x i16> %InVec, <i16 1, i16 2, i16 4, i16 8>
- ret <4 x i16> %mul
- }
- ; CHECK-LABEL: @MulTest1_i16(
- ; CHECK: shl <4 x i16> %InVec, <i16 0, i16 1, i16 2, i16 3>
- ; CHECK: ret
- define <4 x i16> @MulTest2_i16(<4 x i16> %InVec) {
- entry:
- %mul = mul <4 x i16> %InVec, <i16 3, i16 3, i16 3, i16 3>
- ret <4 x i16> %mul
- }
- ; CHECK-LABEL: @MulTest2_i16(
- ; CHECK: mul <4 x i16> %InVec, <i16 3, i16 3, i16 3, i16 3>
- ; CHECK: ret
- define <4 x i16> @MulTest3_i16(<4 x i16> %InVec) {
- entry:
- %mul = mul <4 x i16> %InVec, <i16 4, i16 4, i16 2, i16 2>
- ret <4 x i16> %mul
- }
- ; CHECK-LABEL: @MulTest3_i16(
- ; CHECK: shl <4 x i16> %InVec, <i16 2, i16 2, i16 1, i16 1>
- ; CHECK: ret
- define <4 x i16> @MulTest4_i16(<4 x i16> %InVec) {
- entry:
- %mul = mul <4 x i16> %InVec, <i16 4, i16 4, i16 0, i16 2>
- ret <4 x i16> %mul
- }
- ; CHECK-LABEL: @MulTest4_i16(
- ; CHECK: mul <4 x i16> %InVec, <i16 4, i16 4, i16 0, i16 2>
- ; CHECK: ret
- define <4 x i32> @Zero_i32(<4 x i32> %InVec) {
- entry:
- %mul = mul <4 x i32> %InVec, <i32 0, i32 0, i32 0, i32 0>
- ret <4 x i32> %mul
- }
- ; CHECK-LABEL: @Zero_i32(
- ; CHECK: ret <4 x i32> zeroinitializer
- define <4 x i32> @Identity_i32(<4 x i32> %InVec) {
- entry:
- %mul = mul <4 x i32> %InVec, <i32 1, i32 1, i32 1, i32 1>
- ret <4 x i32> %mul
- }
- ; CHECK-LABEL: @Identity_i32(
- ; CHECK: ret <4 x i32> %InVec
- define <4 x i32> @AddToSelf_i32(<4 x i32> %InVec) {
- entry:
- %mul = mul <4 x i32> %InVec, <i32 2, i32 2, i32 2, i32 2>
- ret <4 x i32> %mul
- }
- ; CHECK-LABEL: @AddToSelf_i32(
- ; CHECK: shl <4 x i32> %InVec, <i32 1, i32 1, i32 1, i32 1>
- ; CHECK: ret
- define <4 x i32> @SplatPow2Test1_i32(<4 x i32> %InVec) {
- entry:
- %mul = mul <4 x i32> %InVec, <i32 4, i32 4, i32 4, i32 4>
- ret <4 x i32> %mul
- }
- ; CHECK-LABEL: @SplatPow2Test1_i32(
- ; CHECK: shl <4 x i32> %InVec, <i32 2, i32 2, i32 2, i32 2>
- ; CHECK: ret
- define <4 x i32> @SplatPow2Test2_i32(<4 x i32> %InVec) {
- entry:
- %mul = mul <4 x i32> %InVec, <i32 8, i32 8, i32 8, i32 8>
- ret <4 x i32> %mul
- }
- ; CHECK-LABEL: @SplatPow2Test2_i32(
- ; CHECK: shl <4 x i32> %InVec, <i32 3, i32 3, i32 3, i32 3>
- ; CHECK: ret
- define <4 x i32> @MulTest1_i32(<4 x i32> %InVec) {
- entry:
- %mul = mul <4 x i32> %InVec, <i32 1, i32 2, i32 4, i32 8>
- ret <4 x i32> %mul
- }
- ; CHECK-LABEL: @MulTest1_i32(
- ; CHECK: shl <4 x i32> %InVec, <i32 0, i32 1, i32 2, i32 3>
- ; CHECK: ret
- define <4 x i32> @MulTest2_i32(<4 x i32> %InVec) {
- entry:
- %mul = mul <4 x i32> %InVec, <i32 3, i32 3, i32 3, i32 3>
- ret <4 x i32> %mul
- }
- ; CHECK-LABEL: @MulTest2_i32(
- ; CHECK: mul <4 x i32> %InVec, <i32 3, i32 3, i32 3, i32 3>
- ; CHECK: ret
- define <4 x i32> @MulTest3_i32(<4 x i32> %InVec) {
- entry:
- %mul = mul <4 x i32> %InVec, <i32 4, i32 4, i32 2, i32 2>
- ret <4 x i32> %mul
- }
- ; CHECK-LABEL: @MulTest3_i32(
- ; CHECK: shl <4 x i32> %InVec, <i32 2, i32 2, i32 1, i32 1>
- ; CHECK: ret
- define <4 x i32> @MulTest4_i32(<4 x i32> %InVec) {
- entry:
- %mul = mul <4 x i32> %InVec, <i32 4, i32 4, i32 0, i32 1>
- ret <4 x i32> %mul
- }
- ; CHECK-LABEL: @MulTest4_i32(
- ; CHECK: mul <4 x i32> %InVec, <i32 4, i32 4, i32 0, i32 1>
- ; CHECK: ret
- define <4 x i64> @Zero_i64(<4 x i64> %InVec) {
- entry:
- %mul = mul <4 x i64> %InVec, <i64 0, i64 0, i64 0, i64 0>
- ret <4 x i64> %mul
- }
- ; CHECK-LABEL: @Zero_i64(
- ; CHECK: ret <4 x i64> zeroinitializer
- define <4 x i64> @Identity_i64(<4 x i64> %InVec) {
- entry:
- %mul = mul <4 x i64> %InVec, <i64 1, i64 1, i64 1, i64 1>
- ret <4 x i64> %mul
- }
- ; CHECK-LABEL: @Identity_i64(
- ; CHECK: ret <4 x i64> %InVec
- define <4 x i64> @AddToSelf_i64(<4 x i64> %InVec) {
- entry:
- %mul = mul <4 x i64> %InVec, <i64 2, i64 2, i64 2, i64 2>
- ret <4 x i64> %mul
- }
- ; CHECK-LABEL: @AddToSelf_i64(
- ; CHECK: shl <4 x i64> %InVec, <i64 1, i64 1, i64 1, i64 1>
- ; CHECK: ret
- define <4 x i64> @SplatPow2Test1_i64(<4 x i64> %InVec) {
- entry:
- %mul = mul <4 x i64> %InVec, <i64 4, i64 4, i64 4, i64 4>
- ret <4 x i64> %mul
- }
- ; CHECK-LABEL: @SplatPow2Test1_i64(
- ; CHECK: shl <4 x i64> %InVec, <i64 2, i64 2, i64 2, i64 2>
- ; CHECK: ret
- define <4 x i64> @SplatPow2Test2_i64(<4 x i64> %InVec) {
- entry:
- %mul = mul <4 x i64> %InVec, <i64 8, i64 8, i64 8, i64 8>
- ret <4 x i64> %mul
- }
- ; CHECK-LABEL: @SplatPow2Test2_i64(
- ; CHECK: shl <4 x i64> %InVec, <i64 3, i64 3, i64 3, i64 3>
- ; CHECK: ret
- define <4 x i64> @MulTest1_i64(<4 x i64> %InVec) {
- entry:
- %mul = mul <4 x i64> %InVec, <i64 1, i64 2, i64 4, i64 8>
- ret <4 x i64> %mul
- }
- ; CHECK-LABEL: @MulTest1_i64(
- ; CHECK: shl <4 x i64> %InVec, <i64 0, i64 1, i64 2, i64 3>
- ; CHECK: ret
- define <4 x i64> @MulTest2_i64(<4 x i64> %InVec) {
- entry:
- %mul = mul <4 x i64> %InVec, <i64 3, i64 3, i64 3, i64 3>
- ret <4 x i64> %mul
- }
- ; CHECK-LABEL: @MulTest2_i64(
- ; CHECK: mul <4 x i64> %InVec, <i64 3, i64 3, i64 3, i64 3>
- ; CHECK: ret
- define <4 x i64> @MulTest3_i64(<4 x i64> %InVec) {
- entry:
- %mul = mul <4 x i64> %InVec, <i64 4, i64 4, i64 2, i64 2>
- ret <4 x i64> %mul
- }
- ; CHECK-LABEL: @MulTest3_i64(
- ; CHECK: shl <4 x i64> %InVec, <i64 2, i64 2, i64 1, i64 1>
- ; CHECK: ret
- define <4 x i64> @MulTest4_i64(<4 x i64> %InVec) {
- entry:
- %mul = mul <4 x i64> %InVec, <i64 4, i64 4, i64 0, i64 1>
- ret <4 x i64> %mul
- }
- ; CHECK-LABEL: @MulTest4_i64(
- ; CHECK: mul <4 x i64> %InVec, <i64 4, i64 4, i64 0, i64 1>
- ; CHECK: ret
- ; Test also that the following rewriting rule works with vectors
- ; of integers as well:
- ; ((X << C1)*C2) == (X * (C2 << C1))
- define <4 x i8> @ShiftMulTest1(<4 x i8> %InVec) {
- entry:
- %shl = shl <4 x i8> %InVec, <i8 2, i8 2, i8 2, i8 2>
- %mul = mul <4 x i8> %shl, <i8 3, i8 3, i8 3, i8 3>
- ret <4 x i8> %mul
- }
- ; CHECK-LABEL: @ShiftMulTest1(
- ; CHECK: mul <4 x i8> %InVec, <i8 12, i8 12, i8 12, i8 12>
- ; CHECK: ret
- define <4 x i16> @ShiftMulTest2(<4 x i16> %InVec) {
- entry:
- %shl = shl <4 x i16> %InVec, <i16 2, i16 2, i16 2, i16 2>
- %mul = mul <4 x i16> %shl, <i16 3, i16 3, i16 3, i16 3>
- ret <4 x i16> %mul
- }
- ; CHECK-LABEL: @ShiftMulTest2(
- ; CHECK: mul <4 x i16> %InVec, <i16 12, i16 12, i16 12, i16 12>
- ; CHECK: ret
- define <4 x i32> @ShiftMulTest3(<4 x i32> %InVec) {
- entry:
- %shl = shl <4 x i32> %InVec, <i32 2, i32 2, i32 2, i32 2>
- %mul = mul <4 x i32> %shl, <i32 3, i32 3, i32 3, i32 3>
- ret <4 x i32> %mul
- }
- ; CHECK-LABEL: @ShiftMulTest3(
- ; CHECK: mul <4 x i32> %InVec, <i32 12, i32 12, i32 12, i32 12>
- ; CHECK: ret
- define <4 x i64> @ShiftMulTest4(<4 x i64> %InVec) {
- entry:
- %shl = shl <4 x i64> %InVec, <i64 2, i64 2, i64 2, i64 2>
- %mul = mul <4 x i64> %shl, <i64 3, i64 3, i64 3, i64 3>
- ret <4 x i64> %mul
- }
- ; CHECK-LABEL: @ShiftMulTest4(
- ; CHECK: mul <4 x i64> %InVec, <i64 12, i64 12, i64 12, i64 12>
- ; CHECK: ret
|