[llvm] a911fc1 - [X86] Fold expand(splat,passthrough,mask) -> select(splat,passthrough,mask) (#180238)

via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 9 08:15:47 PST 2026


Author: Simon Pilgrim
Date: 2026-02-09T16:15:41Z
New Revision: a911fc12ec1f280203e243810de2b8acafbca4b8

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

LOG: [X86] Fold expand(splat,passthrough,mask) -> select(splat,passthrough,mask) (#180238)

If all elements of the expansion vector are already splatted in place then we can use a vselect directly

Added: 
    

Modified: 
    llvm/lib/Target/X86/X86ISelLowering.cpp
    llvm/test/CodeGen/X86/vector-shuffle-combining-avx512f.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 239359b5b039e..36d650671251d 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -43636,6 +43636,10 @@ static SDValue combineTargetShuffle(SDValue N, const SDLoc &DL,
     if (auto *Msk = dyn_cast<ConstantSDNode>(peekThroughBitcasts(ExpMask)))
       if (Msk->getAPIntValue().isMask())
         return DAG.getSelect(DL, VT, ExpMask, ExpVec, PassThru);
+    // If ExpVec is splat value, then all elements are already in place - just
+    // use a select.
+    if (DAG.isSplatValue(ExpVec, /*AllowUndefs=*/false))
+      return DAG.getSelect(DL, VT, ExpMask, ExpVec, PassThru);
     return SDValue();
   }
   case X86ISD::VPERMV: {

diff  --git a/llvm/test/CodeGen/X86/vector-shuffle-combining-avx512f.ll b/llvm/test/CodeGen/X86/vector-shuffle-combining-avx512f.ll
index 2eae92b7117e9..3d4af023de799 100644
--- a/llvm/test/CodeGen/X86/vector-shuffle-combining-avx512f.ll
+++ b/llvm/test/CodeGen/X86/vector-shuffle-combining-avx512f.ll
@@ -1035,28 +1035,25 @@ define <8 x double> @concat_vpermilvar_v8f64_v4f64(<4 x double> %a0, <4 x double
   ret <8 x double> %res
 }
 
-define <16 x float> @combine_vexpandd_of_broadcast(float %x, <16 x float> %y, i16 %m) {
-; X86-LABEL: combine_vexpandd_of_broadcast:
+define <16 x float> @combine_vexpandps_of_broadcast(float %x, <16 x float> %y, i16 %m) {
+; X86-LABEL: combine_vexpandps_of_broadcast:
 ; X86:       # %bb.0:
-; X86-NEXT:    vpbroadcastd {{[0-9]+}}(%esp), %zmm1
 ; X86-NEXT:    kmovw {{[0-9]+}}(%esp), %k1
-; X86-NEXT:    vexpandps %zmm1, %zmm0 {%k1}
+; X86-NEXT:    vbroadcastss {{[0-9]+}}(%esp), %zmm0 {%k1}
 ; X86-NEXT:    retl
 ;
-; X64-AVX512F-LABEL: combine_vexpandd_of_broadcast:
+; X64-AVX512F-LABEL: combine_vexpandps_of_broadcast:
 ; X64-AVX512F:       # %bb.0:
-; X64-AVX512F-NEXT:    vpbroadcastd %xmm0, %zmm0
 ; X64-AVX512F-NEXT:    kmovw %edi, %k1
-; X64-AVX512F-NEXT:    vexpandps %zmm0, %zmm1 {%k1}
-; X64-AVX512F-NEXT:    vmovdqa64 %zmm1, %zmm0
+; X64-AVX512F-NEXT:    vbroadcastss %xmm0, %zmm1 {%k1}
+; X64-AVX512F-NEXT:    vmovaps %zmm1, %zmm0
 ; X64-AVX512F-NEXT:    retq
 ;
-; X64-AVX512BW-LABEL: combine_vexpandd_of_broadcast:
+; X64-AVX512BW-LABEL: combine_vexpandps_of_broadcast:
 ; X64-AVX512BW:       # %bb.0:
-; X64-AVX512BW-NEXT:    vpbroadcastd %xmm0, %zmm0
 ; X64-AVX512BW-NEXT:    kmovd %edi, %k1
-; X64-AVX512BW-NEXT:    vexpandps %zmm0, %zmm1 {%k1}
-; X64-AVX512BW-NEXT:    vmovdqa64 %zmm1, %zmm0
+; X64-AVX512BW-NEXT:    vbroadcastss %xmm0, %zmm1 {%k1}
+; X64-AVX512BW-NEXT:    vmovaps %zmm1, %zmm0
 ; X64-AVX512BW-NEXT:    retq
   %xx = insertelement <16 x float> poison, float %x, i32 0
   %vx = shufflevector <16 x float> %xx, <16 x float> poison, <16 x i32> zeroinitializer


        


More information about the llvm-commits mailing list