Commit f966975b authored by Matthias Braun's avatar Matthias Braun
Browse files

iropt: add 0 % x == 0 if x != 0 rule

parent 78ad9c61
......@@ -781,11 +781,18 @@ static ir_tarval *do_computed_value_Div(const ir_node *div)
static ir_tarval *do_computed_value_Mod(const ir_node *a, const ir_node *b)
{
ir_tarval *tb = value_of(b);
/* Compute a % 1 or c1 % c2 */
if (tarval_is_one(tb))
return get_mode_null(get_irn_mode(a));
ir_tarval *ta = value_of(a);
/* 0 % b == 0 if b != 0 */
if (tarval_is_null(ta)) {
assert(get_mode_arithmetic(get_irn_mode(a)) == irma_twos_complement);
const ir_node *dummy;
if (value_not_null(b, &dummy))
return ta;
}
if (ta != tarval_unknown && tb != tarval_unknown && !tarval_is_null(tb))
return tarval_mod(ta, tb);
return tarval_unknown;
......
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