From b49d25ed89af82583449359673fa783e73a4d186 Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Tue, 21 Jun 2005 15:00:06 +0000 Subject: [PATCH] added (a + x) - x = a optimization new i/f for compute_value_confirm_cmp [r6079] --- ir/ir/iropt.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/ir/ir/iropt.c b/ir/ir/iropt.c index 7f2dd8f2e..ca637d7ee 100644 --- a/ir/ir/iropt.c +++ b/ir/ir/iropt.c @@ -513,7 +513,7 @@ static tarval *computed_value_Proj_Cmp(ir_node *n) } } - return computed_value_Cmp_Confirm(aa, ab, proj_nr); + return computed_value_Cmp_Confirm(a, aa, ab, proj_nr); } /** @@ -831,12 +831,53 @@ static ir_node *equivalent_node_left_zero(ir_node *n) return n; } -#define equivalent_node_Sub equivalent_node_left_zero #define equivalent_node_Shl equivalent_node_left_zero #define equivalent_node_Shr equivalent_node_left_zero #define equivalent_node_Shrs equivalent_node_left_zero #define equivalent_node_Rot equivalent_node_left_zero +/** + * Optimize a - 0 and (a + x) - x (for modes with wrap-around). + * + * The second one looks strange, but this construct + * is used heavily in the LCC sources :-). + */ +static ir_node *equivalent_node_Sub(ir_node *n) +{ + ir_node *oldn = n; + + ir_node *a = get_Sub_left(n); + ir_node *b = get_Sub_right(n); + + if (classify_tarval(value_of(b)) == TV_CLASSIFY_NULL) { + n = a; + + DBG_OPT_ALGSIM1(oldn, a, b, n); + } + else if (get_irn_op(a) == op_Add) { + ir_mode *mode = get_irn_mode(n); + + if (mode_wrap_around(mode)) { + ir_node *left = get_Add_left(a); + ir_node *right = get_Add_right(a); + + if (left == b) { + n = right; + + DBG_OPT_ALGSIM1(oldn, a, b, n); + } + else if (right == b) { + n = left; + + DBG_OPT_ALGSIM1(oldn, a, b, n); + } + } + } + + return n; +} + + /** * Optimize an "idempotent unary op", ie op(op(n)) = n. * -- 2.20.1