public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix ICE with useless VALUE in ix86_pic_register_p (PR  target/41762)
@ 2009-10-23 21:25 Jakub Jelinek
  2009-10-28 14:22 ` Ian Lance Taylor
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2009-10-23 21:25 UTC (permalink / raw)
  To: gcc-patches

Hi!

Roughly a year ago ix86_pic_register_p was added to do a cselib
lookup to find more occurences of pic register when deligitimizing
addresses on i386.  Unfortunately, as the testcase below on 4.4 branch
shows, it can ICE when seeing a VALUE already discarded by
remove_useless_value.  As the i386 backend uses it always, without checking
what kind of pass uses cselib and whether it preserves VALUEs or not, we
IMHO need to be as careful as e.g. aliasing code is.  get_addr in alias.c
also passes through VALUE with NULL CSELIB_VAL_PTR (i.e. VALUE discarded as
useless), instead of dereferencing it unconditionally.
VALUE rtxs are preserved until cselib_finish, which is usually end of pass,
but the associated cselib structures are freed earlier if deemed useless
and not preserved.

Bootstrapped/regtested on x86_64-linux (with r152315 reverted) and
i686-linux, ok for trunk/4.4?

2009-10-23  Jakub Jelinek  <jakub@redhat.com>

	PR target/41762
	* config/i386/i386.c (ix86_pic_register_p): Don't call
	rtx_equal_for_cselib_p for VALUEs discarded as useless.

	* gcc.dg/pr41762.c: New test.

--- gcc/config/i386/i386.c.jj	2009-09-29 17:58:03.000000000 +0200
+++ gcc/config/i386/i386.c	2009-10-23 19:08:19.000000000 +0200
@@ -10379,7 +10379,7 @@ i386_output_dwarf_dtprel (FILE *file, in
 static bool
 ix86_pic_register_p (rtx x)
 {
-  if (GET_CODE (x) == VALUE)
+  if (GET_CODE (x) == VALUE && CSELIB_VAL_PTR (x))
     return (pic_offset_table_rtx
 	    && rtx_equal_for_cselib_p (x, pic_offset_table_rtx));
   else
--- gcc/testsuite/gcc.dg/pr41762.c.jj	2009-10-23 19:15:42.000000000 +0200
+++ gcc/testsuite/gcc.dg/pr41762.c	2009-10-23 19:14:35.000000000 +0200
@@ -0,0 +1,31 @@
+/* PR target/41762 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -ftracer -fsched2-use-superblocks" } */
+/* { dg-options "-O2 -ftracer -fsched2-use-superblocks -fpic" { target fpic } } */
+
+extern __SIZE_TYPE__ strlen (const char *);
+extern int f1 (void *);
+extern char *f2 (void);
+extern void f3 (int, int);
+static char *a;
+char *b, *c, *d, *e;
+
+void
+foo (void)
+{
+  int f, g, h;
+  f = (a ? strlen (a) : strlen ("abcde"));
+  f += (b ? strlen (b) : 0);
+  f += (c ? strlen (c) : 0);
+  f += (d ? strlen (d) : 0);
+  f += (e ? strlen (e) : 0);
+  h = f1 (strlen);
+  g = strlen (a);
+  f3 (g, f);
+}
+
+void
+bar (void)
+{
+  a = f2 ();
+}

	Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix ICE with useless VALUE in ix86_pic_register_p (PR  target/41762)
  2009-10-23 21:25 [PATCH] Fix ICE with useless VALUE in ix86_pic_register_p (PR target/41762) Jakub Jelinek
@ 2009-10-28 14:22 ` Ian Lance Taylor
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor @ 2009-10-28 14:22 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

Jakub Jelinek <jakub@redhat.com> writes:

> 2009-10-23  Jakub Jelinek  <jakub@redhat.com>
>
> 	PR target/41762
> 	* config/i386/i386.c (ix86_pic_register_p): Don't call
> 	rtx_equal_for_cselib_p for VALUEs discarded as useless.
>
> 	* gcc.dg/pr41762.c: New test.

This is OK.

Thanks.

Ian

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-10-28 14:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-23 21:25 [PATCH] Fix ICE with useless VALUE in ix86_pic_register_p (PR target/41762) Jakub Jelinek
2009-10-28 14:22 ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).