From 97681f32a0299b61848a5094531d54f37a5f5ca1 Mon Sep 17 00:00:00 2001
From: julia <jkoval@gkticlel801.igk.intel.com>
Date: Mon, 15 Jan 2018 11:34:28 +0300
Subject: [PATCH] fix

---
 gcc/config/i386/i386.c                | 23 +++++++++++++++++++++++
 gcc/config/i386/i386.md               | 11 +++++++++--
 gcc/testsuite/gcc.target/i386/rdpid.c |  2 +-
 3 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 5e17b69..b44f657 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -35942,6 +35942,29 @@ ix86_expand_builtin (tree exp, rtx target, rtx subtarget,
     case IX86_BUILTIN_NANSQ:
       return expand_call (exp, target, ignore);
 
+    case IX86_BUILTIN_RDPID:
+
+      op0 = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
+
+      if (TARGET_64BIT)
+	{
+	  insn = gen_rdpid_rex64 (op0);
+	  op0 = convert_to_mode (SImode, op0, 1);
+	}
+      else
+	insn = gen_rdpid (op0);
+      emit_insn (insn);
+
+      if (target == 0)
+	{
+	  /* mode is VOIDmode if __builtin_rd* has been called
+	     without lhs.  */
+	  if (mode == VOIDmode)
+	    return target;
+	  target = gen_reg_rtx (mode);
+	}
+      emit_move_insn (target, op0);
+      return target;
     case IX86_BUILTIN_RDPMC:
     case IX86_BUILTIN_RDTSC:
     case IX86_BUILTIN_RDTSCP:
diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index 3f58780..25b5aba 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -20539,8 +20539,15 @@
 
 (define_insn "rdpid"
   [(set (match_operand:SI 0 "register_operand" "=r")
-	(unspec_volatile:SI [(const_int 0)] UNSPECV_RDPID))]
-  "TARGET_RDPID"
+  	(unspec_volatile:SI [(const_int 0)] UNSPECV_RDPID))]
+  "!TARGET_64BIT && TARGET_RDPID"
+  "rdpid\t%0"
+  [(set_attr "type" "other")])
+
+(define_insn "rdpid_rex64"
+  [(set (match_operand:DI 0 "register_operand" "=r")
+  	(unspec_volatile:DI [(const_int 0)] UNSPECV_RDPID))]
+  "TARGET_64BIT && TARGET_RDPID"
   "rdpid\t%0"
   [(set_attr "type" "other")])
 
diff --git a/gcc/testsuite/gcc.target/i386/rdpid.c b/gcc/testsuite/gcc.target/i386/rdpid.c
index 286c297..7bba988 100644
--- a/gcc/testsuite/gcc.target/i386/rdpid.c
+++ b/gcc/testsuite/gcc.target/i386/rdpid.c
@@ -1,6 +1,6 @@
 /* { dg-do compile } */
 /* { dg-options "-O2 -mrdpid" } */
-/* { dg-final { scan-assembler "rdpid\[ \t]+(%|)eax" } } */
+/* { dg-final { scan-assembler "rdpid" } } */
 
 #include <x86intrin.h>
 
-- 
2.5.5

