public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-1913] compiler: in composite literals use temps only for interfaces
@ 2021-06-29 18:01 Ian Lance Taylor
  0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2021-06-29 18:01 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:8a8a7d332d5d01db5aea7336a36d9fd71a679fb1

commit r12-1913-g8a8a7d332d5d01db5aea7336a36d9fd71a679fb1
Author: Ian Lance Taylor <iant@golang.org>
Date:   Mon Jun 28 16:47:55 2021 -0700

    compiler: in composite literals use temps only for interfaces
    
    For a composite literal we only need to introduce a temporary variable
    if we may be converting to an interface type, so only do it then.
    This saves over 80% of compilation time when using gccgo to compile
    cmd/internal/obj/x86, as the GCC middle-end spends a lot of time
    pointlessly computing interactions between temporary variables.
    
    For PR debug/101064
    For golang/go#46600
    
    Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/331513

Diff:
---
 gcc/go/gofrontend/MERGE          |  2 +-
 gcc/go/gofrontend/expressions.cc | 17 +++++++++++++----
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index f16fb9facc3..f7bcc8c484a 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-bcafcb3c39530bb325514d6377747eb3127d1a03
+cad187fe3aceb2a7d964b64c70dfa8c8ad24ce65
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index 5d45e4baab4..94342b2f9b8 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -15148,7 +15148,7 @@ Struct_construction_expression::do_copy()
 }
 
 // Flatten a struct construction expression.  Store the values into
-// temporaries in case they need interface conversion.
+// temporaries if they may need interface conversion.
 
 Expression*
 Struct_construction_expression::do_flatten(Gogo*, Named_object*,
@@ -15162,10 +15162,13 @@ Struct_construction_expression::do_flatten(Gogo*, Named_object*,
     return this;
 
   Location loc = this->location();
+  const Struct_field_list* fields = this->type_->struct_type()->fields();
+  Struct_field_list::const_iterator pf = fields->begin();
   for (Expression_list::iterator pv = this->vals()->begin();
        pv != this->vals()->end();
-       ++pv)
+       ++pv, ++pf)
     {
+      go_assert(pf != fields->end());
       if (*pv != NULL)
 	{
           if ((*pv)->is_error_expression() || (*pv)->type()->is_error_type())
@@ -15173,7 +15176,8 @@ Struct_construction_expression::do_flatten(Gogo*, Named_object*,
               go_assert(saw_errors());
               return Expression::make_error(loc);
             }
-	  if (!(*pv)->is_multi_eval_safe())
+	  if (pf->type()->interface_type() != NULL
+	      && !(*pv)->is_multi_eval_safe())
 	    {
 	      Temporary_statement* temp =
 		Statement::make_temporary(NULL, *pv, loc);
@@ -15448,7 +15452,7 @@ Array_construction_expression::do_check_types(Gogo*)
 }
 
 // Flatten an array construction expression.  Store the values into
-// temporaries in case they need interface conversion.
+// temporaries if they may need interface conversion.
 
 Expression*
 Array_construction_expression::do_flatten(Gogo*, Named_object*,
@@ -15467,6 +15471,11 @@ Array_construction_expression::do_flatten(Gogo*, Named_object*,
   if (this->is_constant_array() || this->is_static_initializer())
     return this;
 
+  // If the array element type is not an interface type, we don't need
+  // temporaries.
+  if (this->type_->array_type()->element_type()->interface_type() == NULL)
+    return this;
+
   Location loc = this->location();
   for (Expression_list::iterator pv = this->vals()->begin();
        pv != this->vals()->end();


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-06-29 18:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-29 18:01 [gcc r12-1913] compiler: in composite literals use temps only for interfaces Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).