From: Matthias Braun Date: Thu, 22 Sep 2011 12:56:22 +0000 (+0200) Subject: simplify transform_node_Mux by using is_single_bit X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=4483fd1671b94b61ed147d0247b313ee9b19f754;p=libfirm simplify transform_node_Mux by using is_single_bit --- diff --git a/ir/ir/iropt.c b/ir/ir/iropt.c index dd254ef57..ad965bd38 100644 --- a/ir/ir/iropt.c +++ b/ir/ir/iropt.c @@ -4972,6 +4972,23 @@ static bool is_cmp_unequal(const ir_node *node) return false; } +/** + * returns true for Cmp(x == 0) or Cmp(x != 0) + */ +static bool is_cmp_equality_zero(const ir_node *node) +{ + ir_relation relation; + ir_node *right = get_Cmp_right(node); + + if (!is_Const(right) || !is_Const_null(right)) + return false; + relation = get_Cmp_relation(node); + return relation == ir_relation_equal + || relation == ir_relation_less_greater + || (!mode_is_signed(get_irn_mode(right)) + && relation == ir_relation_greater); +} + /** * Transform an Or. */ @@ -5783,73 +5800,42 @@ static ir_node *transform_node_Mux(ir_node *n) } } - if (is_Cmp(sel)) { + if (is_Cmp(sel) && mode_is_int(mode) && is_cmp_equality_zero(sel)) { + ir_relation relation = get_Cmp_relation(sel); ir_node *cmp_r = get_Cmp_right(sel); - if (is_Const(cmp_r) && is_Const_null(cmp_r)) { - ir_node *block = get_nodes_block(n); - ir_node *cmp_l = get_Cmp_left(sel); - - if (mode_is_int(mode)) { - ir_relation relation = get_Cmp_relation(sel); - /* integer only */ - if ((relation == ir_relation_less_greater || relation == ir_relation_equal) && is_And(cmp_l)) { - /* Mux((a & b) != 0, c, 0) */ - ir_node *and_r = get_And_right(cmp_l); - ir_node *and_l; - - if (and_r == t && f == cmp_r) { - if (is_Const(t) && tarval_is_single_bit(get_Const_tarval(t))) { - if (relation == ir_relation_less_greater) { - /* Mux((a & 2^C) != 0, 2^C, 0) == a & 2^c */ - n = cmp_l; - DBG_OPT_ALGSIM1(oldn, sel, sel, n, FS_OPT_MUX_TO_BITOP); - } else { - /* Mux((a & 2^C) == 0, 2^C, 0) == (a & 2^c) xor (2^c) */ - n = new_rd_Eor(get_irn_dbg_info(n), - block, cmp_l, t, mode); - DBG_OPT_ALGSIM1(oldn, sel, sel, n, FS_OPT_MUX_TO_BITOP); - } - return n; - } - } - if (is_Shl(and_r)) { - ir_node *shl_l = get_Shl_left(and_r); - if (is_Const(shl_l) && is_Const_one(shl_l)) { - if (and_r == t && f == cmp_r) { - if (relation == ir_relation_less_greater) { - /* (a & (1 << n)) != 0, (1 << n), 0) == a & (1<