This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix PR optimization/12419


On Tue, Mar 02, 2004 at 10:02:46AM +0100, Jakub Jelinek wrote:
> Actually that is not enough, Jason in Dec, 2002 removed DECL_INITIAL (t) ==
> NULL case.  But this certainly makes Andrew's testcase read from a only
> once.

I've bootstrapped/regtested the following patch on
{i686,x86-64,ia64,ppc,ppc64,s390,s390x}-*-linux.
Ok to commit to trunk/3.4?

2004-03-03  Jakub Jelinek  <jakub@redhat.com>

	PR optimization/12419
	* explow.c (maybe_set_unchanging): Set RTX_UNCHANGING_P even for
	read-only DECL_EXTERNAL decls.

	* gcc.dg/20040302-1.c: New test.

--- gcc/explow.c.jj	2003-12-15 09:37:32.000000000 +0100
+++ gcc/explow.c	2004-03-02 12:07:55.034840235 +0100
@@ -608,9 +608,11 @@ maybe_set_unchanging (rtx ref, tree t)
      solution, perhaps based on alias sets.  */
 
   if ((TREE_READONLY (t) && DECL_P (t)
-       && (TREE_STATIC (t) || ! AGGREGATE_TYPE_P (TREE_TYPE (t)))
-       && (TREE_CODE (t) == PARM_DECL
-	   || (DECL_INITIAL (t) && TREE_CONSTANT (DECL_INITIAL (t)))))
+       && (DECL_EXTERNAL (t)
+	   || ((TREE_STATIC (t) || ! AGGREGATE_TYPE_P (TREE_TYPE (t)))
+	       && (TREE_CODE (t) == PARM_DECL
+		   || (DECL_INITIAL (t)
+		       && TREE_CONSTANT (DECL_INITIAL (t)))))))
       || TREE_CODE_CLASS (TREE_CODE (t)) == 'c')
     RTX_UNCHANGING_P (ref) = 1;
 }
--- gcc/testsuite/gcc.dg/20040302-1.c.jj	2004-01-21 17:12:41.000000000 +0100
+++ gcc/testsuite/gcc.dg/20040302-1.c	2004-03-03 00:08:25.449237291 +0100
@@ -0,0 +1,18 @@
+/* PR optimization/12419 */
+/* Ensure external_const_array[0] is read just once.  */
+/* { dg-do compile { target i?86-*-linux* x86_64-*-linux* } } */
+/* { dg-options "-O2" } */
+/* { dg-final { scan-assembler "external_const_array" } } */
+/* { dg-final { scan-assembler-not "external_const_array.*add\[^\\n\]*external_const_array" } } */
+
+extern const int external_const_array [];
+extern void foo (void);
+
+int
+bar (void)
+{
+  int n = external_const_array[0];
+  foo ();
+  n += external_const_array[0];
+  return n;
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]