diff mbox

PATCH: copy_addr_to_reg: Convert to Pmode if needed

Message ID 20110312155735.GA4668@intel.com
State New
Headers show

Commit Message

H.J. Lu March 12, 2011, 3:57 p.m. UTC
Hi,

copy_addr_to_reg doesn't check of mode is valid before copy it to
Pmode.  This patch converts to Pmode if needed.  OK for 4.7?

Thanks.


H.J.
--

Comments

Richard Sandiford March 21, 2011, 4:05 p.m. UTC | #1
"H.J. Lu" <hongjiu.lu@intel.com> writes:
> diff --git a/gcc/explow.c b/gcc/explow.c
> index 460af1f..9b3c082 100644
> --- a/gcc/explow.c
> +++ b/gcc/explow.c
> @@ -611,6 +611,8 @@ copy_to_reg (rtx x)
>  rtx
>  copy_addr_to_reg (rtx x)
>  {
> +  if (GET_MODE (x) != VOIDmode && GET_MODE (x) != Pmode)
> +    x = convert_to_mode (Pmode, x, 1);
>    return copy_to_mode_reg (Pmode, x);
>  }

I think you need to say why the conversion should be done here
rather than in the caller.

Regardless of that, though: I think this should be convert_memory_address
rather than convert_to_mode.  Paasing 1 is wrong, because pointers are
signed on some targets.

Richard
diff mbox

Patch

diff --git a/gcc/ChangeLog.x32 b/gcc/ChangeLog.x32
index b85956c..3405300 100644
--- a/gcc/ChangeLog.x32
+++ b/gcc/ChangeLog.x32
@@ -1,5 +1,10 @@ 
 2011-03-12  H.J. Lu  <hongjiu.lu@intel.com>
 
+	PR target/48084
+	* explow.c (copy_addr_to_reg): Convert to Pmode if needed.
+
+2011-03-12  H.J. Lu  <hongjiu.lu@intel.com>
+
 	* config/i386/i386.md (*tls_global_dynamic_64): Don't generate
 	byte 0x66 before lea for TARGET_X32.
 
diff --git a/gcc/explow.c b/gcc/explow.c
index 460af1f..9b3c082 100644
--- a/gcc/explow.c
+++ b/gcc/explow.c
@@ -611,6 +611,8 @@  copy_to_reg (rtx x)
 rtx
 copy_addr_to_reg (rtx x)
 {
+  if (GET_MODE (x) != VOIDmode && GET_MODE (x) != Pmode)
+    x = convert_to_mode (Pmode, x, 1);
   return copy_to_mode_reg (Pmode, x);
 }
 
diff --git a/gcc/testsuite/ChangeLog.x32 b/gcc/testsuite/ChangeLog.x32
index 06ba94e..3b7be1d 100644
--- a/gcc/testsuite/ChangeLog.x32
+++ b/gcc/testsuite/ChangeLog.x32
@@ -1,3 +1,8 @@ 
+2011-03-12  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR target/48084
+	* gcc.target/i386/pr48084-5.c: New.
+
 2011-03-11  H.J. Lu  <hongjiu.lu@intel.com>
 
 	PR target/48084
diff --git a/gcc/testsuite/gcc.target/i386/pr48084-5.c b/gcc/testsuite/gcc.target/i386/pr48084-5.c
new file mode 100644
index 0000000..d6ed8e5
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr48084-5.c
@@ -0,0 +1,8 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O0 -mrdrnd" } */
+
+int
+_rdrand16_step (unsigned short *__P)
+{
+  return __builtin_ia32_rdrand16_step (__P);
+}