From 82fe4c79cd69aa57cf03a23b7f46200a3c3d001f Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Sun, 19 Mar 2006 11:56:56 +0000 Subject: [PATCH] Add optmitizations for the following cases: And(x, C) == C ==> And(x, C) != 0 And(x, C) != C ==> And(X, C) == 0 This helps the ia32 backend to create test instructions and might be useful for other backends as well [r7474] --- ir/ir/iropt.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/ir/ir/iropt.c b/ir/ir/iropt.c index a03d0f72c..aac8fe0ea 100644 --- a/ir/ir/iropt.c +++ b/ir/ir/iropt.c @@ -2530,7 +2530,32 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) } } } /* mode_is_int */ - } + + /* + * optimization for AND: + * Optimize: + * And(x, C) == C ==> And(x, C) != 0 + * And(x, C) != C ==> And(X, C) == 0 + * + * if C is a single Bit constant. + */ + if ((proj_nr == pn_Cmp_Eq || proj_nr == pn_Cmp_Lg) && + (get_irn_op(left) == op_And)) { + if (is_single_bit_tarval(tv)) { + /* check for Constant's match. We have check hare the tarvals, + because our const might be changed */ + ir_node *la = get_And_left(left); + ir_node *ra = get_And_right(left); + if ((is_Const(la) && get_Const_tarval(la) == tv) || + (is_Const(ra) && get_Const_tarval(ra) == tv)) { + /* fine: do the transformation */ + tv = get_mode_null(get_tarval_mode(tv)); + proj_nr ^= pn_Cmp_Leg; + changed |= 2; + } + } + } + } /* tarval != bad */ } if (changed) { -- 2.20.1