This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix debug ICE on aarch64 due to bad rtl simplification (PR debug/70628)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Bernd Schmidt <bschmidt at redhat dot com>
- Cc: Jeff Law <law at redhat dot com>, Eric Botcazou <ebotcazou at adacore dot com>, gcc-patches at gcc dot gnu dot org, Andrew Pinski <pinskia at gmail dot com>, "H.J. Lu" <hjl dot tools at gmail dot com>, Kyrill Tkachov <kyrylo dot tkachov at foss dot arm dot com>
- Date: Tue, 12 Apr 2016 22:34:03 +0200
- Subject: Re: [PATCH] Fix debug ICE on aarch64 due to bad rtl simplification (PR debug/70628)
- Authentication-results: sourceware.org; auth=none
- References: <20160412151011 dot GW19207 at tucnak dot redhat dot com> <570D544A dot 6080101 at redhat dot com> <20160412200651 dot GH19207 at tucnak dot redhat dot com> <570D5719 dot 6060308 at redhat dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Tue, Apr 12, 2016 at 10:14:17PM +0200, Bernd Schmidt wrote:
> >So, would you be ok with the patch if I change it that way (to be tested
> >tomorrow)?
>
> Yeah, I think so.
So here is what I'll throw at testing:
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-12 19:12:34.681054428 +0200
+++ gcc/rtl.h 2016-04-12 22:20:14.879906956 +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-04-12 19:12:34.711054027 +0200
+++ gcc/explow.c 2016-04-12 22:26:17.633953657 +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;
+ temp = convert_memory_address_addr_space_1 (to_mode, XEXP (x, 0), as,
+ true, no_emit);
+ return temp ? gen_rtx_CONST (to_mode, temp) : temp;
case PLUS:
case MULT:
@@ -338,18 +337,25 @@ 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),
- XEXP (x, 1));
+ {
+ temp = convert_memory_address_addr_space_1 (to_mode, XEXP (x, 0),
+ as, in_const, no_emit);
+ return temp ? gen_rtx_fmt_ee (GET_CODE (x), to_mode,
+ temp, XEXP (x, 1))
+ : temp;
+ }
break;
default:
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 +370,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-12 19:12:34.755053438 +0200
+++ gcc/simplify-rtx.c 2016-04-12 22:20:14.881906929 +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 22:20:14.882906915 +0200
+++ gcc/testsuite/gcc.dg/torture/pr70628.c 2016-04-12 22:20:14.882906915 +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