diff --git a/llvm/test/Transforms/InstCombine/shuffle_select.ll b/llvm/test/Transforms/InstCombine/shuffle_select.ll index 1f0d60a82697b..25064b5df13c3 100644 --- a/llvm/test/Transforms/InstCombine/shuffle_select.ll +++ b/llvm/test/Transforms/InstCombine/shuffle_select.ll @@ -1390,6 +1390,60 @@ define <4 x i32> @shl_mul_2_vars(<4 x i32> %v0, <4 x i32> %v1) { ret <4 x i32> %t3 } +; Negate can be converted to mul to enable the fold. + +define <4 x i32> @mul_neg(<4 x i32> %x) { +; CHECK-LABEL: @mul_neg( +; CHECK-NEXT: [[M:%.*]] = mul <4 x i32> [[X:%.*]], +; CHECK-NEXT: [[N:%.*]] = sub <4 x i32> , [[X]] +; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i32> [[M]], <4 x i32> [[N]], <4 x i32> +; CHECK-NEXT: ret <4 x i32> [[R]] +; + %m = mul <4 x i32> %x, + %n = sub <4 x i32> , %x + %r = shufflevector <4 x i32> %m, <4 x i32> %n, <4 x i32> + ret <4 x i32> %r +} + +define <3 x i79> @neg_mul(<3 x i79> %x) { +; CHECK-LABEL: @neg_mul( +; CHECK-NEXT: [[N:%.*]] = sub nsw <3 x i79> , [[X:%.*]] +; CHECK-NEXT: [[M:%.*]] = mul nsw <3 x i79> [[X]], +; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i79> [[N]], <3 x i79> [[M]], <3 x i32> +; CHECK-NEXT: ret <3 x i79> [[R]] +; + %n = sub nsw <3 x i79> , %x + %m = mul nsw <3 x i79> %x, + %r = shufflevector <3 x i79> %n, <3 x i79> %m, <3 x i32> + ret <3 x i79> %r +} + +define <4 x i32> @mul_neg_2_vars(<4 x i32> %x, <4 x i32> %y) { +; CHECK-LABEL: @mul_neg_2_vars( +; CHECK-NEXT: [[M:%.*]] = mul nuw <4 x i32> [[X:%.*]], +; CHECK-NEXT: [[N:%.*]] = sub nsw <4 x i32> , [[Y:%.*]] +; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i32> [[M]], <4 x i32> [[N]], <4 x i32> +; CHECK-NEXT: ret <4 x i32> [[R]] +; + %m = mul nuw <4 x i32> %x, + %n = sub nsw <4 x i32> , %y + %r = shufflevector <4 x i32> %m, <4 x i32> %n, <4 x i32> + ret <4 x i32> %r +} + +define <4 x i32> @neg_mul_2_vars(<4 x i32> %x, <4 x i32> %y) { +; CHECK-LABEL: @neg_mul_2_vars( +; CHECK-NEXT: [[N:%.*]] = sub nsw <4 x i32> , [[Y:%.*]] +; CHECK-NEXT: [[M:%.*]] = mul nuw nsw <4 x i32> [[X:%.*]], +; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i32> [[N]], <4 x i32> [[M]], <4 x i32> +; CHECK-NEXT: ret <4 x i32> [[R]] +; + %n = sub nsw <4 x i32> , %y + %m = mul nuw nsw <4 x i32> %x, + %r = shufflevector <4 x i32> %n, <4 x i32> %m, <4 x i32> + ret <4 x i32> %r +} + ; Or with constant can be converted to add to enable the fold. ; The 'shl' is here to allow analysis to determine that the 'or' can be transformed to 'add'. ; TODO: The 'or' constant is limited to a splat.