public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* REQ_EQUAL and mems hoisted out of loops
@ 2003-03-25 14:02 Alan Modra
  2003-03-25 18:27 ` David Edelsohn
  2003-03-26 10:36 ` Alan Modra
  0 siblings, 2 replies; 5+ messages in thread
From: Alan Modra @ 2003-03-25 14:02 UTC (permalink / raw)
  To: gcc

gcc.c-torture/execute/991202-1.c has been failing at -O2 on
powerpc64-linux for some time.  The following rtl is just before cse2
goes wild.

When cse_insn looks at insn 50, it decides that insn 30 calculates the
same value and simplifies insn 50 down to

(set:DI (reg:DI 138) (reg:DI 127))

Oops, reg 145 has changed in the meantime at insn 41.  From what I can
tell, the REG_EQUAL notes in combination with the fact that the store
to "y" has been moved out of the loop by loop optimization, is the cause
of cse confusion.

So it seems a possible fix would be to delete all REG_EQUAL notes
that mention any mem hoisted out of a loop.  Before I try to do that,
I thought I'd solicit comments on the approach.  Reasonable?


(insn 30 28 31 1 (nil) (set:DI (reg:DI 127)
        (zero_extend:DI (reg/v:SI 145))) -1 (nil)
    (expr_list:REG_EQUAL (zero_extend:DI (mem/f:SI (symbol_ref:DI ("y")) [3 y+0 S4 A32]))
        (nil)))

(insn 31 30 32 1 (nil) (set (reg:SI 128)
        (subreg:SI (reg:DI 127) 4)) -1 (nil)
    (nil))

(insn 32 31 34 1 (nil) (set (reg/v:SI 148)
        (subreg:SI (reg:DI 127) 4)) 300 {*movsi_internal1} (nil)
    (nil))

(insn 34 32 36 1 (nil) (use (symbol_ref:DI ("y"))) -1 (nil)
    (nil))

(insn 36 34 41 1 (nil) (use (symbol_ref:DI ("y"))) -1 (nil)
    (nil))

(insn 41 36 43 1 (nil) (set (reg/v:SI 145)
        (ashift:SI (reg:SI 128)
            (const_int 1 [0x1]))) -1 (nil)
    (expr_list:REG_EQUAL (ashift:SI (reg:SI 128)
            (const_int 1 [0x1]))
        (nil)))

(note 43 41 46 1 NOTE_INSN_LOOP_CONT)

(insn 46 43 48 1 (nil) (use (symbol_ref:DI ("y"))) -1 (nil)
    (nil))

(insn 48 46 50 1 (nil) (use (symbol_ref:DI ("x"))) -1 (nil)
    (nil))

(insn 50 48 51 1 (nil) (set:DI (reg:DI 138)
        (zero_extend:DI (reg/v:SI 145))) -1 (nil)
    (expr_list:REG_EQUAL (zero_extend:DI (mem/f:SI (symbol_ref:DI ("y")) [3 y+0 S4 A32]))
        (nil)))

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

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

* Re: REQ_EQUAL and mems hoisted out of loops
  2003-03-25 14:02 REQ_EQUAL and mems hoisted out of loops Alan Modra
@ 2003-03-25 18:27 ` David Edelsohn
  2003-03-26 10:36 ` Alan Modra
  1 sibling, 0 replies; 5+ messages in thread
From: David Edelsohn @ 2003-03-25 18:27 UTC (permalink / raw)
  To: Alan Modra; +Cc: gcc

>>>>> Alan Modra writes:

Alan> Oops, reg 145 has changed in the meantime at insn 41.  From what I can
Alan> tell, the REG_EQUAL notes in combination with the fact that the store
Alan> to "y" has been moved out of the loop by loop optimization, is the cause
Alan> of cse confusion.

Alan> So it seems a possible fix would be to delete all REG_EQUAL notes
Alan> that mention any mem hoisted out of a loop.  Before I try to do that,
Alan> I thought I'd solicit comments on the approach.  Reasonable?

	Sounds similar to a previous unroller bug I tracked down where a
REG_EQUAL note no longer was valid:

	http://gcc.gnu.org/ml/gcc-patches/2002-10/msg00269.html

David

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

* Re: REQ_EQUAL and mems hoisted out of loops
  2003-03-25 14:02 REQ_EQUAL and mems hoisted out of loops Alan Modra
  2003-03-25 18:27 ` David Edelsohn
@ 2003-03-26 10:36 ` Alan Modra
  2003-03-26 17:26   ` Matt Kraai
  2003-03-28  2:12   ` Richard Henderson
  1 sibling, 2 replies; 5+ messages in thread
From: Alan Modra @ 2003-03-26 10:36 UTC (permalink / raw)
  To: gcc, gcc-patches

On Tue, Mar 25, 2003 at 10:42:16PM +1030, Alan Modra wrote:
> Oops, reg 145 has changed in the meantime at insn 41.  From what I can
> tell, the REG_EQUAL notes in combination with the fact that the store
> to "y" has been moved out of the loop by loop optimization, is the cause
> of cse confusion.
> 
> So it seems a possible fix would be to delete all REG_EQUAL notes
> that mention any mem hoisted out of a loop.  Before I try to do that,
> I thought I'd solicit comments on the approach.  Reasonable?

This cures the failures.  Bootstrapped, regression tested powerpc-linux
and powerpc64-linux on 3.3 branch.  Currently testing on mainline.

	* loop.c: Include tree.h.
	(find_mem_in_note_1, find_mem_in_note): New functions.
	(load_mems): Remove invalid REG_EQUAL notes after hoisting.

OK?

Index: gcc/loop.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/loop.c,v
retrieving revision 1.448
diff -u -p -r1.448 loop.c
--- gcc/loop.c	15 Mar 2003 22:51:33 -0000	1.448
+++ gcc/loop.c	26 Mar 2003 08:40:23 -0000
@@ -39,6 +39,7 @@ Software Foundation, 59 Temple Place - S
 #include "coretypes.h"
 #include "tm.h"
 #include "rtl.h"
+#include "tree.h"
 #include "tm_p.h"
 #include "function.h"
 #include "expr.h"
@@ -328,6 +329,8 @@ static void update_reg_last_use PARAMS (
 static rtx next_insn_in_loop PARAMS ((const struct loop *, rtx));
 static void loop_regs_scan PARAMS ((const struct loop *, int));
 static int count_insns_in_loop PARAMS ((const struct loop *));
+static int find_mem_in_note_1 PARAMS ((rtx *, void *));
+static rtx find_mem_in_note PARAMS ((rtx));
 static void load_mems PARAMS ((const struct loop *));
 static int insert_loop_mem PARAMS ((rtx *, void *));
 static int replace_loop_mem PARAMS ((rtx *, void *));
@@ -9800,6 +9803,29 @@ count_insns_in_loop (loop)
   return count;
 }
 
+static int
+find_mem_in_note_1 (x, data)
+     rtx *x;
+     void *data;
+{
+  if (*x != NULL_RTX && GET_CODE (*x) == MEM)
+    {
+      rtx *res = (rtx *) data;
+      *res = *x;
+      return 1;
+    }
+  return 0;
+}
+
+static rtx
+find_mem_in_note (note)
+     rtx note;
+{
+  if (note && for_each_rtx (&note, find_mem_in_note_1, &note))
+    return note;
+  return NULL_RTX;
+}
+  
 /* Move MEMs into registers for the duration of the loop.  */
 
 static void
@@ -10130,6 +10156,25 @@ load_mems (loop)
 	       try_swap_copy_prop (loop, reg, j);
 	     });
 	  CLEAR_REG_SET (&store_copies);
+
+	  /* If we hoist a mem write out of the loop, then REG_EQUAL
+	     notes referring to the mem are no longer valid.  */
+	  if (written)
+	    {
+	      for (p = next_insn_in_loop (loop, loop->scan_start);
+		   p != NULL_RTX;
+		   p = next_insn_in_loop (loop, p))
+		{
+		  rtx note, sub;
+
+		  if (INSN_P (p)
+		      && (note = find_reg_note (p, REG_EQUAL, NULL_RTX))
+		      && (sub = find_mem_in_note (note))
+		      && alias_sets_conflict_p (MEM_ALIAS_SET (mem),
+						MEM_ALIAS_SET (sub)))
+		    remove_note (p, note);
+		}
+	    }
 	}
     }
 

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

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

* Re: REQ_EQUAL and mems hoisted out of loops
  2003-03-26 10:36 ` Alan Modra
@ 2003-03-26 17:26   ` Matt Kraai
  2003-03-28  2:12   ` Richard Henderson
  1 sibling, 0 replies; 5+ messages in thread
From: Matt Kraai @ 2003-03-26 17:26 UTC (permalink / raw)
  To: gcc, gcc-patches

On Wed, Mar 26, 2003 at 07:19:33PM +1030, Alan Modra wrote:
> 	* loop.c: Include tree.h.
> 	(find_mem_in_note_1, find_mem_in_note): New functions.
> 	(load_mems): Remove invalid REG_EQUAL notes after hoisting.

Would you please add $(TREE_H) to the dependencies of loop.o in
Makefile.in?

Matt
-- 
It's most certainly GNU/Linux, not Linux.  Read more at
http://www.gnu.org/gnu/why-gnu-linux.html.

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

* Re: REQ_EQUAL and mems hoisted out of loops
  2003-03-26 10:36 ` Alan Modra
  2003-03-26 17:26   ` Matt Kraai
@ 2003-03-28  2:12   ` Richard Henderson
  1 sibling, 0 replies; 5+ messages in thread
From: Richard Henderson @ 2003-03-28  2:12 UTC (permalink / raw)
  To: gcc, gcc-patches

On Wed, Mar 26, 2003 at 07:19:33PM +1030, Alan Modra wrote:
> 	(load_mems): Remove invalid REG_EQUAL notes after hoisting.

I think this is the wrong spot to handle this.
Do it in replace_loop_mems instead.


r~

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

end of thread, other threads:[~2003-03-27 23:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-25 14:02 REQ_EQUAL and mems hoisted out of loops Alan Modra
2003-03-25 18:27 ` David Edelsohn
2003-03-26 10:36 ` Alan Modra
2003-03-26 17:26   ` Matt Kraai
2003-03-28  2:12   ` Richard Henderson

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