[PATCH] Fix debug ICE on aarch64 due to bad rtl simplification (PR debug/70628)

Jakub Jelinek jakub@redhat.com
Tue Apr 12 15:10:00 GMT 2016


Hi!

Most of simplify-rtx.c attempts hard not to generate any extra instructions,
just simplify the RTL to something equivalent and let the user try to
recognize it, or whatever else it wishes.
This is especially important post-reload, when we can't create new pseudos,
or e.g. when processing (simplifying) DEBUG_INSNs, where we certainly don't
want any code around it (not to mention where exactly would it be emitted
anyway?).  E.g. it uses the gen_lowpart_no_emit rtl hook instead of
gen_lowpart, etc.
As the following testcase shows, there are two exceptions, for
POINTER_EXTEND* targets under some very limited conditions it actually
calls convert_memory_address, which sometimes does what simplify-rtx.c
normally does, just return equivalent RTL expression, but in another case
can create a new pseudo (no no after reload, or for debug insns any time)
and emit some move insns.

This patch arranges for a new argument to
convert_memory_address_addr_space_1 and calls it with that new argument set
to true, to make sure it never emits instructions or creates pseudos.

Compared to the previous version of the patch, I've added ATTRIBUTE_UNUSED
to the new argument, so that bootstrap doesn't fail on targets that don't
define POINTERS_EXTEND*.

Bootstrapped/regtested on x86_64-linux and i686-linux, bootstrapped on
aarch64-linux (regtest pending).
I don't have access to aarch64 ilp32 setup though, Andrew or anybody else,
could you please test it there?  Also CCing H.J. just in case it affects
x86 -mx32.

Ok for trunk?

2016-04-12  Jakub Jelinek  <jakub@redhat.com>

	PR debug/70628
	* rtl.h (convert_memory_address_addr_space_1): New prototype.
	* explow.c (convert_memory_address_addr_space_1): No longer static,
	add NO_EMIT argument and don't call convert_modes if true, pass
	it down recursively, remove break after return.
	(convert_memory_address_addr_space): Adjust caller.
	* simplify-rtx.c (simplify_unary_operation_1): Call
	convert_memory_address_addr_space_1 instead of convert_memory_address,
	if it returns NULL, don't simplify.

	* gcc.dg/torture/pr70628.c: New test.

--- gcc/rtl.h.jj	2016-04-04 12:28:42.000000000 +0200
+++ gcc/rtl.h	2016-04-12 12:08:00.327498386 +0200
@@ -2747,6 +2747,8 @@ extern unsigned int subreg_highpart_offs
 					    machine_mode);
 extern int byte_lowpart_offset (machine_mode, machine_mode);
 extern rtx make_safe_from (rtx, rtx);
+extern rtx convert_memory_address_addr_space_1 (machine_mode, rtx,
+						addr_space_t, bool, bool);
 extern rtx convert_memory_address_addr_space (machine_mode, rtx,
 					      addr_space_t);
 #define convert_memory_address(to_mode,x) \
--- gcc/explow.c.jj	2016-03-13 21:39:24.000000000 +0100
+++ gcc/explow.c	2016-04-12 13:27:26.945851321 +0200
@@ -259,12 +259,14 @@ break_out_memory_refs (rtx x)
    which way).  We take advantage of the fact that pointers are not allowed to
    overflow by commuting arithmetic operations over conversions so that address
    arithmetic insns can be used. IN_CONST is true if this conversion is inside
-   a CONST.  */
+   a CONST. NO_EMIT is true if no insns should be emitted, and instead
+   it should return NULL if it can't be simplified without emitting insns.  */
 
-static rtx
+rtx
 convert_memory_address_addr_space_1 (machine_mode to_mode ATTRIBUTE_UNUSED,
 				     rtx x, addr_space_t as ATTRIBUTE_UNUSED,
-				     bool in_const ATTRIBUTE_UNUSED)
+				     bool in_const ATTRIBUTE_UNUSED,
+				     bool no_emit ATTRIBUTE_UNUSED)
 {
 #ifndef POINTERS_EXTEND_UNSIGNED
   gcc_assert (GET_MODE (x) == to_mode || GET_MODE (x) == VOIDmode);
@@ -310,19 +312,16 @@ convert_memory_address_addr_space_1 (mac
       temp = gen_rtx_LABEL_REF (to_mode, LABEL_REF_LABEL (x));
       LABEL_REF_NONLOCAL_P (temp) = LABEL_REF_NONLOCAL_P (x);
       return temp;
-      break;
 
     case SYMBOL_REF:
       temp = shallow_copy_rtx (x);
       PUT_MODE (temp, to_mode);
       return temp;
-      break;
 
     case CONST:
       return gen_rtx_CONST (to_mode,
 			    convert_memory_address_addr_space_1
-			      (to_mode, XEXP (x, 0), as, true));
-      break;
+			      (to_mode, XEXP (x, 0), as, true, no_emit));
 
     case PLUS:
     case MULT:
@@ -338,11 +337,12 @@ convert_memory_address_addr_space_1 (mac
 	      && CONST_INT_P (XEXP (x, 1))
 	      && ((in_const && POINTERS_EXTEND_UNSIGNED != 0)
 		  || XEXP (x, 1) == convert_memory_address_addr_space_1
-				     (to_mode, XEXP (x, 1), as, in_const)
+				     (to_mode, XEXP (x, 1), as, in_const,
+				      no_emit)
                   || POINTERS_EXTEND_UNSIGNED < 0)))
 	return gen_rtx_fmt_ee (GET_CODE (x), to_mode,
 			       convert_memory_address_addr_space_1
-				 (to_mode, XEXP (x, 0), as, in_const),
+				 (to_mode, XEXP (x, 0), as, in_const, no_emit),
 			       XEXP (x, 1));
       break;
 
@@ -350,6 +350,9 @@ convert_memory_address_addr_space_1 (mac
       break;
     }
 
+  if (no_emit)
+    return NULL_RTX;
+
   return convert_modes (to_mode, from_mode,
 			x, POINTERS_EXTEND_UNSIGNED);
 #endif /* defined(POINTERS_EXTEND_UNSIGNED) */
@@ -364,7 +367,7 @@ convert_memory_address_addr_space_1 (mac
 rtx
 convert_memory_address_addr_space (machine_mode to_mode, rtx x, addr_space_t as)
 {
-  return convert_memory_address_addr_space_1 (to_mode, x, as, false);
+  return convert_memory_address_addr_space_1 (to_mode, x, as, false, false);
 }
 
 
--- gcc/simplify-rtx.c.jj	2016-04-05 19:01:34.000000000 +0200
+++ gcc/simplify-rtx.c	2016-04-12 12:25:32.895790315 +0200
@@ -1482,7 +1482,14 @@ simplify_unary_operation_1 (enum rtx_cod
 		  && REG_POINTER (SUBREG_REG (op))
 		  && GET_MODE (SUBREG_REG (op)) == Pmode))
 	  && !targetm.have_ptr_extend ())
-	return convert_memory_address (Pmode, op);
+	{
+	  temp
+	    = convert_memory_address_addr_space_1 (Pmode, op,
+						   ADDR_SPACE_GENERIC, false,
+						   true);
+	  if (temp)
+	    return temp;
+	}
 #endif
       break;
 
@@ -1604,7 +1611,14 @@ simplify_unary_operation_1 (enum rtx_cod
 		  && REG_POINTER (SUBREG_REG (op))
 		  && GET_MODE (SUBREG_REG (op)) == Pmode))
 	  && !targetm.have_ptr_extend ())
-	return convert_memory_address (Pmode, op);
+	{
+	  temp
+	    = convert_memory_address_addr_space_1 (Pmode, op,
+						   ADDR_SPACE_GENERIC, false,
+						   true);
+	  if (temp)
+	    return temp;
+	}
 #endif
       break;
 
--- gcc/testsuite/gcc.dg/torture/pr70628.c.jj	2016-04-12 13:26:35.852566678 +0200
+++ gcc/testsuite/gcc.dg/torture/pr70628.c	2016-04-12 13:26:12.000000000 +0200
@@ -0,0 +1,46 @@
+/* PR debug/70628 */
+/* { dg-do compile } */
+/* { dg-options "-g -w" } */
+
+struct S { char s[64]; int *t; } *a;
+char b[64];
+int *foo (void);
+struct S *bar (int *);
+int baz (void);
+
+void
+test (const char *p, long q)
+{
+  int *c;
+  c = foo ();
+  while (a = bar (c))
+    {
+      if (__builtin_strstr (p, "ABCD")
+	  || __builtin_strstr (p, "EFGHI")
+	  || __builtin_strstr (p, "JKL")
+	  || __builtin_strstr (p, "MNOPQR")
+	  || __builtin_strstr (p, "STUV")
+	  || __builtin_strstr (p, "WXYZabcd")
+	  || __builtin_strstr (p, "efghij")
+	  || __builtin_strstr (p, "klmno")
+	  || __builtin_strstr (p, "pqrstuvw")
+	  || __builtin_strstr (b, "MNOPQR") != "EFGHI"
+	  || __builtin_strstr (b, "JKL"))
+	if (__builtin_strstr (a->s, "xyz12"))
+	  continue;
+      __builtin_printf ("%p\n", a->t);
+    }
+  bar (c);
+  while (a)
+    if (__builtin_strstr (p, "ABCD")
+	|| __builtin_strstr (p, "EFGHI")
+	|| __builtin_strstr (p, "JKL")
+	|| __builtin_strstr (p, "MNOPQR")
+	|| __builtin_strstr (p, "STUV")
+	|| __builtin_strstr (p, "WXYZabcd")
+	|| __builtin_strstr (p, "efghij")
+	|| __builtin_strstr (p, "klmno")
+	|| __builtin_strstr (p, "pqrstuvw")
+	|| __builtin_strstr ((const char *) q, "MNOPQR"))
+      baz ();
+}

	Jakub



More information about the Gcc-patches mailing list