This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C, PATCH] Improve/Fix the gimplifier of C complex/vector compound literals


On Tue, 2006-12-19 at 20:43 -0800, Andrew Pinski wrote: 
> On Thu, 2006-12-14 at 22:35 -0800, Andrew Pinski wrote:
> > Hi,
> >   Since the decl for a compound literal is added to the temporary
> > variable list while gimplifing, we don't get the chance to mark the decl
> > as DECL_GIMPLE_REG_P unlike if the decl was in the BLOCK.  Since the
> > decl is not marked with DECL_GIMPLE_REG_P, we get an extra temporary for
> > complex and vector compound literals which seems wrong.
> > 
> > OK? Bootstrapped and tested on i686-linux-gnu with no regressions.
> 
> I withdraw this patch for now as I found another issue with compound
> literals and invalid gimple.
> The following testcase can produce invalid gimple:
> int f(float *);
> int g(float x)
> {
>   return f(&(float){x}) + f(&x);
> }
Also my original patch would also cause a regression with the following
code:
int f(_Complex float *);
int g(_Complex float x)
{
  return f(&(_Complex float){x+1}) + f(&x);
}

As it would mark the compound literal as a gimple register even though
its address was taken.

Here is the patch which fixes the above invalid gimple issue and the one
mentioned in my original message (I hope people don't mind that I am
replying to myself as it seems wrong).

OK?  Bootstrapped and tested on i686-linux-gnu with no regressions.

Thanks,
Andrew Pinski

ChangeLog: 

	* c-gimplifier.c (gimplify_compound_literal_expr): Mark the
	decl as addressable if the compound literal was marked as
	addressable.
	Mark the decl as a gimple register if it is a complex or
	vector decl and does not live in memory.
Index: testsuite/gcc.c-torture/compile/compound-literal-2.c
===================================================================
--- testsuite/gcc.c-torture/compile/compound-literal-2.c	(revision 0)
+++ testsuite/gcc.c-torture/compile/compound-literal-2.c	(revision 0)
@@ -0,0 +1,8 @@
+/* PR C/30265, invalid gimple was produced because we did not mark
+   the compound literal's decl early enough.  */
+
+int f(float *);
+int g(float x)
+{
+  return f(&(float){x}) + f(&x);
+}
Index: testsuite/gcc.c-torture/compile/compound-literal-3.c
===================================================================
--- testsuite/gcc.c-torture/compile/compound-literal-3.c	(revision 0)
+++ testsuite/gcc.c-torture/compile/compound-literal-3.c	(revision 0)
@@ -0,0 +1,8 @@
+/* PR C/30265, invalid gimple was produced because we did not mark
+   the compound literal's decl early enough.  */
+
+int f(_Complex float *);
+int g(_Complex float x)
+{
+  return f(&(_Complex float){x+1}) + f(&x);
+}
Index: c-gimplify.c
===================================================================
--- c-gimplify.c	(revision 120144)
+++ c-gimplify.c	(working copy)
@@ -183,6 +183,20 @@ gimplify_compound_literal_expr (tree *ex
 {
   tree decl_s = COMPOUND_LITERAL_EXPR_DECL_STMT (*expr_p);
   tree decl = DECL_EXPR_DECL (decl_s);
+  /* Mark the decl as addressable if the compound literal
+     expression is addressable now, otherwise it is marked too late
+     after we gimplify the initialization expression.  */
+  if (TREE_ADDRESSABLE (*expr_p))
+    TREE_ADDRESSABLE (decl) = 1;
+
+  /* Preliminarily mark non-addressed complex variables as eligible
+     for promotion to gimple registers.  We'll transform their uses
+     as we find them.  */
+  if ((TREE_CODE (TREE_TYPE (decl)) == COMPLEX_TYPE
+       || TREE_CODE (TREE_TYPE (decl)) == VECTOR_TYPE)
+      && !TREE_THIS_VOLATILE (decl)
+      && !needs_to_live_in_memory (decl))
+    DECL_GIMPLE_REG_P (decl) = 1;
 
   /* This decl isn't mentioned in the enclosing block, so add it to the
      list of temps.  FIXME it seems a bit of a kludge to say that

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]