public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* PR 66076: invalid vec_grow in rtx iterators
@ 2015-05-11  9:04 Richard Sandiford
  2015-05-11  9:15 ` Eric Botcazou
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Sandiford @ 2015-05-11  9:04 UTC (permalink / raw)
  To: gcc-patches

The rtx iterators start out using a stack worklist but fall back to
a heap worklist if the stack one turns out to be too small (which is rare).
PR 66076 showed up a bug in the code that makes the switch from the stack
worklist to the heap worklist: the heap one might already have been
allocated if the worklist structure was shared with a previous
FOR_EACH_SUBRTX and if that FOR_EACH_SUBRTX also blew the stack worklist.
Fixed by making the vec_safe_grow conditional on a vec_safe_length check.
(Note that vec_safe_grow starts with a call to vec_safe_length,
so this is no less efficient than a check for a null pointer.)

If one FOR_EACH_SUBRTX needs to use the heap worklist, it might be slightly
more efficient for future FOR_EACH_SUBRTXes on the same worklist structure
to start out using the heap worklist, in order to avoid any future stack-to-heap
memcpy.  The problem is that that would require extra set-up code for all
FOR_EACH_SUBRTXes, and the idea is to optimise for the common case where
the stack worklist is enough.  The situation handled by the patch should
be very rare -- backed up by the fact that the ICE would always trigger
in that case, yet it didn't show up in pre-release testing.

Maybe it would be worth bumping up the size of the stack worklist to cope
with those long AVX512 constants though.

Tested on x86_64-linux-gnu.  Also tested that the testcase passes on
aarch64-elf.  OK to install?

Thanks,
Richard


gcc/
	PR rtl-optimization/66076
	* rtlanal.c (generic_subrtx_iterator <T>::add_single_to_queue):
	Don't grow the heap array if it is already big enough from a
	previous iteration.

gcc/testsuite/
	PR rtl-optimization/66076
	* gcc.dg/torture/pr66076.c: New test.

Index: gcc/rtlanal.c
===================================================================
--- gcc/rtlanal.c	2015-05-10 10:44:24.091059530 +0100
+++ gcc/rtlanal.c	2015-05-10 20:49:56.618230132 +0100
@@ -104,7 +104,10 @@ generic_subrtx_iterator <T>::add_single_
 	  return base;
 	}
       gcc_checking_assert (i == LOCAL_ELEMS);
-      vec_safe_grow (array.heap, i + 1);
+      /* A previous iteration might also have moved from the stack to the
+	 heap, in which case the heap array will already be big enough.  */
+      if (vec_safe_length (array.heap) <= i)
+	vec_safe_grow (array.heap, i + 1);
       base = array.heap->address ();
       memcpy (base, array.stack, sizeof (array.stack));
       base[LOCAL_ELEMS] = x;
Index: gcc/testsuite/gcc.dg/torture/pr66076.c
===================================================================
--- /dev/null	2015-04-20 08:05:53.260830006 +0100
+++ gcc/testsuite/gcc.dg/torture/pr66076.c	2015-05-10 20:49:56.626230040 +0100
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "" } */
+/* { dg-options "-mno-prefer-avx128 -march=bdver4" { target i?86-*-* x86_64-*-* } } */
+
+void
+f0a (char *result, char *arg1, char *arg4, char temp_6)
+{
+  int idx = 0;
+  for (idx = 0; idx < 416; idx += 1)
+    result[idx] = (arg1[idx] + arg4[idx]) * temp_6;
+}

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

* Re: PR 66076: invalid vec_grow in rtx iterators
  2015-05-11  9:04 PR 66076: invalid vec_grow in rtx iterators Richard Sandiford
@ 2015-05-11  9:15 ` Eric Botcazou
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Botcazou @ 2015-05-11  9:15 UTC (permalink / raw)
  To: Richard Sandiford; +Cc: gcc-patches

> gcc/
> 	PR rtl-optimization/66076
> 	* rtlanal.c (generic_subrtx_iterator <T>::add_single_to_queue):
> 	Don't grow the heap array if it is already big enough from a
> 	previous iteration.
> 
> gcc/testsuite/
> 	PR rtl-optimization/66076
> 	* gcc.dg/torture/pr66076.c: New test.

OK, thanks.

-- 
Eric Botcazou

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

end of thread, other threads:[~2015-05-11  9:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-11  9:04 PR 66076: invalid vec_grow in rtx iterators Richard Sandiford
2015-05-11  9:15 ` Eric Botcazou

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).