Commit 8e1ca098 by Richard Henderson Committed by Richard Henderson

fold-const.c (extract_muldiv): Apply type check for defined overflow to multiply as well as divide.

        * fold-const.c (extract_muldiv): Apply type check for defined
        overflow to multiply as well as divide.

From-SVN: r32636
parent 1519ae2c
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
(flow_delete_insn): Decrement LABEL_NUSES when deleting insns that (flow_delete_insn): Decrement LABEL_NUSES when deleting insns that
reference labels. reference labels.
* fold-const.c (extract_muldiv): Apply type check for defined
overflow to multiply as well as divide.
2000-03-18 Mark Mitchell <mark@codesourcery.com> 2000-03-18 Mark Mitchell <mark@codesourcery.com>
* emit-rtl.c (remove_unncessary_notes): Check that all * emit-rtl.c (remove_unncessary_notes): Check that all
......
...@@ -4333,9 +4333,13 @@ optimize_minmax_comparison (t) ...@@ -4333,9 +4333,13 @@ optimize_minmax_comparison (t)
should be used for the computation if wider than our type. should be used for the computation if wider than our type.
For example, if we are dividing (X * 8) + (Y + 16) by 4, we can return For example, if we are dividing (X * 8) + (Y + 16) by 4, we can return
(X * 2) + (Y + 4). We also canonicalize (X + 7) * 4 into X * 4 + 28 (X * 2) + (Y + 4). We must, however, be assured that either the original
in the hope that either the machine has a multiply-accumulate insn expression would not overflow or that overflow is undefined for the type
or that this is part of an addressing calculation. in the language in question.
We also canonicalize (X + 7) * 4 into X * 4 + 28 in the hope that either
the machine has a multiply-accumulate insn or that this is part of an
addressing calculation.
If we return a non-null expression, it is an equivalent form of the If we return a non-null expression, it is an equivalent form of the
original computation, but need not be in the original type. */ original computation, but need not be in the original type. */
...@@ -4358,7 +4362,7 @@ extract_muldiv (t, c, code, wide_type) ...@@ -4358,7 +4362,7 @@ extract_muldiv (t, c, code, wide_type)
/* Don't deal with constants of zero here; they confuse the code below. */ /* Don't deal with constants of zero here; they confuse the code below. */
if (integer_zerop (c)) if (integer_zerop (c))
return 0; return NULL_TREE;
if (TREE_CODE_CLASS (tcode) == '1') if (TREE_CODE_CLASS (tcode) == '1')
op0 = TREE_OPERAND (t, 0); op0 = TREE_OPERAND (t, 0);
...@@ -4379,7 +4383,6 @@ extract_muldiv (t, c, code, wide_type) ...@@ -4379,7 +4383,6 @@ extract_muldiv (t, c, code, wide_type)
break; break;
case CONVERT_EXPR: case NON_LVALUE_EXPR: case NOP_EXPR: case CONVERT_EXPR: case NON_LVALUE_EXPR: case NOP_EXPR:
/* Pass the constant down and see if we can make a simplification. If /* Pass the constant down and see if we can make a simplification. If
we can, replace this expression with the inner simplification for we can, replace this expression with the inner simplification for
possible later conversion to our or some other type. */ possible later conversion to our or some other type. */
...@@ -4534,16 +4537,18 @@ extract_muldiv (t, c, code, wide_type) ...@@ -4534,16 +4537,18 @@ extract_muldiv (t, c, code, wide_type)
/* If these operations "cancel" each other, we have the main /* If these operations "cancel" each other, we have the main
optimizations of this pass, which occur when either constant is a optimizations of this pass, which occur when either constant is a
multiple of the other, in which case we replace this with either an multiple of the other, in which case we replace this with either an
operation or CODE or TCODE. If we have an unsigned type that is operation or CODE or TCODE.
not a sizetype, we canot do this for division since it will change
the result if the original computation overflowed. */ If we have an unsigned type that is not a sizetype, we canot do
if ((code == MULT_EXPR && tcode == EXACT_DIV_EXPR this since it will change the result if the original computation
&& (! TREE_UNSIGNED (ctype) overflowed. */
|| (TREE_CODE (ctype) == INTEGER_TYPE if ((! TREE_UNSIGNED (ctype)
&& TYPE_IS_SIZETYPE (ctype)))) || (TREE_CODE (ctype) == INTEGER_TYPE
|| (tcode == MULT_EXPR && TYPE_IS_SIZETYPE (ctype)))
&& code != TRUNC_MOD_EXPR && code != CEIL_MOD_EXPR && ((code == MULT_EXPR && tcode == EXACT_DIV_EXPR)
&& code != FLOOR_MOD_EXPR && code != ROUND_MOD_EXPR)) || (tcode == MULT_EXPR
&& code != TRUNC_MOD_EXPR && code != CEIL_MOD_EXPR
&& code != FLOOR_MOD_EXPR && code != ROUND_MOD_EXPR)))
{ {
if (integer_zerop (const_binop (TRUNC_MOD_EXPR, op1, c, 0))) if (integer_zerop (const_binop (TRUNC_MOD_EXPR, op1, c, 0)))
return fold (build (tcode, ctype, convert (ctype, op0), return fold (build (tcode, ctype, convert (ctype, op0),
......
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