diff options
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/fold-const.c | 31 |
2 files changed, 37 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9d7055e7d20..0b3f40f3f6e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +Tue Oct 28 11:58:40 1997 Toon Moene <toon@moene.indiv.nluug.nl> + + * fold-const.c (fold): For ((a * C1) / C3) or (((a * C1) + C2) / C3) + optimizations, look inside dividend to determine if the expression + can be simplified by using EXACT_DIV_EXPR. + Tue Oct 28 10:19:01 1997 Jason Merrill <jason@yorick.cygnus.com> From Brendan: diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 1e823fbf4c7..da18997acc3 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -4655,6 +4655,37 @@ fold (expr) STRIP_NOPS (xarg0); + /* Look inside the dividend and simplify using EXACT_DIV_EXPR + if possible. */ + if (TREE_CODE (xarg0) == MULT_EXPR + && multiple_of_p (type, TREE_OPERAND (xarg0, 0), arg1)) + { + tree t; + + t = fold (build (MULT_EXPR, type, + fold (build (EXACT_DIV_EXPR, type, + TREE_OPERAND (xarg0, 0), arg1)), + TREE_OPERAND (xarg0, 1))); + if (have_save_expr) + t = save_expr (t); + return t; + + } + + if (TREE_CODE (xarg0) == MULT_EXPR + && multiple_of_p (type, TREE_OPERAND (xarg0, 1), arg1)) + { + tree t; + + t = fold (build (MULT_EXPR, type, + fold (build (EXACT_DIV_EXPR, type, + TREE_OPERAND (xarg0, 1), arg1)), + TREE_OPERAND (xarg0, 0))); + if (have_save_expr) + t = save_expr (t); + return t; + } + if (TREE_CODE (xarg0) == PLUS_EXPR && TREE_CODE (TREE_OPERAND (xarg0, 1)) == INTEGER_CST) c2 = TREE_OPERAND (xarg0, 1), xarg0 = TREE_OPERAND (xarg0, 0); |