[PATCH] Fix PR36691, wrong-code with wrong # of iterations
Richard Guenther
rguenther@suse.de
Mon Aug 4 18:32:00 GMT 2008
On Mon, 4 Aug 2008, Zdenek Dvorak wrote:
> Hi,
>
> > This fixes PR36691 where we wrongly skip generation of assumptions
> > for non-wrapping of the induction variable.
> >
> > Bootstrapped and tested on x86_64-unknown-linux-gnu - Zdenek, does this
> > look ok?
>
> yes, thanks for fixing this. Although,
>
> > *************** number_of_iterations_lt_to_ne (tree type
> > *** 692,703 ****
> > mpz_set_double_int (mmod, tree_to_double_int (mod), true);
> > mpz_neg (mmod, mmod);
> >
> > if (integer_nonzerop (iv0->step))
> > {
> > /* The final value of the iv is iv1->base + MOD, assuming that this
> > computation does not overflow, and that
> > iv0->base <= iv1->base + MOD. */
> > ! if (!iv1->no_overflow && !integer_zerop (mod))
> > {
> > bound = fold_build2 (MINUS_EXPR, type,
> > TYPE_MAX_VALUE (type1), tmod);
>
> it might be better to just fix the tests and check iv0->no_overflow here
> (since iv1->step == 0, it does not make sense to check whether it
> overflows),
>
> > *************** number_of_iterations_lt_to_ne (tree type
> > *** 719,725 ****
> > /* The final value of the iv is iv0->base - MOD, assuming that this
> > computation does not overflow, and that
> > iv0->base - MOD <= iv1->base. */
> > ! if (!iv0->no_overflow && !integer_zerop (mod))
> > {
> > bound = fold_build2 (PLUS_EXPR, type1,
> > TYPE_MIN_VALUE (type1), tmod);
>
> and iv1->no_overflow here.
Ok. I didn't realize one of them is always zero.
So the following is what I applied after re-testing.
Thanks,
Richard.
2008-08-04 Richard Guenther <rguenther@suse.de>
PR middle-end/36691
* tree-ssa-loop-niter.c (number_of_iterations_lt_to_ne): Correctly
check for no_overflow.
* gcc.c-torture/execute/pr36691.c: New testcase.
Index: gcc/testsuite/gcc.c-torture/execute/pr36691.c
===================================================================
*** gcc/testsuite/gcc.c-torture/execute/pr36691.c (revision 0)
--- gcc/testsuite/gcc.c-torture/execute/pr36691.c (revision 0)
***************
*** 0 ****
--- 1,17 ----
+ unsigned char g_5;
+
+ void func_1 (void)
+ {
+ for (g_5 = 9; g_5 >= 4; g_5 -= 5)
+ ;
+ }
+
+ extern void abort (void);
+ int main (void)
+ {
+ func_1 ();
+ if (g_5 != 0)
+ abort ();
+ return 0;
+ }
+
Index: gcc/tree-ssa-loop-niter.c
===================================================================
*** gcc/tree-ssa-loop-niter.c (revision 138620)
--- gcc/tree-ssa-loop-niter.c (working copy)
*************** number_of_iterations_lt_to_ne (tree type
*** 697,703 ****
/* The final value of the iv is iv1->base + MOD, assuming that this
computation does not overflow, and that
iv0->base <= iv1->base + MOD. */
! if (!iv1->no_overflow && !integer_zerop (mod))
{
bound = fold_build2 (MINUS_EXPR, type,
TYPE_MAX_VALUE (type1), tmod);
--- 697,703 ----
/* The final value of the iv is iv1->base + MOD, assuming that this
computation does not overflow, and that
iv0->base <= iv1->base + MOD. */
! if (!iv0->no_overflow && !integer_zerop (mod))
{
bound = fold_build2 (MINUS_EXPR, type,
TYPE_MAX_VALUE (type1), tmod);
*************** number_of_iterations_lt_to_ne (tree type
*** 719,725 ****
/* The final value of the iv is iv0->base - MOD, assuming that this
computation does not overflow, and that
iv0->base - MOD <= iv1->base. */
! if (!iv0->no_overflow && !integer_zerop (mod))
{
bound = fold_build2 (PLUS_EXPR, type1,
TYPE_MIN_VALUE (type1), tmod);
--- 719,725 ----
/* The final value of the iv is iv0->base - MOD, assuming that this
computation does not overflow, and that
iv0->base - MOD <= iv1->base. */
! if (!iv1->no_overflow && !integer_zerop (mod))
{
bound = fold_build2 (PLUS_EXPR, type1,
TYPE_MIN_VALUE (type1), tmod);
More information about the Gcc-patches
mailing list