[llvm] 87750c9 - [VectorCombine] foldPermuteOfBinops - match identity shuffles only if they match the destination type

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 14 08:10:05 PST 2025


Author: Simon Pilgrim
Date: 2025-01-14T16:09:50Z
New Revision: 87750c9de4b7bd71539bfadd61c10317235da138

URL: https://github.com/llvm/llvm-project/commit/87750c9de4b7bd71539bfadd61c10317235da138
DIFF: https://github.com/llvm/llvm-project/commit/87750c9de4b7bd71539bfadd61c10317235da138.diff

LOG: [VectorCombine] foldPermuteOfBinops - match identity shuffles only if they match the destination type

Fixes regression identified after #122118

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/VectorCombine.cpp
    llvm/test/Transforms/VectorCombine/X86/permute-of-binops.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
index 88d7cf2013a6b0..59920b5a4dd20a 100644
--- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -1639,10 +1639,10 @@ bool VectorCombine::foldPermuteOfBinops(Instruction &I) {
   }
 
   unsigned NumOpElts = Op0Ty->getNumElements();
-  bool IsIdentity0 =
+  bool IsIdentity0 = ShuffleDstTy == Op0Ty &&
       all_of(NewMask0, [NumOpElts](int M) { return M < (int)NumOpElts; }) &&
       ShuffleVectorInst::isIdentityMask(NewMask0, NumOpElts);
-  bool IsIdentity1 =
+  bool IsIdentity1 = ShuffleDstTy == Op1Ty &&
       all_of(NewMask1, [NumOpElts](int M) { return M < (int)NumOpElts; }) &&
       ShuffleVectorInst::isIdentityMask(NewMask1, NumOpElts);
 

diff  --git a/llvm/test/Transforms/VectorCombine/X86/permute-of-binops.ll b/llvm/test/Transforms/VectorCombine/X86/permute-of-binops.ll
index 1dc324bbd63ff9..862c07c3d2270a 100644
--- a/llvm/test/Transforms/VectorCombine/X86/permute-of-binops.ll
+++ b/llvm/test/Transforms/VectorCombine/X86/permute-of-binops.ll
@@ -36,8 +36,8 @@ define <4 x double> @fadd_v4f64_poison_idx(<4 x double> %a, <4 x double> %b) {
   ret <4 x double> %post
 }
 
-define <4 x double> @fadd_mixed_types(<4 x double> %a, <2 x double> %b) {
-; CHECK-LABEL: define <4 x double> @fadd_mixed_types(
+define <4 x double> @fadd_v4f64_mixed_types(<4 x double> %a, <2 x double> %b) {
+; CHECK-LABEL: define <4 x double> @fadd_v4f64_mixed_types(
 ; CHECK-SAME: <4 x double> [[A:%.*]], <2 x double> [[B:%.*]]) #[[ATTR0]] {
 ; CHECK-NEXT:    [[TMP1:%.*]] = shufflevector <4 x double> [[A]], <4 x double> poison, <4 x i32> <i32 2, i32 3, i32 0, i32 1>
 ; 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) {
   ret <4 x double> %post
 }
 
+define <4 x float> @fadd_v4f32_mixed_types(<4 x float> %a0) {
+; CHECK-LABEL: define <4 x float> @fadd_v4f32_mixed_types(
+; CHECK-SAME: <4 x float> [[A0:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:    [[TMP1:%.*]] = shufflevector <4 x float> [[A0]], <4 x float> zeroinitializer, <4 x i32> <i32 1, i32 5, i32 poison, i32 poison>
+; CHECK-NEXT:    [[POST:%.*]] = fmul <4 x float> [[TMP1]], <float 0.000000e+00, float 0.000000e+00, float undef, float undef>
+; CHECK-NEXT:    ret <4 x float> [[POST]]
+;
+  %pre = shufflevector <4 x float> %a0, <4 x float> zeroinitializer, <2 x i32> <i32 1, i32 5>
+  %op = fmul <2 x float> %pre, zeroinitializer
+  %post = shufflevector <2 x float> %op, <2 x float> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
+  ret <4 x float> %post
+}
+
 ; Negative test - multiple use of fadd
 define <4 x double> @fadd_v4f64_multiuse_op(<4 x double> %a, <4 x double> %b) {
 ; CHECK-LABEL: define <4 x double> @fadd_v4f64_multiuse_op(


        


More information about the llvm-commits mailing list