From 506a2967a763e4f5f1abd1133dabe44d6cfd5bf7 Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Tue, 24 Jul 2007 16:57:29 +0000 Subject: [PATCH] add 2.0*x = x+x and x/c = x*(1.0/c) for some constants [r15327] --- ir/ir/iropt.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/ir/ir/iropt.c b/ir/ir/iropt.c index 64ff6b68b..609eb5901 100644 --- a/ir/ir/iropt.c +++ b/ir/ir/iropt.c @@ -2191,6 +2191,24 @@ static ir_node *transform_node_Mul(ir_node *n) { return n; } } + if (get_mode_arithmetic(mode) == irma_ieee754) { + if (is_Const(a)) { + tarval *tv = get_Const_tarval(a); + if (tarval_ieee754_get_exponent(tv) == 1 && tarval_ieee754_zero_mantissa(tv)) { + n = new_rd_Add(get_irn_dbg_info(n), current_ir_graph, get_irn_n(n, -1), b, b, mode); + DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_ADD_A_A); + return n; + } + } + else if (is_Const(b)) { + tarval *tv = get_Const_tarval(b); + if (tarval_ieee754_get_exponent(tv) == 1 && tarval_ieee754_zero_mantissa(tv)) { + n = new_rd_Add(get_irn_dbg_info(n), current_ir_graph, get_irn_n(n, -1), a, a, mode); + DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_ADD_A_A); + return n; + } + } + } return arch_dep_replace_mul_with_shifts(n); } /* transform_node_Mul */ @@ -2314,6 +2332,41 @@ static ir_node *transform_node_DivMod(ir_node *n) { return n; } /* transform_node_DivMod */ +/** + * Optimize x / 1.0 * E+y to x * 1.0E-y + */ +static ir_node *transform_node_Quot(ir_node *n) { + ir_mode *mode = get_Quot_resmode(n); + ir_node *oldn = n; + + if (get_mode_arithmetic(mode) == irma_ieee754) { + ir_node *b = get_Quot_right(n); + + if (is_Const(b)) { + tarval *tv = get_Const_tarval(b); + + if (tarval_ieee754_zero_mantissa(tv)) { + tv = tarval_quo(get_mode_one(mode), tv); + if (tv != tarval_bad) { + ir_node *blk = get_irn_n(n, -1); + ir_node *c = new_r_Const(current_ir_graph, blk, mode, tv); + ir_node *a = get_Quot_left(n); + ir_node *m = new_rd_Mul(get_irn_dbg_info(n), current_ir_graph, blk, a, c, mode); + ir_node *mem = get_Quot_mem(n); + + turn_into_tuple(n, pn_Quot_max); + set_Tuple_pred(n, pn_Quot_M, mem); + set_Tuple_pred(n, pn_Quot_X_regular, new_r_Jmp(current_ir_graph, blk)); + set_Tuple_pred(n, pn_Quot_X_except, new_r_Bad(current_ir_graph)); + set_Tuple_pred(n, pn_Quot_res, m); + DBG_OPT_ALGSIM1(oldn, a, b, m, FS_OPT_FP_INV_MUL); + } + } + } + } + return n; +} /* transform_node_Quot */ + /** * Optimize Abs(x) into x if x is Confirmed >= 0 * Optimize Abs(x) into -x if x is Confirmed <= 0 @@ -3668,6 +3721,7 @@ static ir_op_ops *firm_set_default_transform_node(ir_opcode code, ir_op_ops *ops CASE(Div); CASE(Mod); CASE(DivMod); + CASE(Quot); CASE(Abs); CASE(Cond); CASE(And); -- 2.20.1