X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firarch.c;h=ada45d670d5b47f0eeb34d9d35636895152ae7e6;hb=672b5c243e900427b5dcae01441d4fa3327d692c;hp=2431931a6f4f90efedb64d987a6e00cfea405daf;hpb=bdacbd77db4138f76e06dde1f0098edfa25e1aa9;p=libfirm diff --git a/ir/ir/irarch.c b/ir/ir/irarch.c index 2431931a6..ada45d670 100644 --- a/ir/ir/irarch.c +++ b/ir/ir/irarch.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. + * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. * * This file is part of libFirm. * @@ -79,9 +79,6 @@ void arch_dep_init(arch_dep_params_factory_t factory) { void arch_dep_set_opts(arch_dep_opts_t the_opts) { opts = the_opts; - - if (opts & arch_dep_mul_to_shift) - set_opt_arch_dep_running(1); } /** check, whether a mode allows a Mulh instruction. */ @@ -232,8 +229,8 @@ static unsigned char *value_to_condensed(mul_env *env, tarval *tv, int *pr) { * Calculate the gain when using the generalized complementary technique */ static int calculate_gain(unsigned char *R, int r) { - int max_gain = -1; - int idx, i; + int max_gain = 0; + int idx = -1, i; int gain; /* the gain for r == 1 */ @@ -247,9 +244,7 @@ static int calculate_gain(unsigned char *R, int r) { idx = i; } } - if (max_gain > 0) - return idx; - return -1; + return idx; } /** @@ -329,11 +324,16 @@ static instruction *decompose_simple_cases(mul_env *env, unsigned char *R, int r assert(r == 2); ins = env->root; + if (R[1] <= env->max_S) { + ins = emit_LEA(env, ins, ins, R[1]); + if (R[0] != 0) { + ins = emit_SHIFT(env, ins, R[0]); + } + return ins; + } if (R[0] != 0) { ins = emit_SHIFT(env, ins, R[0]); } - if (R[1] <= env->max_S) - return emit_LEA(env, ins, ins, R[1]); ins2 = emit_SHIFT(env, env->root, R[0] + R[1]); return emit_LEA(env, ins, ins2, 0); @@ -570,30 +570,34 @@ ir_node *arch_dep_replace_mul_with_shifts(ir_node *irn) { if (params == NULL || (opts & arch_dep_mul_to_shift) == 0) return irn; - if (is_Mul(irn) && mode_is_int(mode)) { - ir_node *left = get_binop_left(irn); - ir_node *right = get_binop_right(irn); - tarval *tv = NULL; - ir_node *operand = NULL; - - /* Look, if one operand is a constant. */ - if (is_Const(left)) { - tv = get_Const_tarval(left); - operand = right; - } else if (is_Const(right)) { - tv = get_Const_tarval(right); - operand = left; - } + set_arch_dep_running(1); + { + if (is_Mul(irn) && mode_is_int(mode)) { + ir_node *left = get_binop_left(irn); + ir_node *right = get_binop_right(irn); + tarval *tv = NULL; + ir_node *operand = NULL; + + /* Look, if one operand is a constant. */ + if (is_Const(left)) { + tv = get_Const_tarval(left); + operand = right; + } else if (is_Const(right)) { + tv = get_Const_tarval(right); + operand = left; + } - if (tv != NULL) { - res = do_decomposition(irn, operand, tv); + if (tv != NULL) { + res = do_decomposition(irn, operand, tv); - if (res != irn) { - hook_arch_dep_replace_mul_with_shifts(irn); - exchange(irn, res); + if (res != irn) { + hook_arch_dep_replace_mul_with_shifts(irn); + exchange(irn, res); + } } } } + //set_arch_dep_running(0); return res; } @@ -926,15 +930,20 @@ ir_node *arch_dep_replace_div_by_const(ir_node *irn) { ir_node *k_node; ir_node *curr = left; - if (k != 1) { - k_node = new_r_Const_long(current_ir_graph, block, mode_Iu, k - 1); - curr = new_rd_Shrs(dbg, current_ir_graph, block, left, k_node, mode); - } + /* create the correction code for signed values only if there might be a remainder */ + if (! is_Div_remainderless(irn)) { + if (k != 1) { + k_node = new_r_Const_long(current_ir_graph, block, mode_Iu, k - 1); + curr = new_rd_Shrs(dbg, current_ir_graph, block, left, k_node, mode); + } - k_node = new_r_Const_long(current_ir_graph, block, mode_Iu, bits - k); - curr = new_rd_Shr(dbg, current_ir_graph, block, curr, k_node, mode); + k_node = new_r_Const_long(current_ir_graph, block, mode_Iu, bits - k); + curr = new_rd_Shr(dbg, current_ir_graph, block, curr, k_node, mode); - curr = new_rd_Add(dbg, current_ir_graph, block, left, curr, mode); + curr = new_rd_Add(dbg, current_ir_graph, block, left, curr, mode); + } else { + k_node = left; + } k_node = new_r_Const_long(current_ir_graph, block, mode_Iu, k); res = new_rd_Shrs(dbg, current_ir_graph, block, curr, k_node, mode);