c-common.c (c_expand_expr): If the last expression is a VAR_DECL with RTL that matche...
authorJason Merrill <jason@redhat.com>
Wed, 7 Aug 2002 00:52:24 +0000 (20:52 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 7 Aug 2002 00:52:24 +0000 (20:52 -0400)
        * c-common.c (c_expand_expr) [STMT_EXPR]: If the last expression is
        a VAR_DECL with RTL that matches the target, just return that RTL.

From-SVN: r56083

gcc/ChangeLog
gcc/c-common.c

index 2e3a9b8d47b385c4a89edabe9cac80f4e1f26838..23f8caa6d8d1595b7269188b2b752feae557d013 100644 (file)
@@ -1,3 +1,8 @@
+2002-08-06  Jason Merrill  <jason@redhat.com>
+
+       * c-common.c (c_expand_expr) [STMT_EXPR]: If the last expression is
+       a VAR_DECL with RTL that matches the target, just return that RTL.
+
 2002-08-06  Dale Johannesen  <dalej@apple.com>
        * c-common.c (fname_decl): Use line number 0 for
         __func__, to avoid confusing debuggers.
index fabc18139043d76372b601e8e727b9638e62ad7b..30c38de04abf48054af95950d2aae7ada186174d 100644 (file)
@@ -4185,6 +4185,7 @@ c_expand_expr (exp, target, tmode, modifier)
        tree rtl_expr;
        rtx result;
        bool preserve_result = false;
+       bool return_target = false;
 
        /* Since expand_expr_stmt calls free_temp_slots after every
           expression statement, we must call push_temp_slots here.
@@ -4212,8 +4213,20 @@ c_expand_expr (exp, target, tmode, modifier)
            if (TREE_CODE (last) == SCOPE_STMT
                && TREE_CODE (expr) == EXPR_STMT)
              {
-               TREE_ADDRESSABLE (expr) = 1;
-               preserve_result = true;
+               if (target && TREE_CODE (EXPR_STMT_EXPR (expr)) == VAR_DECL
+                   && DECL_RTL_IF_SET (EXPR_STMT_EXPR (expr)) == target)
+                 /* If the last expression is a variable whose RTL is the
+                    same as our target, just return the target; if it
+                    isn't valid expanding the decl would produce different
+                    RTL, and store_expr would try to do a copy.  */
+                 return_target = true;
+               else
+                 {
+                   /* Otherwise, note that we want the value from the last
+                      expression.  */
+                   TREE_ADDRESSABLE (expr) = 1;
+                   preserve_result = true;
+                 }
              }
          }
 
@@ -4221,7 +4234,9 @@ c_expand_expr (exp, target, tmode, modifier)
        expand_end_stmt_expr (rtl_expr);
 
        result = expand_expr (rtl_expr, target, tmode, modifier);
-       if (preserve_result && GET_CODE (result) == MEM)
+       if (return_target)
+         result = target;
+       else if (preserve_result && GET_CODE (result) == MEM)
          {
            if (GET_MODE (result) != BLKmode)
              result = copy_to_reg (result);