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: Reenable doloop recognition when preconditioned


This patch

2002-06-24 Alan Modra <amodra@bigpond.net.au>

* doloop.c (doloop_valid_p): Correct comment.
(doloop_modify_runtime <abs_inc != 1>): Simplify.
(doloop_modify_runtime <do-while>): Don't emit code when NE.

disables the doloop optimization when the final test is NE. This is
correct in general, but in the case where the loop was unrolled and
preconditioned, we know that the loop does terminate and NE is OK.
When running the loop optimizer twice, the loop_info->preconditioned bit
is available only on the first pass; so this patch also adds a
mechanism to preserve it for the second pass, by keeping it in the
unused word 4 of the NOTE_INSN_LOOP_END node.

2002-09-19 Dale Johannesen <dalej@apple.com>
* rtl.h: Add NOTE_PRECONDITIONED.
* unroll.c: Set it.
* loop.c: Set loop_info->preconditioned from it.
* doloop.c: Permit doloop treatment when loop_info->preconditioned.

/* Make sure the loop is recognized as a doloop,
even after unrolling. If so, "bdnz" will be g
enerated on ppc; if not, you will get "ble". */

/* { dg-do compile { target powerpc-*-* } } */
/* { dg-options "-O2 -funroll-loops" } */
int foo(int size) {
int k = 1, i;
for ( i=0; i<size; i++ )
k *= 42;
return k;
}

Attachment: diffs
Description: Binary data


Index: loop.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/loop.c,v
retrieving revision 1.425
diff -u -d -b -w -c -3 -p -r1.425 loop.c
*** loop.c 16 Sep 2002 16:36:32 -0000 1.425
--- loop.c 23 Sep 2002 19:55:38 -0000
*************** prescan_loop (loop)
*** 2475,2481 ****
loop_info->first_loop_store_insn = NULL_RTX;
loop_info->mems_idx = 0;
loop_info->num_mem_sets = 0;
!

for (insn = start; insn && GET_CODE (insn) != CODE_LABEL;
insn = PREV_INSN (insn))
--- 2475,2482 ----
loop_info->first_loop_store_insn = NULL_RTX;
loop_info->mems_idx = 0;
loop_info->num_mem_sets = 0;
! /* If loop opts run twice, this was set on 1st pass for 2nd. */
! loop_info->preconditioned = NOTE_PRECONDITIONED (end);

for (insn = start; insn && GET_CODE (insn) != CODE_LABEL;
insn = PREV_INSN (insn))
Index: unroll.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/unroll.c,v
retrieving revision 1.176
diff -u -d -b -w -c -3 -p -r1.176 unroll.c
*** unroll.c 8 Sep 2002 18:32:31 -0000 1.176
--- unroll.c 23 Sep 2002 19:55:38 -0000
*************** unroll_loop (loop, insn_count, strength_
*** 1137,1142 ****
--- 1137,1145 ----
/* And whether the loop has been preconditioned. */
loop_info->preconditioned = loop_preconditioned;

+ /* Remember whether it was preconditioned for the second loop pass. */
+ NOTE_PRECONDITIONED (loop->end) = loop_preconditioned;
+
/* For each biv and giv, determine whether it can be safely split into
a different variable for each unrolled copy of the loop body.
We precalculate and save this info here, since computing it is
Index: rtl.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/rtl.h,v
retrieving revision 1.369
diff -u -d -b -w -c -3 -p -r1.369 rtl.h
*** rtl.h 16 Sep 2002 18:33:19 -0000 1.369
--- rtl.h 23 Sep 2002 19:55:39 -0000
*************** extern const char * const reg_note_name[
*** 787,792 ****
--- 787,793 ----
#define NOTE_BASIC_BLOCK(INSN) XCBBDEF (INSN, 4, NOTE)
#define NOTE_EXPECTED_VALUE(INSN) XCEXP (INSN, 4, NOTE)
#define NOTE_PREDICTION(INSN) XCINT (INSN, 4, NOTE)
+ #define NOTE_PRECONDITIONED(INSN) XCINT (INSN, 4, NOTE)

/* In a NOTE that is a line number, this is the line number.
Other kinds of NOTEs are identified by negative numbers here. */
Index: doloop.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doloop.c,v
retrieving revision 1.22
diff -u -d -b -w -c -3 -p -r1.22 doloop.c
*** doloop.c 16 Sep 2002 11:41:58 -0000 1.22
--- doloop.c 23 Sep 2002 19:55:39 -0000
*************** doloop_valid_p (loop, jump_insn)
*** 339,344 ****
--- 339,345 ----
condition at run-time and have an additional jump around the loop
to ensure an infinite loop. */
if (loop_info->comparison_code == NE
+ && !loop_info->preconditioned
&& INTVAL (loop_info->increment) != -1
&& INTVAL (loop_info->increment) != 1)
{

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