From 12644a9a4012a7f4ace9e450f9789ce516bae239 Mon Sep 17 00:00:00 2001 From: Toon Moene Date: Sun, 9 Jul 2000 00:29:17 +0200 Subject: [PATCH] fold-const.c (extract_muldiv): Check whether c divides op1 exactly if operation is not multiplication. 2000-07-08 Toon Moene * fold-const.c (extract_muldiv) case PLUS_EXPR, MINUS_EXPR: Check whether c divides op1 exactly if operation is not multiplication. From-SVN: r34928 --- gcc/ChangeLog | 6 ++++++ gcc/fold-const.c | 15 +++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7bc499e2461..4d33224b012 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2000-07-08 Toon Moene + + * fold-const.c (extract_muldiv) case PLUS_EXPR, MINUS_EXPR: + Check whether c divides op1 exactly if operation is not + multiplication. + 2000-07-08 Richard Henderson * final.c (final): Do not abort when reg-stack introduces diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 5cf688f61e2..26ac5d27a7e 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -4501,10 +4501,17 @@ extract_muldiv (t, c, code, wide_type) break; } - /* Now do the operation and verify it doesn't overflow. */ - op1 = const_binop (code, convert (ctype, op1), convert (ctype, c), 0); - if (op1 == 0 || TREE_OVERFLOW (op1)) - break; + /* If it's a multiply or a division/modulus operation of a multiple + of our constant, do the operation and verify it doesn't overflow. */ + if (code == MULT_EXPR + || integer_zerop (const_binop (TRUNC_MOD_EXPR, op1, c, 0))) + { + op1 = const_binop (code, convert (ctype, op1), convert (ctype, c), 0); + if (op1 == 0 || TREE_OVERFLOW (op1)) + break; + } + else + break; /* If we have an unsigned type is not a sizetype, we cannot widen the operation since it will change the result if the original -- 2.30.2