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]

[PATCH] Improve Gimplification of return for vectors and complex variables


Hi,
  When DECL_COMPLEX_GIMPLE_REG_P was added, we made function that
returned complex types gimplify in a no longer optimal way, we produce a
temporary decl as a non gimple register which causes us to produce an
extra decls.

For an example take this GNU C code:
_Complex int f(int a, int b)
{
  if (a)
    return a;
  return b;
}
---------------
Without this patch, we get the following in .final_cleanup at -O2:
  int SR.12;
  int SR.11;
  <unnamed type> D.1613;
  <unnamed type> D.1612;
  <unnamed type> D.1611;

<bb 2>:
  if (a != 0) goto <L0>; else goto <L1>;

<L0>:;
  D.1612 = COMPLEX_EXPR <a, 0>;
  SR.12 = IMAGPART_EXPR <D.1612>;
  SR.11 = REALPART_EXPR <D.1612>;
  goto <bb 5> (<L2>);

<L1>:;
  D.1613 = COMPLEX_EXPR <b, 0>;
  SR.12 = IMAGPART_EXPR <D.1613>;
  SR.11 = REALPART_EXPR <D.1613>;

<L2>:;
  IMAGPART_EXPR <D.1611> = SR.12;
  REALPART_EXPR <D.1611> = SR.11;
  return D.1611;

With this patch:
  <unnamed type> D.1614;

<bb 2>:
  if (a != 0) goto <L0>; else goto <L1>;

<L0>:;
  D.1614 = COMPLEX_EXPR <a, 0>;
  goto <bb 5> (<L2>);

<L1>:;
  D.1614 = COMPLEX_EXPR <b, 0>;

<L2>:;
  return D.1614;

Yes this is still can be improved so there is only one COMPLEX_EXPR, but
that is a bug for another time.

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

Thanks,
Andrew Pinski

ChangeLog:
	* gimplify.c (gimplify_return_expr): Make the temporary variable
	for the return expression, a gimple register variable.



Index: gimplify.c
===================================================================
--- gimplify.c	(revision 120040)
+++ gimplify.c	(working copy)
@@ -1171,6 +1171,9 @@ gimplify_return_expr (tree stmt, tree *p
   else
     {
       result = create_tmp_var (TREE_TYPE (result_decl), NULL);
+      if (TREE_CODE (TREE_TYPE (result)) == COMPLEX_TYPE
+          || TREE_CODE (TREE_TYPE (result)) == VECTOR_TYPE)
+        DECL_GIMPLE_REG_P (result) = 1;
 
       /* ??? With complex control flow (usually involving abnormal edges),
 	 we can wind up warning about an uninitialized value for this.  Due


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