]> gcc.gnu.org Git - gcc.git/commitdiff
cse.c (fold_rtx): When arg1 has a constant equivalent...
authorHans-Peter Nilsson <hp@axis.com>
Wed, 1 Feb 2006 21:15:54 +0000 (21:15 +0000)
committerHans-Peter Nilsson <hp@gcc.gnu.org>
Wed, 1 Feb 2006 21:15:54 +0000 (21:15 +0000)
* 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

gcc/ChangeLog
gcc/cse.c

index 1898c2a16c9699aa0ae10a02fc10da89419c25db..fb24b92b16e371091242f7a8e4d8bda908018327 100644 (file)
@@ -1,3 +1,10 @@
+2006-02-01  Hans-Peter Nilsson  <hp@axis.com>
+
+       * 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.
+
 2006-02-01  Jan Hubicka  <jh@suse.cz>
 
        * opts.c (no_unit_at_a_time_default): New global variable.
index 3d2f6b43d5e7a71d39ff067b6823fa8d8fa3f897..8163c6445ac305997db41b978ae93a8735bfd2e9 100644 (file)
--- 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
This page took 0.072905 seconds and 5 git commands to generate.