This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] fix prefetch optimization in loop.c
- From: Janis Johnson <janis187 at us dot ibm dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 21 Jan 2002 11:11:14 -0800
- Subject: [PATCH] fix prefetch optimization in loop.c
This patch allows the mainline to bootstrap on i686-pc-linux-gnu with
BOOT_CFLAGS="-O2 -fprefetch-loop-arrays -mcpu=pentium3". Without this
patch, reload.c and reload1.c were being miscompiled when loops were
considered and then rejected for prefetch optimization. This happened
because of an assumption that rtx_copy was returning a copy of the
address rtx when it was actually returning a pointer to the original
rtx.
Bootstrapped and tested on i686-pc-linux-gnu and ia64-unknown-linux,
along with the following patches:
http://gcc.gnu.org/ml/gcc-patches/2002-01/msg01071.html
http://gcc.gnu.org/ml/gcc-patches/2002-01/msg01393.html
http://gcc.gnu.org/ml/gcc-patches/2002-01/msg01395.html
OK?
2002-01-21 Janis Johnson <janis187@us.ibm.com>
* loop.c (emit_prefetch_instructions): Don't change addresses if
they aren't new copies.
testsuite:
* gcc.dg/20020121-2.c: New test.
Index: loop.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/loop.c,v
retrieving revision 1.378
diff -u -p -r1.378 loop.c
--- loop.c 2002/01/03 16:05:54 1.378
+++ loop.c 2002/01/20 20:59:46
@@ -54,6 +54,7 @@ Software Foundation, 59 Temple Place - S
#include "toplev.h"
#include "predict.h"
#include "insn-flags.h"
+#include "optabs.h"
/* Not really meaningful values, but at least something. */
#ifndef SIMULTANEOUS_PREFETCHES
@@ -3856,10 +3857,18 @@ emit_prefetch_instructions (loop)
address = copy_rtx (iv->add_val);
temp = copy_rtx (bl->initial_value);
- address = simplify_gen_binary (PLUS, Pmode, temp, address);
- index = remove_constant_addition (&address);
+ /* COPY_RTX sometimes returns a pointer to the original rather
+ than making a copy. We can't change the existing rtx in case
+ we end up not doing a prefetch.
+ ??? If we can always get a real copy, do that instead of
+ skipping the following code. */
+ if (temp != bl->initial_value)
+ {
+ address = simplify_gen_binary (PLUS, Pmode, temp, address);
+ index = remove_constant_addition (&address);
+ index += size;
+ }
- index += size;
d.mem_write = 0;
d.mem_address = *iv->location;
--- /dev/null Tue May 23 09:27:54 2000
+++ testsuite/gcc.dg/20020121-2.c Sat Jan 19 20:12:03 2002
@@ -0,0 +1,43 @@
+/* This code is from the beginning of combine_reloads in reload.c in
+ GCC 3.1-20020117, with simplifications. It compiled incorrectly
+ for -O2 -fprefetch-loop-arrays for ix86 targets. */
+
+/* { dg-options "-O2 -fprefetch-loop-arrays -mcpu=pentium3" } */
+/* { dg-do run { target-i?86-*-* } } */
+
+struct reload
+{
+ int first_member;
+ int out;
+ int final_member;
+};
+
+int n_reloads;
+struct reload rld[10];
+
+static int
+combine_reloads ()
+{
+ int i;
+ int output_reload = -1;
+ int secondary_out = -1;
+
+ for (i = 0; i < n_reloads; i++)
+ if (rld[i].out != 0)
+ {
+ if (output_reload >= 0)
+ return output_reload;
+ output_reload = i;
+ }
+ return output_reload;
+}
+
+int
+main ()
+{
+ n_reloads = 4;
+ rld[2].out = 2;
+ if (combine_reloads () != 2)
+ abort ();
+ exit (0);
+}