From 55e03c1992776334e04330e1afc1a652e92f88dc Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Sun, 27 Apr 2014 11:41:06 +0000 Subject: [PATCH] SelectionDAG: Aggressively fold shuffles of constant splats. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207352 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 5 +++++ test/CodeGen/X86/vector-idiv.ll | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 3f68d49da68..46d0fcac410 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -1441,6 +1441,11 @@ SDValue SelectionDAG::getVectorShuffle(EVT VT, SDLoc dl, SDValue N1, if (Identity && NElts) return N1; + // Shuffling a constant splat doesn't change the result. + if (N2Undef && N1.getOpcode() == ISD::BUILD_VECTOR) + if (cast(N1)->getConstantSplatValue()) + return N1; + FoldingSetNodeID ID; SDValue Ops[2] = { N1, N2 }; AddNodeIDNode(ID, ISD::VECTOR_SHUFFLE, getVTList(VT), Ops, 2); diff --git a/test/CodeGen/X86/vector-idiv.ll b/test/CodeGen/X86/vector-idiv.ll index 3b300f74061..981c317157f 100644 --- a/test/CodeGen/X86/vector-idiv.ll +++ b/test/CodeGen/X86/vector-idiv.ll @@ -115,6 +115,7 @@ define <4 x i32> @test8(<4 x i32> %a) { ; SSE-LABEL: test8: ; SSE: pmuldq ; SSE: pshufd $57 +; SSE-NOT: pshufd $57 ; SSE: pmuldq ; SSE: shufps $-35 ; SSE: pshufd $-40 @@ -126,6 +127,7 @@ define <4 x i32> @test8(<4 x i32> %a) { ; AVX-LABEL: test8: ; AVX: vpmuldq ; AVX: vpshufd $57 +; AVX-NOT: vpshufd $57 ; AVX: vpmuldq ; AVX: vshufps $-35 ; AVX: vpshufd $-40 @@ -140,7 +142,7 @@ define <8 x i32> @test9(<8 x i32> %a) { ret <8 x i32> %div ; AVX-LABEL: test9: -; AVX: vpermd +; AVX: vpbroadcastd ; AVX: vpmuldq ; AVX: vshufps $-35 ; AVX: vpmuldq @@ -157,7 +159,7 @@ define <8 x i32> @test10(<8 x i32> %a) { ret <8 x i32> %rem ; AVX-LABEL: test10: -; AVX: vpermd +; AVX: vpbroadcastd ; AVX: vpmuludq ; AVX: vshufps $-35 ; AVX: vpmuludq @@ -174,7 +176,7 @@ define <8 x i32> @test11(<8 x i32> %a) { ret <8 x i32> %rem ; AVX-LABEL: test11: -; AVX: vpermd +; AVX: vpbroadcastd ; AVX: vpmuldq ; AVX: vshufps $-35 ; AVX: vpmuldq