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] for PR 22348


Hello,

let me first note that this patch does not really fix the problem
causing the PR, but introduces an useful change that masks the problem.

This PR is caused by fold incorrectly simplifying (x - 7) FLOOR_MOD_EXPR
3 to x FLOOR_MOD_EXPR 3 (x is unsigned).  The reason for this behavior
is that fold first replaces (x - 7) by (x + ~6), and ~6 is divisible by
3 -- a check for overflow is missing somewhere in extract_muldiv;
I did not have time to determine precisely where.

Nevertheless, in the PR the problem is exposed because we try to fold
(51 - 7) %[fl] 3.  Creation of this expression can be prevented by
folding the expression after the subtraction, as done by the patch.

Bootstrapped & regtested on i686.

Zdenek

	PR tree-optimize/22348
	* tree-ssa-loop-niter.c (number_of_iterations_cond):
	Fold the partial computation.

Index: tree-ssa-loop-niter.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-loop-niter.c,v
retrieving revision 2.32
diff -c -3 -p -r2.32 tree-ssa-loop-niter.c
*** tree-ssa-loop-niter.c       28 Jun 2005 00:52:25 -0000      2.32
--- tree-ssa-loop-niter.c       15 Jul 2005 09:45:01 -0000
*************** number_of_iterations_cond (tree type, tr
*** 273,279 ****
        step = fold_unary_to_constant (NEGATE_EXPR, type, step1);
        else
        step = step0;
!       delta = build2 (MINUS_EXPR, type, base1, base0);
        delta = fold_build2 (FLOOR_MOD_EXPR, type, delta, step);
        may_xform = boolean_false_node;

--- 273,279 ----
        step = fold_unary_to_constant (NEGATE_EXPR, type, step1);
        else
        step = step0;
!       delta = fold_build2 (MINUS_EXPR, type, base1, base0);
        delta = fold_build2 (FLOOR_MOD_EXPR, type, delta, step);
        may_xform = boolean_false_node;


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