[llvm] r357642 - [x86] eliminate movddup of horizontal op

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 3 15:15:29 PDT 2019


Author: spatel
Date: Wed Apr  3 15:15:29 2019
New Revision: 357642

URL: http://llvm.org/viewvc/llvm-project?rev=357642&view=rev
Log:
[x86] eliminate movddup of horizontal op

This pattern would show up as a regression if we more
aggressively convert vector FP ops to scalar ops.

There's still a missed optimization for the v4f64 legal
case (AVX) because we create that h-op with an undef operand.
We should probably just duplicate the operands for that
pattern to avoid trouble.

Modified:
    llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
    llvm/trunk/test/CodeGen/X86/haddsub-shuf.ll

Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=357642&r1=357641&r2=357642&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Wed Apr  3 15:15:29 2019
@@ -32866,8 +32866,10 @@ static SDValue combineShuffleOfConcatUnd
 
 /// Eliminate a redundant shuffle of a horizontal math op.
 static SDValue foldShuffleOfHorizOp(SDNode *N) {
-  if (N->getOpcode() != ISD::VECTOR_SHUFFLE || !N->getOperand(1).isUndef())
-    return SDValue();
+  unsigned Opcode = N->getOpcode();
+  if (Opcode != X86ISD::MOVDDUP)
+    if (Opcode != ISD::VECTOR_SHUFFLE || !N->getOperand(1).isUndef())
+      return SDValue();
 
   SDValue HOp = N->getOperand(0);
   if (HOp.getOpcode() != X86ISD::HADD && HOp.getOpcode() != X86ISD::FHADD &&
@@ -32885,6 +32887,13 @@ static SDValue foldShuffleOfHorizOp(SDNo
   // When the operands of a horizontal math op are identical, the low half of
   // the result is the same as the high half. If the shuffle is also replicating
   // low and high halves, we don't need the shuffle.
+  if (Opcode == X86ISD::MOVDDUP) {
+    // movddup (hadd X, X) --> hadd X, X
+    assert((HOp.getValueType() == MVT::v2f64 ||
+            HOp.getValueType() == MVT::v4f64) && "Unexpected type for h-op");
+    return HOp;
+  }
+
   // shuffle (hadd X, X), undef, [low half...high half] --> hadd X, X
   ArrayRef<int> Mask = cast<ShuffleVectorSDNode>(N)->getMask();
   // TODO: Other mask possibilities like {1,1} and {1,0} could be added here,

Modified: llvm/trunk/test/CodeGen/X86/haddsub-shuf.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/haddsub-shuf.ll?rev=357642&r1=357641&r2=357642&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/haddsub-shuf.ll (original)
+++ llvm/trunk/test/CodeGen/X86/haddsub-shuf.ll Wed Apr  3 15:15:29 2019
@@ -325,7 +325,6 @@ define <2 x double> @hadd_v2f64_scalar_s
 ; SSSE3_FAST-LABEL: hadd_v2f64_scalar_splat:
 ; SSSE3_FAST:       # %bb.0:
 ; SSSE3_FAST-NEXT:    haddpd %xmm0, %xmm0
-; SSSE3_FAST-NEXT:    movddup {{.*#+}} xmm0 = xmm0[0,0]
 ; SSSE3_FAST-NEXT:    retq
 ;
 ; AVX1_SLOW-LABEL: hadd_v2f64_scalar_splat:
@@ -338,7 +337,6 @@ define <2 x double> @hadd_v2f64_scalar_s
 ; AVX1_FAST-LABEL: hadd_v2f64_scalar_splat:
 ; AVX1_FAST:       # %bb.0:
 ; AVX1_FAST-NEXT:    vhaddpd %xmm0, %xmm0, %xmm0
-; AVX1_FAST-NEXT:    vmovddup {{.*#+}} xmm0 = xmm0[0,0]
 ; AVX1_FAST-NEXT:    retq
 ;
 ; AVX2_SLOW-LABEL: hadd_v2f64_scalar_splat:
@@ -378,8 +376,6 @@ define <4 x double> @hadd_v4f64_scalar_s
 ; SSSE3_FAST:       # %bb.0:
 ; SSSE3_FAST-NEXT:    haddpd %xmm0, %xmm0
 ; SSSE3_FAST-NEXT:    haddpd %xmm1, %xmm1
-; SSSE3_FAST-NEXT:    movddup {{.*#+}} xmm0 = xmm0[0,0]
-; SSSE3_FAST-NEXT:    movddup {{.*#+}} xmm1 = xmm1[0,0]
 ; SSSE3_FAST-NEXT:    retq
 ;
 ; AVX-LABEL: hadd_v4f64_scalar_splat:




More information about the llvm-commits mailing list