From 9d3172516df99d45ccd381ee644d1b0618a2ea15 Mon Sep 17 00:00:00 2001 From: Roger Sayle Date: Mon, 5 Apr 2004 03:14:13 +0000 Subject: [PATCH] simplify-rtx.c (simplify_binary_operation): Constant fold DIV, MOD, UDIV and UMOD using div_and_round_double. * simplify-rtx.c (simplify_binary_operation): Constant fold DIV, MOD, UDIV and UMOD using div_and_round_double. From-SVN: r80420 --- gcc/ChangeLog | 5 +++++ gcc/simplify-rtx.c | 31 +++++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 582add2..74005c4 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2004-04-04 Roger Sayle + + * simplify-rtx.c (simplify_binary_operation): Constant fold + DIV, MOD, UDIV and UMOD using div_and_round_double. + 2004-04-04 Mark Mitchell PR c++/14804 diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index 0058589..0d283cd 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -1285,8 +1285,8 @@ simplify_binary_operation (enum rtx_code code, enum machine_mode mode, && (GET_CODE (trueop1) == CONST_DOUBLE || GET_CODE (trueop1) == CONST_INT)) { - unsigned HOST_WIDE_INT l1, l2, lv; - HOST_WIDE_INT h1, h2, hv; + unsigned HOST_WIDE_INT l1, l2, lv, lt; + HOST_WIDE_INT h1, h2, hv, ht; if (GET_CODE (trueop0) == CONST_DOUBLE) l1 = CONST_DOUBLE_LOW (trueop0), h1 = CONST_DOUBLE_HIGH (trueop0); @@ -1315,10 +1315,29 @@ simplify_binary_operation (enum rtx_code code, enum machine_mode mode, mul_double (l1, h1, l2, h2, &lv, &hv); break; - case DIV: case MOD: case UDIV: case UMOD: - /* We'd need to include tree.h to do this and it doesn't seem worth - it. */ - return 0; + case DIV: + if (div_and_round_double (TRUNC_DIV_EXPR, 0, l1, h1, l2, h2, + &lv, &hv, <, &ht)) + return 0; + break; + + case MOD: + if (div_and_round_double (TRUNC_DIV_EXPR, 0, l1, h1, l2, h2, + <, &ht, &lv, &hv)) + return 0; + break; + + case UDIV: + if (div_and_round_double (TRUNC_DIV_EXPR, 1, l1, h1, l2, h2, + &lv, &hv, <, &ht)) + return 0; + break; + + case UMOD: + if (div_and_round_double (TRUNC_DIV_EXPR, 1, l1, h1, l2, h2, + <, &ht, &lv, &hv)) + return 0; + break; case AND: lv = l1 & l2, hv = h1 & h2; -- 2.7.4