This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] for PR 19937
- From: Zdenek Dvorak <rakdver at atrey dot karlin dot mff dot cuni dot cz>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 13 Feb 2005 23:20:00 +0100
- Subject: [patch] for PR 19937
Hello,
in case original induction variable is used in exit condition,
we compare it with the unsigned final value. This may be wrong
if the variable is signed. This patch adds the necessary cast
of the final value.
The problem was uncovered by the patch to avoid producing iv increments
of form i = (int) ((unsigned) i + 1), probably due to one of the
optimizers no longer propagating the unsigned value to the comparison.
Bootstrapped & regtested on i686.
Zdenek
PR tree-optimization/19937
* tree-ssa-loop-ivopts.c (rewrite_use_compare): Cast the final value
to the type of the induction variable.
Index: tree-ssa-loop-ivopts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-loop-ivopts.c,v
retrieving revision 2.47
diff -c -3 -p -r2.47 tree-ssa-loop-ivopts.c
*** tree-ssa-loop-ivopts.c 10 Feb 2005 20:13:20 -0000 2.47
--- tree-ssa-loop-ivopts.c 13 Feb 2005 19:39:59 -0000
*************** rewrite_use_compare (struct ivopts_data
*** 4877,4891 ****
if (may_eliminate_iv (data, use, cand, &compare, &bound))
{
op = force_gimple_operand (unshare_expr (bound), &stmts,
true, NULL_TREE);
if (stmts)
bsi_insert_before (&bsi, stmts, BSI_SAME_STMT);
! *use->op_p = build2 (compare, boolean_type_node,
! var_at_stmt (data->current_loop,
! cand, use->stmt), op);
modify_stmt (use->stmt);
return;
}
--- 4877,4893 ----
if (may_eliminate_iv (data, use, cand, &compare, &bound))
{
+ tree var = var_at_stmt (data->current_loop, cand, use->stmt);
+ tree var_type = TREE_TYPE (var);
+
+ bound = fold_convert (var_type, bound);
op = force_gimple_operand (unshare_expr (bound), &stmts,
true, NULL_TREE);
if (stmts)
bsi_insert_before (&bsi, stmts, BSI_SAME_STMT);
! *use->op_p = build2 (compare, boolean_type_node, var, op);
modify_stmt (use->stmt);
return;
}