From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Hayes To: mark@markmitchell.com Cc: m.hayes@elec.canterbury.ac.nz, toon@moene.indiv.nluug.nl, law@cygnus.com, egcs@cygnus.com Subject: Re: Re-run of loop pass Date: Sun, 18 Oct 1998 18:52:00 -0000 Message-id: <13866.22547.705620.883607@ongaonga.elec.canterbury.ac.nz> References: <13865.9178.455954.70561"@ongaonga.elec.canterbury.ac.nz> <18798.908694891@hurl.cygnus.com> <13865.44885.953349.460182@ongaonga.elec.canterbury.ac.nz> <199810181824.LAA30178@smtp.earthlink.net> X-SW-Source: 1998-10/msg00711.html Mark Mitchell writes: > Or the second pass could learn to recongize some of these idioms. > For example, you seem to imply that if I write: > > int* i; > int* j; > for (i = j ; i < j + 4; ++j) > ; > > say, that loop can't figure out the number of iterations. A little > algebra might be helpful here, since this is a reasonably common > idiom, especially in C++ using STL, and especially where `4' is > replaced by `k'. So much so that if no-one else does this, I'll > probably get around to it. OK, this patch (with maybe a little strengthening) should handle the very simple case. Index: unroll.c =================================================================== RCS file: /egcs/carton/cvsfiles/egcs/gcc/unroll.c,v retrieving revision 1.32 diff -c -3 -p -r1.32 unroll.c *** unroll.c 1998/10/14 09:02:52 1.32 --- unroll.c 1998/10/18 22:02:59 *************** loop_iterations (loop_start, loop_end) *** 3499,3504 **** --- 3499,3508 ---- if (note && GET_CODE (XEXP (note, 0)) != EXPR_LIST && CONSTANT_P (XEXP (note, 0))) comparison_value = XEXP (note, 0); + /* May have to check that we have the sum of a register + and a constant. */ + else if (GET_CODE (SET_SRC (set)) == PLUS) + comparison_value = SET_SRC (set); } break; } *************** loop_iterations (loop_start, loop_end) *** 3535,3544 **** } else if (GET_CODE (initial_value) != CONST_INT) { ! if (loop_dump_stream) ! fprintf (loop_dump_stream, ! "Loop unrolling: Initial value not constant.\n"); ! return 0; } else if (final_value == 0) { --- 3539,3559 ---- } else if (GET_CODE (initial_value) != CONST_INT) { ! if (REG_P (initial_value) ! && GET_CODE (final_value) == PLUS ! && XEXP (final_value, 0) == initial_value ! && CONSTANT_P (XEXP (final_value, 1))) ! { ! initial_value = const0_rtx; ! final_value = XEXP (final_value, 1); ! } ! else ! { ! if (loop_dump_stream) ! fprintf (loop_dump_stream, ! "Loop unrolling: Initial value not constant.\n"); ! return 0; ! } } else if (final_value == 0) {