This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix PR optimization/5547 (was DWARF-2 ICE on IA-32)


On Tue, Feb 12, 2002 at 02:35:52PM -0800, Richard Henderson wrote:
> On Tue, Feb 12, 2002 at 11:36:01PM +0100, Jakub Jelinek wrote:
> > Can I commit the testcase?
> 
> Yes.
> 
> > Another could be adding target hooks which would transfer
> > some of the UNSPEC constructions back to debugger understandable rtl...
> 
> See ASM_SIMPLIFY_DWARF_ADDR.

Thanks.
It just needed to understand all the legitimate ia32 addressing modes.
I have reworked the testcase so that it tests all the different cases.
Ok to commit (testing pending)?

2002-02-13  Jakub Jelinek  <jakub@redhat.com>

	PR optimization/5547:
	* config/i386/i386.c (i386_simplify_dwarf_addr): Simplify
	all valid IA-32 address modes involving non-scaled %ebx and
	GOT/GOTOFF as displacement.

	* g++.dg/other/debug3.C: New test.

--- gcc/config/i386/i386.c.jj	Thu Feb  7 12:23:09 2002
+++ gcc/config/i386/i386.c	Wed Feb 13 12:54:18 2002
@@ -5365,7 +5365,7 @@ rtx
 i386_simplify_dwarf_addr (orig_x)
      rtx orig_x;
 {
-  rtx x = orig_x;
+  rtx x = orig_x, y;
 
   if (TARGET_64BIT)
     {
@@ -5377,22 +5377,54 @@ i386_simplify_dwarf_addr (orig_x)
     }
 
   if (GET_CODE (x) != PLUS
-      || GET_CODE (XEXP (x, 0)) != REG
       || GET_CODE (XEXP (x, 1)) != CONST)
     return orig_x;
 
+  if (GET_CODE (XEXP (x, 0)) == REG
+      && REGNO (XEXP (x, 0)) == PIC_OFFSET_TABLE_REGNUM)
+    /* %ebx + GOT/GOTOFF */
+    y = NULL;
+  else if (GET_CODE (XEXP (x, 0)) == PLUS)
+    {
+      /* %ebx + %reg * scale + GOT/GOTOFF */
+      y = XEXP (x, 0);
+      if (GET_CODE (XEXP (y, 0)) == REG
+	  && REGNO (XEXP (y, 0)) == PIC_OFFSET_TABLE_REGNUM)
+	y = XEXP (y, 1);
+      else if (GET_CODE (XEXP (y, 1)) == REG
+	       && REGNO (XEXP (y, 1)) == PIC_OFFSET_TABLE_REGNUM)
+	y = XEXP (y, 0);
+      else
+	return orig_x;
+      if (GET_CODE (y) != REG
+	  && GET_CODE (y) != MULT
+	  && GET_CODE (y) != ASHIFT)
+	return orig_x;
+    }
+  else
+    return orig_x;
+
   x = XEXP (XEXP (x, 1), 0);
   if (GET_CODE (x) == UNSPEC
       && (XINT (x, 1) == 6
 	  || XINT (x, 1) == 7))
-    return XVECEXP (x, 0, 0);
+    {
+      if (y)
+	return gen_rtx_PLUS (Pmode, y, XVECEXP (x, 0, 0));
+      return XVECEXP (x, 0, 0);
+    }
 
   if (GET_CODE (x) == PLUS
       && GET_CODE (XEXP (x, 0)) == UNSPEC
       && GET_CODE (XEXP (x, 1)) == CONST_INT
       && (XINT (XEXP (x, 0), 1) == 6
 	  || XINT (XEXP (x, 0), 1) == 7))
-    return gen_rtx_PLUS (VOIDmode, XVECEXP (XEXP (x, 0), 0, 0), XEXP (x, 1));
+    {
+      x = gen_rtx_PLUS (VOIDmode, XVECEXP (XEXP (x, 0), 0, 0), XEXP (x, 1));
+      if (y)
+	return gen_rtx_PLUS (Pmode, y, x);
+      return x;
+    }
 
   return orig_x;
 }
--- gcc/testsuite/g++.dg/other/debug3.C.jj	Tue Feb 12 23:20:23 2002
+++ gcc/testsuite/g++.dg/other/debug3.C	Wed Feb 13 12:44:47 2002
@@ -0,0 +1,47 @@
+// PR optimization/5547
+// This testcase caused ICE on IA-32, since DWARF-2 was unable
+// to emit location expression for parameter a of operator+.
+// { dg-do compile }
+// { dg-options "-O2 -g -fpic" }
+
+struct A { char *s; };
+
+inline A operator+ (char a, const A &b)
+{
+  A s;
+  s.s = new char[12];
+  s.s[0] = a;
+  return s;
+}
+
+int b (const A &);
+
+void test1 (const A &x, int y)
+{
+  int j = b ("012345"[y] + x);
+  for (int i = 0; i < y; i++);
+}
+
+void test2 (const A &x, int y)
+{
+  int j = b ("012345678"[y + 2] + x);
+  for (int i = 0; i < y; i++);
+}
+
+void test3 (const A &x, int y)
+{
+  int j = b ("012345678"[y - 6] + x);
+  for (int i = 0; i < y; i++);
+}
+
+void test4 (const A &x, int y)
+{
+  int j = b ("012345678"[2 * y - 10] + x);
+  for (int i = 0; i < y; i++);
+}
+
+void test5 (const A &x, int y)
+{
+  int j = b ("012345678"[4 * y] + x);
+  for (int i = 0; i < y; i++);
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]