[PATCH] D38696: [DAGCombine] Permit combining of shuffle of equivalent splat BUILD_VECTORs
Simon Pilgrim via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 9 11:16:28 PDT 2017
RKSimon created this revision.
combineShuffleOfScalars is very conservative about shuffled BUILD_VECTOsR that can be combined together.
I'd like to add one additional case - if both BUILD_VECTORs represent splats of the same scalar value but with different UNDEF elements, then we should create a single splat BUILD_VECTOR, sharing only the common UNDEF elements.
Repository:
rL LLVM
https://reviews.llvm.org/D38696
Files:
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
test/CodeGen/X86/avx-vbroadcast.ll
Index: test/CodeGen/X86/avx-vbroadcast.ll
===================================================================
--- test/CodeGen/X86/avx-vbroadcast.ll
+++ test/CodeGen/X86/avx-vbroadcast.ll
@@ -853,14 +853,12 @@
; X32-LABEL: broadcast_shuffle1032:
; X32: ## BB#0:
; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
-; X32-NEXT: vmovddup {{.*#+}} xmm0 = mem[0,0]
-; X32-NEXT: vinsertf128 $1, %xmm0, %ymm0, %ymm0
+; X32-NEXT: vbroadcastsd (%eax), %ymm0
; X32-NEXT: retl
;
; X64-LABEL: broadcast_shuffle1032:
; X64: ## BB#0:
-; X64-NEXT: vmovddup {{.*#+}} xmm0 = mem[0,0]
-; X64-NEXT: vinsertf128 $1, %xmm0, %ymm0, %ymm0
+; X64-NEXT: vbroadcastsd (%rdi), %ymm0
; X64-NEXT: retq
%1 = load double, double* %p
%2 = insertelement <2 x double> undef, double %1, i32 1
Index: lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -15489,6 +15489,24 @@
return SDValue();
}
+ // If both inputs are splats of the same value then we can safely merge this
+ // to a single BUILD_VECTOR with only the common undef elements.
+ auto *BV0 = dyn_cast<BuildVectorSDNode>(N0);
+ auto *BV1 = dyn_cast<BuildVectorSDNode>(N1);
+ if (BV0 && BV1) {
+ BitVector Undefs0, Undefs1;
+ SDValue Splat0 = BV0->getSplatValue(&Undefs0);
+ SDValue Splat1 = BV1->getSplatValue(&Undefs1);
+ if (Splat0 && Splat0 == Splat1) {
+ Undefs0 &= Undefs1;
+ SmallVector<SDValue, 8> Ops(NumElts, Splat0);
+ for (unsigned i = 0; i != NumElts; ++i)
+ if (Undefs0[0])
+ Ops[i] = DAG.getUNDEF(Splat0.getValueType());
+ return DAG.getBuildVector(VT, SDLoc(SVN), Ops);
+ }
+ }
+
SmallVector<SDValue, 8> Ops;
SmallSet<SDValue, 16> DuplicateOps;
for (int M : SVN->getMask()) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38696.118239.patch
Type: text/x-patch
Size: 1927 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171009/be100788/attachment.bin>
More information about the llvm-commits
mailing list