From e6c7bfdbf3db35b471dd67100cb482c14dab4077 Mon Sep 17 00:00:00 2001 From: Julia Koval Date: Wed, 31 Jan 2018 12:06:20 +0100 Subject: [PATCH] re PR target/83618 (_rdpid_u32 doesn't work on 64-bit targets as gas expects the 64-bit register) PR target/83618 gcc/ * config/i386/i386.c (ix86_expand_builtin): Handle IX86_BUILTIN_RDPID. * config/i386/i386.md (rdpid_rex64) New. (rdpid): Make 32bit only. gcc/testsuite/ * gcc.target/i386/rdpid.c: Remove "eax". From-SVN: r257229 --- gcc/ChangeLog | 7 +++++++ gcc/config/i386/i386.c | 23 +++++++++++++++++++++++ gcc/config/i386/i386.md | 9 ++++++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.target/i386/rdpid.c | 2 +- 5 files changed, 44 insertions(+), 2 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9b9a1c39b13..8368986fbc8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2018-01-31 Julia Koval + + PR target/83618 + * config/i386/i386.c (ix86_expand_builtin): Handle IX86_BUILTIN_RDPID. + * config/i386/i386.md (rdpid_rex64) New. + (rdpid): Make 32bit only. + 2018-01-29 Aldy Hernandez PR lto/84105 diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index fef34a1ef64..deb7e8ff617 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -36736,6 +36736,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_rdpid 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 fe9649d8738..c08e4f55cff 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -20559,7 +20559,14 @@ (define_insn "rdpid" [(set (match_operand:SI 0 "register_operand" "=r") (unspec_volatile:SI [(const_int 0)] UNSPECV_RDPID))] - "TARGET_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/ChangeLog b/gcc/testsuite/ChangeLog index 5220da11d8c..0ff502aab1e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-01-31 Julia Koval + + PR target/83618 + * gcc.target/i386/rdpid.c: Remove "eax". + 2018-01-31 Kyrylo Tkachov PR tree-optimization/64946 diff --git a/gcc/testsuite/gcc.target/i386/rdpid.c b/gcc/testsuite/gcc.target/i386/rdpid.c index 286c2974823..7bba9887461 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 -- 2.30.2