X86: When combining shuffles just remove shuffles that are completely redundant.
authorBenjamin Kramer <benny.kra@googlemail.com>
Wed, 2 Jul 2014 15:09:44 +0000 (15:09 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Wed, 2 Jul 2014 15:09:44 +0000 (15:09 +0000)
CombineTo doesn't allow replacing a node with itself so this would crash if the
combined shuffle is the same as the input shuffle.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212181 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86ISelLowering.cpp
test/CodeGen/X86/vector-shuffle-combining.ll

index 40a80329df188a4e2f6e54ca3412da77565f933e..f0d8f22210429898c3e9101baa3d8eb831179fc7 100644 (file)
@@ -18442,6 +18442,13 @@ static bool combineRedundantDWordShuffle(SDValue N, MutableArrayRef<int> Mask,
   V = DAG.getNode(X86ISD::PSHUFD, DL, MVT::v4i32, V.getOperand(0),
                   getV4X86ShuffleImm8ForMask(Mask, DAG));
 
+  // It is possible that one of the combinable shuffles was completely absorbed
+  // by the other, just replace it and revisit all users in that case.
+  if (Old.getNode() == V.getNode()) {
+    DCI.CombineTo(N.getNode(), N.getOperand(0), /*AddTo=*/true);
+    return true;
+  }
+
   // Replace N with its operand as we're going to combine that shuffle away.
   DAG.ReplaceAllUsesWith(N, N.getOperand(0));
 
index 1bc2aee6efe43bc364173be79b6aa957a16651bd..e60ecb70dec6551ff17714207b103b4022dff9e3 100644 (file)
@@ -66,6 +66,16 @@ define <4 x i32> @combine_pshufd5(<4 x i32> %a) {
   ret <4 x i32> %d
 }
 
+define <4 x i32> @combine_pshufd6(<4 x i32> %a) {
+; CHECK-SSE2-LABEL: @combine_pshufd6
+; CHECK-SSE2:       # BB#0:
+; CHECK-SSE2-NEXT:    pshufd $0
+; CHECK-SSE2-NEXT:    retq
+  %b = call <4 x i32> @llvm.x86.sse2.pshuf.d(<4 x i32> %a, i8 0)
+  %c = call <4 x i32> @llvm.x86.sse2.pshuf.d(<4 x i32> %b, i8 8)
+  ret <4 x i32> %c
+}
+
 define <8 x i16> @combine_pshuflw1(<8 x i16> %a) {
 ; CHECK-SSE2-LABEL: @combine_pshuflw1
 ; CHECK-SSE2:       # BB#0: