PR middle-end/25121: [4.1/4.2 Regression] libgcj misscompilation? [Was Re: RFC: peephole vs RTX_FRAME_RELATED_P]

Andrew Haley aph@redhat.com
Tue Dec 20 11:40:00 GMT 2005


Richard Henderson writes:
 > On Mon, Dec 19, 2005 at 02:11:46PM -0800, Ian Lance Taylor wrote:
 > > I think an algorithm which should work fairly reliably in the general
 > > case is:
 > > 
 > >   1) Are there any old insns with RTX_FRAME_RELATED_P set?
 > >      If no, stop.
 > >   2) For each old insn with RTX_FRAME_RELATED_P set:
 > >      a) if insn has a REG_FRAME_RELATED_EXPR note, add it to the list;
 > >      b) otherwise, insn should be a PARALLEL or SEQUENCE or SET;
 > >         add the insn to the list.
 > >   3) Set RTX_FRAME_RELATED_P on last new insn.
 > >   4) If there is more than one entry on list, turn it into a PARALLEL
 > >      (see dwarf2out_frame_debug_expr).  Otherwise take first insn on
 > >      list.
 > >   5) Put the result of 4 in a REG_FRAME_RELATED_EXPR note on last new
 > >      insn.
 > 
 > I think that this is all complicated enough that we should
 > simply deny peepholing insns with RTX_FRAME_RELATED_P set.
 > 
 > You'll note, for instance, that while we got results that
 > were partially correct in the transformation, in that we
 > recoginize that the cfa is at offset 16, we don't recognize
 > that we shouldn't be generating a store of reg 0 in the 
 > state machine.

With my new patch, we get this result:

00a329f8 <java.lang.Throwable.Throwable(java.lang.String)>:
  a329f8:       56                      push   %esi
  a329f9:       53                      push   %ebx
  a329fa:       83 ec 04                sub    $0x4,%esp

00059464 00000020 000328e4 FDE cie=00026b84 pc=00a329f8..00a32a30
  Augmentation data:     00 00 00 00

  DW_CFA_advance_loc: 1 to 00a329f9
  DW_CFA_def_cfa_offset: 8
  DW_CFA_advance_loc: 1 to 00a329fa
  DW_CFA_def_cfa_offset: 12
  DW_CFA_advance_loc: 3 to 00a329fd
  DW_CFA_def_cfa_offset: 16
  DW_CFA_offset: r3 at cfa-12
  DW_CFA_offset: r6 at cfa-8

Bootstrapped gcc-4_1-branch i386-linux-gnu.  OK for branch/mainline?

Andrew.


2005-12-20  Andrew Haley  <aph@redhat.com>

	PR middle-end/25121
	* recog.c (peephole2_optimize): Don't peephole any
	RTX_FRAME_RELATED_P insns.

Index: recog.c
===================================================================
--- recog.c	(revision 108424)
+++ recog.c	(working copy)
@@ -3079,6 +3079,10 @@
       reg_set_iterator rsi;
       unsigned int j;
 
+      /* The distance between the current insn and the last
+	 RTX_FRAME_RELATED_P insn we saw.  */
+      int frame_related_distance = 0;
+
       /* Indicate that all slots except the last holds invalid data.  */
       for (i = 0; i < MAX_INSNS_PER_PEEP2; ++i)
 	peep2_insn_data[i].insn = NULL_RTX;
@@ -3108,6 +3112,8 @@
 	      rtx note;
 	      bool was_call = false;
 
+	      frame_related_distance++;
+
 	      /* Record this insn.  */
 	      if (--peep2_current < 0)
 		peep2_current = MAX_INSNS_PER_PEEP2;
@@ -3120,7 +3126,12 @@
 
 	      /* Match the peephole.  */
 	      try = peephole2_insns (PATTERN (insn), insn, &match_len);
-	      if (try != NULL)
+
+	      if (RTX_FRAME_RELATED_P (insn))
+		frame_related_distance = 0;
+
+	      /* Don't replace sequences with FRAME_RELATED_P insns.  */
+	      if (try != NULL && match_len < frame_related_distance)
 		{
 		  /* If we are splitting a CALL_INSN, look for the CALL_INSN
 		     in SEQ and copy our CALL_INSN_FUNCTION_USAGE and other



More information about the Java mailing list