summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@intel.com>2018-01-18 04:17:06 +0000
committerCraig Topper <craig.topper@intel.com>2018-01-18 04:17:06 +0000
commit7f0d85ec1e567ceeb53523bede3dc948d1a833b0 (patch)
treedf43999c01c8e49660b76b09884aef944c5b34ec
parentdecf22e50fd4568e886c6a6a7eaabc0d4d1066d2 (diff)
downloadbcm5719-llvm-7f0d85ec1e567ceeb53523bede3dc948d1a833b0.tar.gz
bcm5719-llvm-7f0d85ec1e567ceeb53523bede3dc948d1a833b0.zip
[DAGCombiner] Add a DAG combine to turn a splat build_vector where the splat elemnt is a bitcast from a vector type into a concat_vector
For example, a build_vector of i64 bitcasted from v2i32 can be turned into a concat_vectors of the v2i32 vectors with a bitcast to a vXi64 type Differential Revision: https://reviews.llvm.org/D42090 llvm-svn: 322811
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp23
-rw-r--r--llvm/test/CodeGen/X86/insertelement-shuffle.ll8
2 files changed, 23 insertions, 8 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 91f6ba4d4a8..8cab6aaf1a2 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -14947,6 +14947,29 @@ SDValue DAGCombiner::visitBUILD_VECTOR(SDNode *N) {
if (ISD::allOperandsUndef(N))
return DAG.getUNDEF(VT);
+ // If this is a splat of a bitcast from another vector, change to a
+ // concat_vector.
+ // For example:
+ // (build_vector (i64 (bitcast (v2i32 X))), (i64 (bitcast (v2i32 X)))) ->
+ // (v2i64 (bitcast (concat_vectors (v2i32 X), (v2i32 X))))
+ //
+ // If X is a build_vector itself, the concat can become a larger build_vector.
+ // TODO: Maybe this is useful for non-splat too?
+ if (!LegalOperations) {
+ if (SDValue Splat = cast<BuildVectorSDNode>(N)->getSplatValue()) {
+ Splat = peekThroughBitcast(Splat);
+ EVT SrcVT = Splat.getValueType();
+ if (SrcVT.isVector()) {
+ unsigned NumElts = N->getNumOperands() * SrcVT.getVectorNumElements();
+ EVT NewVT = EVT::getVectorVT(*DAG.getContext(),
+ SrcVT.getVectorElementType(), NumElts);
+ SmallVector<SDValue, 8> Ops(N->getNumOperands(), Splat);
+ SDValue Concat = DAG.getNode(ISD::CONCAT_VECTORS, SDLoc(N), NewVT, Ops);
+ return DAG.getBitcast(VT, Concat);
+ }
+ }
+ }
+
// Check if we can express BUILD VECTOR via subvector extract.
if (!LegalTypes && (N->getNumOperands() > 1)) {
SDValue Op0 = N->getOperand(0);
diff --git a/llvm/test/CodeGen/X86/insertelement-shuffle.ll b/llvm/test/CodeGen/X86/insertelement-shuffle.ll
index c0177ad7a9a..1756c2aa836 100644
--- a/llvm/test/CodeGen/X86/insertelement-shuffle.ll
+++ b/llvm/test/CodeGen/X86/insertelement-shuffle.ll
@@ -97,17 +97,9 @@ define <8 x i64> @insert_subvector_512(i32 %x0, i32 %x1, <8 x i64> %v) nounwind
define <8 x i64> @insert_subvector_into_undef(i32 %x0, i32 %x1) nounwind {
; X32_AVX256-LABEL: insert_subvector_into_undef:
; X32_AVX256: # %bb.0:
-; X32_AVX256-NEXT: pushl %ebp
-; X32_AVX256-NEXT: movl %esp, %ebp
-; X32_AVX256-NEXT: andl $-8, %esp
-; X32_AVX256-NEXT: subl $8, %esp
-; X32_AVX256-NEXT: vmovsd {{.*#+}} xmm0 = mem[0],zero
-; X32_AVX256-NEXT: vmovlps %xmm0, (%esp)
; X32_AVX256-NEXT: vmovsd {{.*#+}} xmm0 = mem[0],zero
; X32_AVX256-NEXT: vbroadcastsd %xmm0, %ymm0
; X32_AVX256-NEXT: vmovaps %ymm0, %ymm1
-; X32_AVX256-NEXT: movl %ebp, %esp
-; X32_AVX256-NEXT: popl %ebp
; X32_AVX256-NEXT: retl
;
; X64_AVX256-LABEL: insert_subvector_into_undef:
OpenPOWER on IntegriCloud