Hello, > Since we didn't fail on assert in doloop_modify despite the hack in > doloop_condition_get (removal of the condition check), I just restored the > doloop_condition_get to it's original state and defined instead a new > function called sms_condition_get which is a copy of doloop_condition_get > with the hack. I also replaced the use of doloop_condition_get in > modulo-sched.c/doloop_register_get with sms_condition_get - this became the > only use of sms_condition_get. We SMS unrolled loops just fine with this > change. Can this be not safe?
this is safe, but it is an ugly hack. I guess we may accept it for the moment if you have some other patches depending on it, assuming of course that you plan to fix the problem properly (make SMS use # of iterations analysis) as soon as possible. Zdenek > Thanks, > Vladimir > > ------------------------------------------------------------------------- > Index: cfgloop.h > =================================================================== > --- cfgloop.h (revision 801) > +++ cfgloop.h (working copy) > @@ -290,6 +290,7 @@ > extern bool just_once_each_iteration_p (const struct loop *, basic_block); > extern unsigned expected_loop_iterations (const struct loop *); > extern rtx doloop_condition_get (rtx); > +extern rtx sms_condition_get (rtx); > > /* Loop manipulation. */ > extern bool can_duplicate_loop_p (struct loop *loop); > Index: loop-doloop.c > =================================================================== > --- loop-doloop.c (revision 801) > +++ loop-doloop.c (working copy) > @@ -154,7 +154,94 @@ > > return 0; > } > +/* Return the loop termination condition for PATTERN or zero > + if it is not a decrement and branch jump insn. */ > > +rtx > +sms_condition_get (rtx doloop_pat) > +{ > + rtx cmp; > + rtx inc; > + rtx reg; > + rtx inc_src; > + rtx condition; > + rtx pattern; > + > + /* The canonical doloop pattern we expect is: > + > + (parallel [(set (pc) (if_then_else (condition) > + (label_ref (label)) > + (pc))) > + (set (reg) (plus (reg) (const_int -1))) > + (additional clobbers and uses)]) > + > + Some targets (IA-64) wrap the set of the loop counter in > + an if_then_else too. > + > + In summary, the branch must be the first entry of the > + parallel (also required by jump.c), and the second > + entry of the parallel must be a set of the loop counter > + register. */ > + > + pattern = PATTERN (doloop_pat); > + if (GET_CODE (pattern) != PARALLEL) > + { > + cmp = pattern; > + inc = PATTERN (PREV_INSN (doloop_pat)); > + } > + else > + { > + cmp = XVECEXP (pattern, 0, 0); > + inc = XVECEXP (pattern, 0, 1); > + } > + > + /* Check for (set (reg) (something)). */ > + if (GET_CODE (inc) != SET) > + return 0; > + reg = SET_DEST (inc); > + if (! REG_P (reg)) > + return 0; > + > + /* Check if something = (plus (reg) (const_int -1)). > + On IA-64, this decrement is wrapped in an if_then_else. */ > + inc_src = SET_SRC (inc); > + if (GET_CODE (inc_src) == IF_THEN_ELSE) > + inc_src = XEXP (inc_src, 1); > + if (GET_CODE (inc_src) != PLUS > + || XEXP (inc_src, 0) != reg > + || XEXP (inc_src, 1) != constm1_rtx) > + return 0; > + > + /* Check for (set (pc) (if_then_else (condition) > + (label_ref (label)) > + (pc))). */ > + if (GET_CODE (cmp) != SET > + || SET_DEST (cmp) != pc_rtx > + || GET_CODE (SET_SRC (cmp)) != IF_THEN_ELSE > + || GET_CODE (XEXP (SET_SRC (cmp), 1)) != LABEL_REF > + || XEXP (SET_SRC (cmp), 2) != pc_rtx) > + return 0; > + > + /* Extract loop termination condition. */ > + condition = XEXP (SET_SRC (cmp), 0); > + > + /* We expect a GE or NE comparison with 0 or 1. */ > + if (/*(GET_CODE (condition) != GE > + && GET_CODE (condition) != NE) > + ||*/ (XEXP (condition, 1) != const0_rtx > + && XEXP (condition, 1) != const1_rtx)) > + return 0; > + > + if ((XEXP (condition, 0) == reg) > + || (GET_CODE (XEXP (condition, 0)) == PLUS > + && XEXP (XEXP (condition, 0), 0) == reg)) > + return condition; > + > + /* ??? If a machine uses a funny comparison, we could return a > + canonicalized form here. */ > + > + return 0; > +} > /* Return nonzero if the loop specified by LOOP is suitable for > the use of special low-overhead looping instructions. DESC > describes the number of iterations of the loop. */ > Index: modulo-sched.c > =================================================================== > --- modulo-sched.c (revision 840) > +++ modulo-sched.c (working copy) > @@ -288,7 +288,7 @@ > if (!INSN_P (PREV_INSN (insn))) > return NULL_RTX; > > - condition = doloop_condition_get (insn); > + condition = sms_condition_get (insn); > if (! condition) > return NULL_RTX; > > > > > > > On 6/30/07, Zdenek Dvorak <[EMAIL PROTECTED]> wrote: > > > >Hello, > > > >> It doesn't seem that the number of iterations analysis from > >loop-iv.cdeals > >> with EQ closing branches. > > > >loop-iv works just fine for EQ closing branches. > > > >Zdenek > > > >> One option is for sms to use > >> doloop_condition_get/loop-iv analysis in their current form, and if > >failed > >> check (on our own) for reversed doloop patterns. Another is to try and > >> reverse the closing branch before calling doloop_condition_get/loop-iv > >> analysis; any suitable branch reversal facility available? > >> > >> Ayal. > >