diff mbox

Fix pessimization with volatile objects

Message ID 201008312213.41067.ebotcazou@adacore.com
State New
Headers show

Commit Message

Eric Botcazou Aug. 31, 2010, 8:13 p.m. UTC
Hi Richard,

last January you applied a fix for an issue related to volatile objects:

2010-01-31  Richard Guenther  <rguenther@suse.de>

	PR middle-end/42898
	* gimplify.c (gimplify_init_constructor): For volatile LHS
	initialize a temporary.

on all branches.  Unfortunately this pessimizes a relatively common case in 
Ada, namely the assignment from a constructor with only one element.  May I 
apply the attached patch on all branches as well (after testing)?


2010-08-31  Eric Botcazou  <ebotcazou@adacore.com>

	* gimplify.c (gimplify_init_constructor): Do not create a temporary for
	a volatile LHS if the constructor has only one element.

Comments

Richard Biener Sept. 1, 2010, 8:34 a.m. UTC | #1
On Tue, 31 Aug 2010, Eric Botcazou wrote:

> Hi Richard,
> 
> last January you applied a fix for an issue related to volatile objects:
> 
> 2010-01-31  Richard Guenther  <rguenther@suse.de>
> 
> 	PR middle-end/42898
> 	* gimplify.c (gimplify_init_constructor): For volatile LHS
> 	initialize a temporary.
> 
> on all branches.  Unfortunately this pessimizes a relatively common case in 
> Ada, namely the assignment from a constructor with only one element.  May I 
> apply the attached patch on all branches as well (after testing)?

Yes.

Thanks,
Richard.
diff mbox

Patch

Index: gimplify.c
===================================================================
--- gimplify.c	(revision 163660)
+++ gimplify.c	(working copy)
@@ -3824,11 +3824,12 @@  gimplify_init_constructor (tree *expr_p,
 	      }
 	  }
 
-	/* If the target is volatile and we have non-zero elements
-	   initialize the target from a temporary.  */
+	/* If the target is volatile, we have non-zero elements and more than
+	   one field to assign, initialize the target from a temporary.  */
 	if (TREE_THIS_VOLATILE (object)
 	    && !TREE_ADDRESSABLE (type)
-	    && num_nonzero_elements > 0)
+	    && num_nonzero_elements > 0
+	    && VEC_length (constructor_elt, elts) > 1)
 	  {
 	    tree temp = create_tmp_var (TYPE_MAIN_VARIANT (type), NULL);
 	    TREE_OPERAND (*expr_p, 0) = temp;