Commit e233ac97 by Ian Lance Taylor Committed by Ian Lance Taylor

re PR tree-optimization/33565 (spurious warning: assuming signed overflow does…

re PR tree-optimization/33565 (spurious  warning: assuming signed overflow does not occur when assuming that (X + c) >= X is always true)

./:	PR tree-optimization/33565
	* tree-ssa-loop-ch.c (copy_loop_headers): Set TREE_NO_WARNING on
	assignments of comparisons.
	* tree-ssa-sccvn.c (simplify_binary_expression): Add stmt
	parameter.  Change caller.  Defer overflow warnings around call to
	fold_binary.
	* fold-const.c (fold_undefer_overflow_warnings): Don't warn if
	TREE_NO_WARNING is set on the statement.
	* tree-ssa-forwprop.c
	(tree_ssa_forward_propagate_single_use_vars): Don't test
	TREE_NO_WARNING when calling fold_undefer_overflow_warnings.
	* tree-cfg.c (fold_cond_expr_cond): Likewise.
testsuite/:
	PR tree-optimization/33565
	* gcc.dg/Wstrict-overflow-20.c: New test.

From-SVN: r128840
parent c3048783
2007-09-27 Ian Lance Taylor <iant@google.com>
PR tree-optimization/33565
* tree-ssa-loop-ch.c (copy_loop_headers): Set TREE_NO_WARNING on
assignments of comparisons.
* tree-ssa-sccvn.c (simplify_binary_expression): Add stmt
parameter. Change caller. Defer overflow warnings around call to
fold_binary.
* fold-const.c (fold_undefer_overflow_warnings): Don't warn if
TREE_NO_WARNING is set on the statement.
* tree-ssa-forwprop.c
(tree_ssa_forward_propagate_single_use_vars): Don't test
TREE_NO_WARNING when calling fold_undefer_overflow_warnings.
* tree-cfg.c (fold_cond_expr_cond): Likewise.
2007-09-27 Joseph Myers <joseph@codesourcery.com> 2007-09-27 Joseph Myers <joseph@codesourcery.com>
* config/rs6000/rs6000.c (rs6000_legitimize_address): Do not * config/rs6000/rs6000.c (rs6000_legitimize_address): Do not
...@@ -974,6 +974,9 @@ fold_undefer_overflow_warnings (bool issue, const_tree stmt, int code) ...@@ -974,6 +974,9 @@ fold_undefer_overflow_warnings (bool issue, const_tree stmt, int code)
if (!issue || warnmsg == NULL) if (!issue || warnmsg == NULL)
return; return;
if (stmt != NULL_TREE && TREE_NO_WARNING (stmt))
return;
/* Use the smallest code level when deciding to issue the /* Use the smallest code level when deciding to issue the
warning. */ warning. */
if (code == 0 || code > (int) fold_deferred_overflow_code) if (code == 0 || code > (int) fold_deferred_overflow_code)
......
2007-09-27 Ian Lance Taylor <iant@google.com>
PR tree-optimization/33565
* gcc.dg/Wstrict-overflow-20.c: New test.
2007-09-27 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org> 2007-09-27 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
* gfortran.dg/openmp_stack.f90: Fix typo. * gfortran.dg/openmp_stack.f90: Fix typo.
/* { dg-do compile } */
/* { dg-options "-fstrict-overflow -O2 -Wstrict-overflow" } */
/* Don't warn about an overflow in a copied loop header. We used to
get a warning in value numbering. This is PR 33565. */
void f (int m, int n)
{
int j;
for (j = m; j < m + 10 && j < n; j ++)
do_something (j);
}
...@@ -417,8 +417,7 @@ fold_cond_expr_cond (void) ...@@ -417,8 +417,7 @@ fold_cond_expr_cond (void)
cond = fold (COND_EXPR_COND (stmt)); cond = fold (COND_EXPR_COND (stmt));
zerop = integer_zerop (cond); zerop = integer_zerop (cond);
onep = integer_onep (cond); onep = integer_onep (cond);
fold_undefer_overflow_warnings (((zerop || onep) fold_undefer_overflow_warnings (zerop || onep,
&& !TREE_NO_WARNING (stmt)),
stmt, stmt,
WARN_STRICT_OVERFLOW_CONDITIONAL); WARN_STRICT_OVERFLOW_CONDITIONAL);
if (zerop) if (zerop)
......
...@@ -1021,8 +1021,7 @@ tree_ssa_forward_propagate_single_use_vars (void) ...@@ -1021,8 +1021,7 @@ tree_ssa_forward_propagate_single_use_vars (void)
did_something = forward_propagate_into_cond (stmt, stmt); did_something = forward_propagate_into_cond (stmt, stmt);
if (did_something == 2) if (did_something == 2)
cfg_changed = true; cfg_changed = true;
fold_undefer_overflow_warnings (!TREE_NO_WARNING (stmt) fold_undefer_overflow_warnings (did_something, stmt,
&& did_something, stmt,
WARN_STRICT_OVERFLOW_CONDITIONAL); WARN_STRICT_OVERFLOW_CONDITIONAL);
bsi_next (&bsi); bsi_next (&bsi);
} }
......
...@@ -215,11 +215,22 @@ copy_loop_headers (void) ...@@ -215,11 +215,22 @@ copy_loop_headers (void)
for (i = 0; i < n_bbs; ++i) for (i = 0; i < n_bbs; ++i)
{ {
tree last; block_stmt_iterator bsi;
last = last_stmt (copied_bbs[i]); for (bsi = bsi_start (copied_bbs[i]);
if (TREE_CODE (last) == COND_EXPR) !bsi_end_p (bsi);
TREE_NO_WARNING (last) = 1; bsi_next (&bsi))
{
tree stmt = bsi_stmt (bsi);
if (TREE_CODE (stmt) == COND_EXPR)
TREE_NO_WARNING (stmt) = 1;
else if (TREE_CODE (stmt) == GIMPLE_MODIFY_STMT)
{
tree rhs = GIMPLE_STMT_OPERAND (stmt, 1);
if (COMPARISON_CLASS_P (rhs))
TREE_NO_WARNING (stmt) = 1;
}
}
} }
} }
......
...@@ -1390,7 +1390,7 @@ valueize_expr (tree expr) ...@@ -1390,7 +1390,7 @@ valueize_expr (tree expr)
simplified. */ simplified. */
static tree static tree
simplify_binary_expression (tree rhs) simplify_binary_expression (tree stmt, tree rhs)
{ {
tree result = NULL_TREE; tree result = NULL_TREE;
tree op0 = TREE_OPERAND (rhs, 0); tree op0 = TREE_OPERAND (rhs, 0);
...@@ -1421,8 +1421,13 @@ simplify_binary_expression (tree rhs) ...@@ -1421,8 +1421,13 @@ simplify_binary_expression (tree rhs)
&& op1 == TREE_OPERAND (rhs, 1)) && op1 == TREE_OPERAND (rhs, 1))
return NULL_TREE; return NULL_TREE;
fold_defer_overflow_warnings ();
result = fold_binary (TREE_CODE (rhs), TREE_TYPE (rhs), op0, op1); result = fold_binary (TREE_CODE (rhs), TREE_TYPE (rhs), op0, op1);
fold_undefer_overflow_warnings (result && valid_gimple_expression_p (result),
stmt, 0);
/* Make sure result is not a complex expression consisting /* Make sure result is not a complex expression consisting
of operators of operators (IE (a + b) + (a + c)) of operators of operators (IE (a + b) + (a + c))
Otherwise, we will end up with unbounded expressions if Otherwise, we will end up with unbounded expressions if
...@@ -1522,7 +1527,7 @@ try_to_simplify (tree stmt, tree rhs) ...@@ -1522,7 +1527,7 @@ try_to_simplify (tree stmt, tree rhs)
break; break;
case tcc_comparison: case tcc_comparison:
case tcc_binary: case tcc_binary:
return simplify_binary_expression (rhs); return simplify_binary_expression (stmt, rhs);
break; break;
default: default:
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment