diff mbox

[i386] : Fix PR59153, ICE: in memory_address_length, at config/i386/i386.c

Message ID CAFULd4ZLn+Fpic6vNhEj4e_YitEym_zpT8udDe4Lti+_S+1uYg@mail.gmail.com
State New
Headers show

Commit Message

Uros Bizjak Nov. 17, 2013, 11:04 p.m. UTC
Hello!

ix86_decompose_address is called from many places in i386.c, also to
calculate various attributes of the insn (length, etc). The testcase
failed since addsi_1 pattern was declared as TYPE_LEA and its pattern
(involving subregs of SFmode) was passed to length attribute
calculation as memory operand. The failure was in
ix86_address_subreg_operand that rejected non-integer subregs.
ix86_decompose_address should fail only if the *structure* of address
is totaly wrong, and should not bother too much about its operands.
Operand checks should be done in ix86_legitimate_address_p.
The patch moves a couple of check to ix86_legitimate_address_p. The
prevention of non-integer registers in address was already there, so
the check in ix86_address_subreg_operand was not needed anyway. The
check for invalid x86_64 constant address was also already present in
ix86_legitimate_address_p, so corresponding x32 check was also moved
there.

2013-11-17  Uros Bizjak  <ubizjak@gmail.com>

    PR target/59153
    * config/i386/i386.c (ix86_address_subreg_operand): Do not
    reject non-integer subregs.
    (ix86_decompose_address): Do not reject invalid CONST_INT RTXes.
    Move check for invalid x32 constant addresses ...
    (ix86_legitimate_address_p): ... here.

testsuite/ChangeLog:

2013-11-17  Uros Bizjak  <ubizjak@gmail.com>

    PR target/59153
    * gcc.target/i386/pr59153.c: New test.

Patch was bootstrapped and regression tested on x86_64-pc-linux-gnu
{,-m32} and committed to mainline. The patch will be backported to
other release branches after a couple of days without problems in
mainline.

Uros.
diff mbox

Patch

Index: config/i386/i386.c
===================================================================
--- config/i386/i386.c	(revision 204921)
+++ config/i386/i386.c	(working copy)
@@ -11785,9 +11785,6 @@  ix86_address_subreg_operand (rtx op)
 
   mode = GET_MODE (op);
 
-  if (GET_MODE_CLASS (mode) != MODE_INT)
-    return false;
-
   /* Don't allow SUBREGs that span more than a word.  It can lead to spill
      failures when the register is one word out of a two word structure.  */
   if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
@@ -11962,19 +11959,6 @@  ix86_decompose_address (rtx addr, struct ix86_addr
       scale = 1 << scale;
       retval = -1;
     }
-  else if (CONST_INT_P (addr))
-    {
-      if (!x86_64_immediate_operand (addr, VOIDmode))
-	return 0;
-
-      /* Constant addresses are sign extended to 64bit, we have to
-	 prevent addresses from 0x80000000 to 0xffffffff in x32 mode.  */
-      if (TARGET_X32
-	  && val_signbit_known_set_p (SImode, INTVAL (addr)))
-	return 0;
-
-      disp = addr;
-    }
   else
     disp = addr;			/* displacement */
 
@@ -12706,6 +12690,12 @@  ix86_legitimate_address_p (enum machine_mode mode
 	       && !x86_64_immediate_operand (disp, VOIDmode))
 	/* Displacement is out of range.  */
 	return false;
+      /* In x32 mode, constant addresses are sign extended to 64bit, so
+	 we have to prevent addresses from 0x80000000 to 0xffffffff.  */
+      else if (TARGET_X32 && !(index || base)
+	       && CONST_INT_P (disp)
+	       && val_signbit_known_set_p (SImode, INTVAL (disp)))
+	return false;
     }
 
   /* Everything looks valid.  */
Index: testsuite/gcc.target/i386/pr59153.c
===================================================================
--- testsuite/gcc.target/i386/pr59153.c	(revision 0)
+++ testsuite/gcc.target/i386/pr59153.c	(working copy)
@@ -0,0 +1,13 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O -flive-range-shrinkage -mdispatch-scheduler -march=bdver1" } */
+
+int foo (float f)
+{
+  union
+  {
+    float f;
+    int i;
+  } z = { .f = f };
+
+  return z.i - 1;
+}