From 0253523c927438bb0157a33aeb1b76275991c46d Mon Sep 17 00:00:00 2001
From: Akira Hatanaka <ahatanaka@apple.com>
Date: Thu, 25 Sep 2014 00:26:15 +0000
Subject: [PATCH] [X86,AVX] Add an isel pattern for X86VBroadcast.

This fixes PR21050 and rdar://problem/18434607.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218431 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/Target/X86/X86InstrSSE.td  |  3 +++
 test/CodeGen/X86/avx-movdup.ll | 19 +++++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/lib/Target/X86/X86InstrSSE.td b/lib/Target/X86/X86InstrSSE.td
index a186899d231..b6210e7eb0b 100644
--- a/lib/Target/X86/X86InstrSSE.td
+++ b/lib/Target/X86/X86InstrSSE.td
@@ -8775,6 +8775,9 @@ let Predicates = [HasAVX] in {
               (VPSHUFDri (COPY_TO_REGCLASS GR64:$src, VR128), 0x44), sub_xmm),
               (VPSHUFDri (COPY_TO_REGCLASS GR64:$src, VR128), 0x44), 1)>;
   }
+
+  def : Pat<(v2f64 (X86VBroadcast f64:$src)),
+            (VMOVDDUPrr (COPY_TO_REGCLASS FR64:$src, VR128))>;
 }
 
 //===----------------------------------------------------------------------===//
diff --git a/test/CodeGen/X86/avx-movdup.ll b/test/CodeGen/X86/avx-movdup.ll
index 42d84def98a..19a03259378 100644
--- a/test/CodeGen/X86/avx-movdup.ll
+++ b/test/CodeGen/X86/avx-movdup.ll
@@ -32,3 +32,22 @@ entry:
   ret <4 x i64> %1
 }
 
+; Check that there is a pattern (v2f64 (X86VBroadcast f64:$src)).
+
+; CHECK-LABEL: _vbroadcast_v128_f64
+; CHECK: vmovsd LCPI{{[0-9]+}}_0(%rip), %xmm[[R0:[0-9]+]]
+; CHECK: vmovddup %xmm[[R0]], %xmm{{[0-9]+}}
+
+@E1 = external global [5 x double], align 16
+@.str3 = external unnamed_addr constant [44 x i8], align 1
+
+define void @vbroadcast_v128_f64() #0 {
+entry:
+  store <2 x double> <double -1.000000e+00, double -1.000000e+00>, <2 x double>* bitcast (double* getelementptr inbounds ([5 x double]* @E1, i64 0, i64 2) to <2 x double>*), align 16
+  tail call void @foo1(double -1.000000e+00)
+  ret void
+}
+
+declare void @foo1(double)
+
+attributes #0 = { optsize }
-- 
2.34.1