From 08678f511c3439e279f1d66978a12d324cfbcca1 Mon Sep 17 00:00:00 2001 From: Hans-Peter Nilsson Date: Wed, 1 Feb 2006 21:15:54 +0000 Subject: [PATCH] cse.c (fold_rtx): When arg1 has a constant equivalent... * cse.c (fold_rtx) : When arg1 has a constant equivalent, iterate over equivalents for arg0, calling simplify_relational_operation and if there's a result cheaper than X, apply fold_rtx and return the result. From-SVN: r110481 --- gcc/ChangeLog | 7 +++++++ gcc/cse.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1898c2a16c9..fb24b92b16e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2006-02-01 Hans-Peter Nilsson + + * cse.c (fold_rtx) : When arg1 + has a constant equivalent, iterate over equivalents for arg0, + calling simplify_relational_operation and if there's a result + cheaper than X, apply fold_rtx and return the result. + 2006-02-01 Jan Hubicka * opts.c (no_unit_at_a_time_default): New global variable. diff --git a/gcc/cse.c b/gcc/cse.c index 3d2f6b43d5e..8163c6445ac 100644 --- a/gcc/cse.c +++ b/gcc/cse.c @@ -3981,6 +3981,57 @@ fold_rtx (rtx x, rtx insn) comparison. */ if (const_arg0 == 0 || const_arg1 == 0) { + if (const_arg1 != NULL) + { + rtx cheapest_simplification; + int cheapest_cost; + rtx simp_result; + struct table_elt *p; + + /* See if we can find an equivalent of folded_arg0 + that gets us a cheaper expression, possibly a + constant through simplifications. */ + p = lookup (folded_arg0, SAFE_HASH (folded_arg0, mode_arg0), + mode_arg0); + + if (p != NULL) + { + cheapest_simplification = x; + cheapest_cost = COST (x); + + for (p = p->first_same_value; p != NULL; p = p->next_same_value) + { + int cost; + + /* If the entry isn't valid, skip it. */ + if (! exp_equiv_p (p->exp, p->exp, 1, false)) + continue; + + /* Try to simplify using this equivalence. */ + simp_result + = simplify_relational_operation (code, mode, + mode_arg0, + p->exp, + const_arg1); + + if (simp_result == NULL) + continue; + + cost = COST (simp_result); + if (cost < cheapest_cost) + { + cheapest_cost = cost; + cheapest_simplification = simp_result; + } + } + + /* If we have a cheaper expression now, use that + and try folding it further, from the top. */ + if (cheapest_simplification != x) + return fold_rtx (cheapest_simplification, insn); + } + } + /* Some addresses are known to be nonzero. We don't know their sign, but equality comparisons are known. */ if (const_arg1 == const0_rtx