aboutsummaryrefslogtreecommitdiff
path: root/gcc/cse.c
diff options
context:
space:
mode:
authorHans-Peter Nilsson <hp@axis.com>2006-02-01 21:15:54 +0000
committerHans-Peter Nilsson <hp@gcc.gnu.org>2006-02-01 21:15:54 +0000
commit08678f511c3439e279f1d66978a12d324cfbcca1 (patch)
treee70ddc7be04aa34ecfa022123c32a5a39296a2c3 /gcc/cse.c
parent46fd0f8c241a0afd36adf9c63b56839ace3a0210 (diff)
downloadgcc-08678f511c3439e279f1d66978a12d324cfbcca1.zip
gcc-08678f511c3439e279f1d66978a12d324cfbcca1.tar.gz
gcc-08678f511c3439e279f1d66978a12d324cfbcca1.tar.bz2
cse.c (fold_rtx): When arg1 has a constant equivalent...
* cse.c (fold_rtx) <case RTX_COMM_COMPARE, RTX_COMPARE>: 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
Diffstat (limited to 'gcc/cse.c')
-rw-r--r--gcc/cse.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/gcc/cse.c b/gcc/cse.c
index 3d2f6b4..8163c64 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