diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8aac434028f..9e806b3f062 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2005-01-28 Jeff Law + + * fold-const.c (fold, case CEIL_MOD_EXPR): Optimize 0 % X. + (case FLOOR_MOD_EXPR, ROUND_MOD_EXPR, TRUNC_MOD_EXPR): Similarly. + 2005-01-28 Kazu Hirata * cse.c (cse_reg_info_free_list, cse_reg_info_used_list, diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 8e8a821938b..67a0217057a 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -7875,7 +7875,8 @@ fold (tree expr) case FLOOR_MOD_EXPR: case ROUND_MOD_EXPR: case TRUNC_MOD_EXPR: - if (integer_onep (arg1)) + /* 0 % X is always zero as is X % 1. */ + if (integer_zerop (arg0) || integer_onep (arg1)) return omit_one_operand (type, integer_zero_node, arg0); if (integer_zerop (arg1)) return t;