Zdenek Dvorak - Re: [patch] (-fstrict-overflow) optimize counted loops on signed iv (original) (raw)

This is the mail archive of the gcc-patches@gcc.gnu.orgmailing 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]

Hello,

This allows to optimize loops like : for (i = start; i <= start+1; i++) ...

I sort of do not understand why you need this change. fold is (or should be) able to derive that start < start + 1, if the computation is performed in TYPE_OVERFLOW_UNDEFINED type.

Index: gcc/tree-ssa-loop-niter.c

--- gcc/tree-ssa-loop-niter.c (.../vendor/tags/4.3.20070209) (revision 77) +++ gcc/tree-ssa-loop-niter.c (.../branches/4.3_devs_loop_overflow) (revision 77) @@ -169,6 +169,80 @@ return true; }

+/* Checks whether the number of iterations is a constant value if iv1 is relative

you want to check opb0 == opb1, here. Or more likely, not to check that opb0 and opb1 are ssa names, and just use operand_equal_p

/* Checks whether we can determine the final value of the control variable of the loop with ending condition IV0 < IV1 (computed in TYPE). DELTA is the difference IV1->base - IV0->base, STEP is the absolute value @@ -236,7 +310,8 @@ niter->assumptions = fold_build2 (TRUTH_AND_EXPR, boolean_type_node, niter->assumptions, assumption);

@@ -367,7 +442,8 @@ if (!integer_nonzerop (assumption)) niter->assumptions = fold_build2 (TRUTH_AND_EXPR, boolean_type_node, niter->assumptions, assumption);

} @@ -413,8 +489,9 @@

  In both cases # of iterations is iv1->base - iv0->base, assuming that
  iv1->base >= iv0->base.  */

Nevertheless, this looks just wrong. relative_count_iv does not compare the relative values of the bases of the induction variables, hence this would also make you eliminate the the may_be_zero assumptions in cases like

for (i = a + 17; i < a + 5; i++)

which is obviously wrong.

Zdenek


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