; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; 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) { ; CHECK-LABEL: @Zero_i8( ; CHECK-NEXT: entry: ; CHECK-NEXT: ret <4 x i8> zeroinitializer ; entry: %mul = mul <4 x i8> %InVec, ret <4 x i8> %mul } define <4 x i8> @Identity_i8(<4 x i8> %InVec) { ; CHECK-LABEL: @Identity_i8( ; CHECK-NEXT: entry: ; CHECK-NEXT: ret <4 x i8> [[INVEC:%.*]] ; entry: %mul = mul <4 x i8> %InVec, ret <4 x i8> %mul } define <4 x i8> @AddToSelf_i8(<4 x i8> %InVec) { ; CHECK-LABEL: @AddToSelf_i8( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = shl <4 x i8> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i8> [[MUL]] ; entry: %mul = mul <4 x i8> %InVec, ret <4 x i8> %mul } define <4 x i8> @SplatPow2Test1_i8(<4 x i8> %InVec) { ; CHECK-LABEL: @SplatPow2Test1_i8( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = shl <4 x i8> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i8> [[MUL]] ; entry: %mul = mul <4 x i8> %InVec, ret <4 x i8> %mul } define <4 x i8> @SplatPow2Test2_i8(<4 x i8> %InVec) { ; CHECK-LABEL: @SplatPow2Test2_i8( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = shl <4 x i8> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i8> [[MUL]] ; entry: %mul = mul <4 x i8> %InVec, ret <4 x i8> %mul } define <4 x i8> @MulTest1_i8(<4 x i8> %InVec) { ; CHECK-LABEL: @MulTest1_i8( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = shl <4 x i8> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i8> [[MUL]] ; entry: %mul = mul <4 x i8> %InVec, ret <4 x i8> %mul } define <4 x i8> @MulTest2_i8(<4 x i8> %InVec) { ; CHECK-LABEL: @MulTest2_i8( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = mul <4 x i8> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i8> [[MUL]] ; entry: %mul = mul <4 x i8> %InVec, ret <4 x i8> %mul } define <4 x i8> @MulTest3_i8(<4 x i8> %InVec) { ; CHECK-LABEL: @MulTest3_i8( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = shl <4 x i8> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i8> [[MUL]] ; entry: %mul = mul <4 x i8> %InVec, ret <4 x i8> %mul } define <4 x i8> @MulTest4_i8(<4 x i8> %InVec) { ; CHECK-LABEL: @MulTest4_i8( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = mul <4 x i8> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i8> [[MUL]] ; entry: %mul = mul <4 x i8> %InVec, ret <4 x i8> %mul } define <4 x i16> @Zero_i16(<4 x i16> %InVec) { ; CHECK-LABEL: @Zero_i16( ; CHECK-NEXT: entry: ; CHECK-NEXT: ret <4 x i16> zeroinitializer ; entry: %mul = mul <4 x i16> %InVec, ret <4 x i16> %mul } define <4 x i16> @Identity_i16(<4 x i16> %InVec) { ; CHECK-LABEL: @Identity_i16( ; CHECK-NEXT: entry: ; CHECK-NEXT: ret <4 x i16> [[INVEC:%.*]] ; entry: %mul = mul <4 x i16> %InVec, ret <4 x i16> %mul } define <4 x i16> @AddToSelf_i16(<4 x i16> %InVec) { ; CHECK-LABEL: @AddToSelf_i16( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = shl <4 x i16> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i16> [[MUL]] ; entry: %mul = mul <4 x i16> %InVec, ret <4 x i16> %mul } define <4 x i16> @SplatPow2Test1_i16(<4 x i16> %InVec) { ; CHECK-LABEL: @SplatPow2Test1_i16( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = shl <4 x i16> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i16> [[MUL]] ; entry: %mul = mul <4 x i16> %InVec, ret <4 x i16> %mul } define <4 x i16> @SplatPow2Test2_i16(<4 x i16> %InVec) { ; CHECK-LABEL: @SplatPow2Test2_i16( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = shl <4 x i16> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i16> [[MUL]] ; entry: %mul = mul <4 x i16> %InVec, ret <4 x i16> %mul } define <4 x i16> @MulTest1_i16(<4 x i16> %InVec) { ; CHECK-LABEL: @MulTest1_i16( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = shl <4 x i16> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i16> [[MUL]] ; entry: %mul = mul <4 x i16> %InVec, ret <4 x i16> %mul } define <4 x i16> @MulTest2_i16(<4 x i16> %InVec) { ; CHECK-LABEL: @MulTest2_i16( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = mul <4 x i16> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i16> [[MUL]] ; entry: %mul = mul <4 x i16> %InVec, ret <4 x i16> %mul } define <4 x i16> @MulTest3_i16(<4 x i16> %InVec) { ; CHECK-LABEL: @MulTest3_i16( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = shl <4 x i16> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i16> [[MUL]] ; entry: %mul = mul <4 x i16> %InVec, ret <4 x i16> %mul } define <4 x i16> @MulTest4_i16(<4 x i16> %InVec) { ; CHECK-LABEL: @MulTest4_i16( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = mul <4 x i16> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i16> [[MUL]] ; entry: %mul = mul <4 x i16> %InVec, ret <4 x i16> %mul } define <4 x i32> @Zero_i32(<4 x i32> %InVec) { ; CHECK-LABEL: @Zero_i32( ; CHECK-NEXT: entry: ; CHECK-NEXT: ret <4 x i32> zeroinitializer ; entry: %mul = mul <4 x i32> %InVec, ret <4 x i32> %mul } define <4 x i32> @Identity_i32(<4 x i32> %InVec) { ; CHECK-LABEL: @Identity_i32( ; CHECK-NEXT: entry: ; CHECK-NEXT: ret <4 x i32> [[INVEC:%.*]] ; entry: %mul = mul <4 x i32> %InVec, ret <4 x i32> %mul } define <4 x i32> @AddToSelf_i32(<4 x i32> %InVec) { ; CHECK-LABEL: @AddToSelf_i32( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = shl <4 x i32> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i32> [[MUL]] ; entry: %mul = mul <4 x i32> %InVec, ret <4 x i32> %mul } define <4 x i32> @SplatPow2Test1_i32(<4 x i32> %InVec) { ; CHECK-LABEL: @SplatPow2Test1_i32( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = shl <4 x i32> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i32> [[MUL]] ; entry: %mul = mul <4 x i32> %InVec, ret <4 x i32> %mul } define <4 x i32> @SplatPow2Test2_i32(<4 x i32> %InVec) { ; CHECK-LABEL: @SplatPow2Test2_i32( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = shl <4 x i32> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i32> [[MUL]] ; entry: %mul = mul <4 x i32> %InVec, ret <4 x i32> %mul } define <4 x i32> @MulTest1_i32(<4 x i32> %InVec) { ; CHECK-LABEL: @MulTest1_i32( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = shl <4 x i32> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i32> [[MUL]] ; entry: %mul = mul <4 x i32> %InVec, ret <4 x i32> %mul } define <4 x i32> @MulTest2_i32(<4 x i32> %InVec) { ; CHECK-LABEL: @MulTest2_i32( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = mul <4 x i32> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i32> [[MUL]] ; entry: %mul = mul <4 x i32> %InVec, ret <4 x i32> %mul } define <4 x i32> @MulTest3_i32(<4 x i32> %InVec) { ; CHECK-LABEL: @MulTest3_i32( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = shl <4 x i32> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i32> [[MUL]] ; entry: %mul = mul <4 x i32> %InVec, ret <4 x i32> %mul } define <4 x i32> @MulTest4_i32(<4 x i32> %InVec) { ; CHECK-LABEL: @MulTest4_i32( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = mul <4 x i32> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i32> [[MUL]] ; entry: %mul = mul <4 x i32> %InVec, ret <4 x i32> %mul } define <4 x i64> @Zero_i64(<4 x i64> %InVec) { ; CHECK-LABEL: @Zero_i64( ; CHECK-NEXT: entry: ; CHECK-NEXT: ret <4 x i64> zeroinitializer ; entry: %mul = mul <4 x i64> %InVec, ret <4 x i64> %mul } define <4 x i64> @Identity_i64(<4 x i64> %InVec) { ; CHECK-LABEL: @Identity_i64( ; CHECK-NEXT: entry: ; CHECK-NEXT: ret <4 x i64> [[INVEC:%.*]] ; entry: %mul = mul <4 x i64> %InVec, ret <4 x i64> %mul } define <4 x i64> @AddToSelf_i64(<4 x i64> %InVec) { ; CHECK-LABEL: @AddToSelf_i64( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = shl <4 x i64> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i64> [[MUL]] ; entry: %mul = mul <4 x i64> %InVec, ret <4 x i64> %mul } define <4 x i64> @SplatPow2Test1_i64(<4 x i64> %InVec) { ; CHECK-LABEL: @SplatPow2Test1_i64( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = shl <4 x i64> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i64> [[MUL]] ; entry: %mul = mul <4 x i64> %InVec, ret <4 x i64> %mul } define <4 x i64> @SplatPow2Test2_i64(<4 x i64> %InVec) { ; CHECK-LABEL: @SplatPow2Test2_i64( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = shl <4 x i64> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i64> [[MUL]] ; entry: %mul = mul <4 x i64> %InVec, ret <4 x i64> %mul } define <4 x i64> @MulTest1_i64(<4 x i64> %InVec) { ; CHECK-LABEL: @MulTest1_i64( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = shl <4 x i64> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i64> [[MUL]] ; entry: %mul = mul <4 x i64> %InVec, ret <4 x i64> %mul } define <4 x i64> @MulTest2_i64(<4 x i64> %InVec) { ; CHECK-LABEL: @MulTest2_i64( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = mul <4 x i64> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i64> [[MUL]] ; entry: %mul = mul <4 x i64> %InVec, ret <4 x i64> %mul } define <4 x i64> @MulTest3_i64(<4 x i64> %InVec) { ; CHECK-LABEL: @MulTest3_i64( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = shl <4 x i64> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i64> [[MUL]] ; entry: %mul = mul <4 x i64> %InVec, ret <4 x i64> %mul } define <4 x i64> @MulTest4_i64(<4 x i64> %InVec) { ; CHECK-LABEL: @MulTest4_i64( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = mul <4 x i64> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i64> [[MUL]] ; entry: %mul = mul <4 x i64> %InVec, ret <4 x i64> %mul } ; 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) { ; CHECK-LABEL: @ShiftMulTest1( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = mul <4 x i8> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i8> [[MUL]] ; entry: %shl = shl <4 x i8> %InVec, %mul = mul <4 x i8> %shl, ret <4 x i8> %mul } define <4 x i16> @ShiftMulTest2(<4 x i16> %InVec) { ; CHECK-LABEL: @ShiftMulTest2( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = mul <4 x i16> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i16> [[MUL]] ; entry: %shl = shl <4 x i16> %InVec, %mul = mul <4 x i16> %shl, ret <4 x i16> %mul } define <4 x i32> @ShiftMulTest3(<4 x i32> %InVec) { ; CHECK-LABEL: @ShiftMulTest3( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = mul <4 x i32> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i32> [[MUL]] ; entry: %shl = shl <4 x i32> %InVec, %mul = mul <4 x i32> %shl, ret <4 x i32> %mul } define <4 x i64> @ShiftMulTest4(<4 x i64> %InVec) { ; CHECK-LABEL: @ShiftMulTest4( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[MUL:%.*]] = mul <4 x i64> [[INVEC:%.*]], ; CHECK-NEXT: ret <4 x i64> [[MUL]] ; entry: %shl = shl <4 x i64> %InVec, %mul = mul <4 x i64> %shl, ret <4 x i64> %mul }