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] Fix PR47566


When inserting calls in PRE we do fold them, which, when presented
by an unfolded call can result in a load of stmts to appear
(like in the testcase the equivalent of sqrt(imag(x)**2+real(x)**2)).
This is not a problem in principle, but gimplifying the stmts causes
us to insert non-register temporaries when gimplifying save-exprs.
I'm not sure why save-expr gimplifying is not using registers, but
the following patch avoids using save-exprs around SSA_NAMEs which
is clearly unnecessary.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

2011-02-02  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/47566
	* builtins.c (builtin_save_expr): No SAVE_EXPR for SSA_NAMEs.

	* gcc.dg/lto/20110201-1_0.c: New testcase.

Index: gcc/builtins.c
===================================================================
*** gcc/builtins.c	(revision 169486)
--- gcc/builtins.c	(working copy)
*************** target_char_cast (tree cst, char *p)
*** 652,660 ****
  static tree
  builtin_save_expr (tree exp)
  {
!   if (TREE_ADDRESSABLE (exp) == 0
!       && (TREE_CODE (exp) == PARM_DECL
! 	  || (TREE_CODE (exp) == VAR_DECL && !TREE_STATIC (exp))))
      return exp;
  
    return save_expr (exp);
--- 652,661 ----
  static tree
  builtin_save_expr (tree exp)
  {
!   if (TREE_CODE (exp) == SSA_NAME
!       || (TREE_ADDRESSABLE (exp) == 0
! 	  && (TREE_CODE (exp) == PARM_DECL
! 	      || (TREE_CODE (exp) == VAR_DECL && !TREE_STATIC (exp)))))
      return exp;
  
    return save_expr (exp);
Index: gcc/testsuite/gcc.dg/lto/20110201-1_0.c
===================================================================
*** gcc/testsuite/gcc.dg/lto/20110201-1_0.c	(revision 0)
--- gcc/testsuite/gcc.dg/lto/20110201-1_0.c	(revision 0)
***************
*** 0 ****
--- 1,19 ----
+ /* { dg-lto-do run } */
+ /* { dg-lto-options { { -O0 -flto } } } */
+ /* { dg-extra-ld-options "-O2 -ffast-math -fuse-linker-plugin" } */
+ /* { dg-require-linker-plugin "" } */
+ 
+ /* We require a linker plugin because otherwise we'd need to link
+    against libm which we are not sure here has cabs on all targets.
+    This is because collect2 invokes ld on the -O0 object code
+    which does not have folded cabs.  */
+ 
+ double cabs(_Complex double);
+ double __attribute__((used))
+ foo (_Complex double x, int b)
+ {
+   if (b)
+     x = 0;
+   return cabs(x);
+ }
+ int main() { return 0; }


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