summaryrefslogtreecommitdiffstats
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorlaw <law@138bc75d-0d04-0410-961f-82ee72b054a4>1997-10-28 19:02:23 +0000
committerlaw <law@138bc75d-0d04-0410-961f-82ee72b054a4>1997-10-28 19:02:23 +0000
commit0c782bca0ee1dcecbb20d55f42a82e53cf95438b (patch)
treeb9bcdf0a69d79c64253d4f4fd74b9910a63c10c0 /gcc/fold-const.c
parent474253a15248331c7cb4f4600ddded5e468e89af (diff)
downloadppe42-gcc-0c782bca0ee1dcecbb20d55f42a82e53cf95438b.tar.gz
ppe42-gcc-0c782bca0ee1dcecbb20d55f42a82e53cf95438b.zip
* 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@16216 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c31
1 files changed, 31 insertions, 0 deletions
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);
OpenPOWER on IntegriCloud