This is the mail archive of the 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] PR middle-end/11414: Clean-up loop.c's load_mems.

The following patch cleans up and improves the performance of load_mems,
and I also believe resolves PR middle-end/11414, a bootstrap failure
building Ada on PA/HP-UX.

As we all know, much of the code in the old loop unroller is reaching
the end of it's shelf-life, written long before much of GCC's current
infrastructure to support such tasks was added.  One excellent example,
is the final loop in load_mems which simply redirects all conditional
and unconditional branches out of the loop from the old loop exit, to
the new block into which loads have been sunk.  In modern era of CFGs
and edge splitting such a task seems trivial, however back in the day
this used to be done by calling for_each_rtx on every insn in the loop!
How quaint.

The patch below brings this code into the 21st century, by calling
redirect_jump on each JUMP_INSN in the loop.  The code above that
analyses the loop has already rejected loops containing indirect
branches, so the only references to the loop's end label are guaranteed
to be in the remaining branch instructions.  Not only does this speed
up the process, but has the added benefit that redirect_jump also
does the additional work of updating the notes on the modified jumps.
Failure PR 11414 is caused because these notes weren't being updated.

I believe that this is one of the last places in the compiler where we
try redirecting control flow by hand rather than use the functionality
by jump.c and friends.

Although an earlier version of this patch solved PR middle-end/11414,
another recent breakage (web splitting) means that David Anglin can't
currently reconfirm that this particular patch still fixes things on PA.
We can leave the PR open for the time being.  However the clean-up and
performance improving nature of this patch should be merit enough to
post it for review.  PR middle-end/11414 is targeted for 3.4.

The following patch has been tested on i686-pc-linux-gnu with a complete
"make bootstrap", all languages except treelang, and regression tested
with a top-level "make -k check" with no new failures.

Ok for mainline?

2003-10-19  Roger Sayle  <>

	PR middle-end/11414
	* loop.c (load_mems): Use redirect_jump to forward jumps from
	the original loop end label to the new "loop sink" block's label.

Index: loop.c
RCS file: /cvs/gcc/gcc/gcc/loop.c,v
retrieving revision 1.473
diff -c -3 -p -r1.473 loop.c
*** loop.c	5 Oct 2003 19:50:54 -0000	1.473
--- loop.c	19 Oct 2003 20:24:43 -0000
*************** load_mems (const struct loop *loop)
*** 10005,10024 ****

    if (label != NULL_RTX && end_label != NULL_RTX)
!     {
!       /* Now, we need to replace all references to the previous exit
! 	 label with the new one.  */
!       replace_label_data rr;
!       rr.r1 = end_label;
!       rr.r2 = label;
!       rr.update_label_nuses = true;
!       for (p = loop->start; p != loop->end; p = NEXT_INSN (p))
! 	{
! 	  for_each_rtx (&p, replace_label, &rr);
! 	}
!     }

    cselib_finish ();
--- 10005,10016 ----

+   /* Now, we need to replace all references to the previous exit
+      label with the new one.  */
    if (label != NULL_RTX && end_label != NULL_RTX)
!     for (p = loop->start; p != loop->end; p = NEXT_INSN (p))
!       if (GET_CODE (p) == JUMP_INSN && JUMP_LABEL (p) == end_label)
! 	redirect_jump (p, label, false);

    cselib_finish ();

Roger Sayle,                         E-mail:
OpenEye Scientific Software,         WWW:
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833

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