Skip to content

Commit 87750c9

Browse files
committed
[VectorCombine] foldPermuteOfBinops - match identity shuffles only if they match the destination type
Fixes regression identified after #122118
1 parent 0fb0ac7 commit 87750c9

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,10 +1639,10 @@ bool VectorCombine::foldPermuteOfBinops(Instruction &I) {
16391639
}
16401640

16411641
unsigned NumOpElts = Op0Ty->getNumElements();
1642-
bool IsIdentity0 =
1642+
bool IsIdentity0 = ShuffleDstTy == Op0Ty &&
16431643
all_of(NewMask0, [NumOpElts](int M) { return M < (int)NumOpElts; }) &&
16441644
ShuffleVectorInst::isIdentityMask(NewMask0, NumOpElts);
1645-
bool IsIdentity1 =
1645+
bool IsIdentity1 = ShuffleDstTy == Op1Ty &&
16461646
all_of(NewMask1, [NumOpElts](int M) { return M < (int)NumOpElts; }) &&
16471647
ShuffleVectorInst::isIdentityMask(NewMask1, NumOpElts);
16481648

llvm/test/Transforms/VectorCombine/X86/permute-of-binops.ll

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ define <4 x double> @fadd_v4f64_poison_idx(<4 x double> %a, <4 x double> %b) {
3636
ret <4 x double> %post
3737
}
3838

39-
define <4 x double> @fadd_mixed_types(<4 x double> %a, <2 x double> %b) {
40-
; CHECK-LABEL: define <4 x double> @fadd_mixed_types(
39+
define <4 x double> @fadd_v4f64_mixed_types(<4 x double> %a, <2 x double> %b) {
40+
; CHECK-LABEL: define <4 x double> @fadd_v4f64_mixed_types(
4141
; CHECK-SAME: <4 x double> [[A:%.*]], <2 x double> [[B:%.*]]) #[[ATTR0]] {
4242
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x double> [[A]], <4 x double> poison, <4 x i32> <i32 2, i32 3, i32 0, i32 1>
4343
; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <2 x double> [[B]], <2 x double> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 1>
@@ -51,6 +51,19 @@ define <4 x double> @fadd_mixed_types(<4 x double> %a, <2 x double> %b) {
5151
ret <4 x double> %post
5252
}
5353

54+
define <4 x float> @fadd_v4f32_mixed_types(<4 x float> %a0) {
55+
; CHECK-LABEL: define <4 x float> @fadd_v4f32_mixed_types(
56+
; CHECK-SAME: <4 x float> [[A0:%.*]]) #[[ATTR0]] {
57+
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x float> [[A0]], <4 x float> zeroinitializer, <4 x i32> <i32 1, i32 5, i32 poison, i32 poison>
58+
; CHECK-NEXT: [[POST:%.*]] = fmul <4 x float> [[TMP1]], <float 0.000000e+00, float 0.000000e+00, float undef, float undef>
59+
; CHECK-NEXT: ret <4 x float> [[POST]]
60+
;
61+
%pre = shufflevector <4 x float> %a0, <4 x float> zeroinitializer, <2 x i32> <i32 1, i32 5>
62+
%op = fmul <2 x float> %pre, zeroinitializer
63+
%post = shufflevector <2 x float> %op, <2 x float> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
64+
ret <4 x float> %post
65+
}
66+
5467
; Negative test - multiple use of fadd
5568
define <4 x double> @fadd_v4f64_multiuse_op(<4 x double> %a, <4 x double> %b) {
5669
; CHECK-LABEL: define <4 x double> @fadd_v4f64_multiuse_op(

0 commit comments

Comments
 (0)