SelectionDAG: Aggressively fold shuffles of constant splats.
llvm-svn: 207352
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 3f68d49..46d0fca 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -1441,6 +1441,11 @@
if (Identity && NElts)
return N1;
+ // Shuffling a constant splat doesn't change the result.
+ if (N2Undef && N1.getOpcode() == ISD::BUILD_VECTOR)
+ if (cast<BuildVectorSDNode>(N1)->getConstantSplatValue())
+ return N1;
+
FoldingSetNodeID ID;
SDValue Ops[2] = { N1, N2 };
AddNodeIDNode(ID, ISD::VECTOR_SHUFFLE, getVTList(VT), Ops, 2);
diff --git a/llvm/test/CodeGen/X86/vector-idiv.ll b/llvm/test/CodeGen/X86/vector-idiv.ll
index 3b300f7..981c317 100644
--- a/llvm/test/CodeGen/X86/vector-idiv.ll
+++ b/llvm/test/CodeGen/X86/vector-idiv.ll
@@ -115,6 +115,7 @@
; SSE-LABEL: test8:
; SSE: pmuldq
; SSE: pshufd $57
+; SSE-NOT: pshufd $57
; SSE: pmuldq
; SSE: shufps $-35
; SSE: pshufd $-40
@@ -126,6 +127,7 @@
; AVX-LABEL: test8:
; AVX: vpmuldq
; AVX: vpshufd $57
+; AVX-NOT: vpshufd $57
; AVX: vpmuldq
; AVX: vshufps $-35
; AVX: vpshufd $-40
@@ -140,7 +142,7 @@
ret <8 x i32> %div
; AVX-LABEL: test9:
-; AVX: vpermd
+; AVX: vpbroadcastd
; AVX: vpmuldq
; AVX: vshufps $-35
; AVX: vpmuldq
@@ -157,7 +159,7 @@
ret <8 x i32> %rem
; AVX-LABEL: test10:
-; AVX: vpermd
+; AVX: vpbroadcastd
; AVX: vpmuludq
; AVX: vshufps $-35
; AVX: vpmuludq
@@ -174,7 +176,7 @@
ret <8 x i32> %rem
; AVX-LABEL: test11:
-; AVX: vpermd
+; AVX: vpbroadcastd
; AVX: vpmuldq
; AVX: vshufps $-35
; AVX: vpmuldq