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] Make FRE/PRE look through casts, improve/fix PRs 14287, 14844, 19792, 21608, 27090


This patch makes value numbering look through casts, effectively
doing lightweight tree-combining.  It works as follows, on a
value number expression of the form (T) VN, we use fold to see
if we can simplify the expression by expanding VN to its expression.
If that simplifies to an existing VN or an expression with a known
VN, we register that as the VNs expression.

Bootstrapped and tested on x86_64-unknown-linux-gnu for all languages
including Ada.  Unfortunately this hits PR26447 during the build of
libjava (but you can "convince" it to go further) - I would really
like someone to look at this PR.

Ok for mainline once PR26447 is fixed and the patch bootstraps without
this problem?

Thanks,
Richard.

:ADDPATCH middle-end:

2006-05-02  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/14287
	PR tree-optimization/14844
	PR tree-optimization/19792
	PR tree-optimization/21608
	PR tree-optimization/27090
	* tree-ssa-pre.c (compute_avail): After constructing the value-handle
	expression, combine NOP_EXPRs with previous value-handle expressions
	and use the result if it is available.

	* gcc.dg/tree-ssa/ssa-fre-1.c: New testcase.
	* gcc.dg/tree-ssa/ssa-fre-2.c: Likewise.
	* gcc.dg/tree-ssa/ssa-fre-3.c: Likewise.
	* gcc.dg/tree-ssa/ssa-fre-4.c: Likewise.
	* gcc.dg/tree-ssa/ssa-fre-5.c: Likewise.

Index: tree-ssa-pre.c
===================================================================
*** tree-ssa-pre.c	(revision 113452)
--- tree-ssa-pre.c	(working copy)
*************** compute_avail (void)
*** 3430,3438 ****
  		  tree newt = create_value_expr_from (rhs, block, stmt);
  		  if (newt)
  		    {
! 		      add_to_sets (lhs, newt, stmt, TMP_GEN (block),
! 				   AVAIL_OUT (block));
! 		      value_insert_into_set (EXP_GEN (block), newt);
  		      continue;
  		    }
  		}
--- 3430,3462 ----
  		  tree newt = create_value_expr_from (rhs, block, stmt);
  		  if (newt)
  		    {
! 		      tree tmp = newt;
! 		      /* tree-combine NOP_EXPRs to existing value-handles.  */
! 		      if ((TREE_CODE (tmp) == NOP_EXPR
! 			   || TREE_CODE (tmp) == CONVERT_EXPR)
! 			  && TREE_CODE (TREE_OPERAND (tmp, 0)) == VALUE_HANDLE
! 			  && !VALUE_HANDLE_VUSES (TREE_OPERAND (tmp, 0)))
! 			{
! 			  tmp = fold_unary (TREE_CODE (tmp), TREE_TYPE (tmp),
! 					    VALUE_HANDLE_EXPR_SET (TREE_OPERAND (tmp, 0))->head->expr);
! 			  if (tmp
! 			      && !(TREE_CODE (tmp) == VALUE_HANDLE
! 				   || is_gimple_min_invariant (tmp)))
! 			    tmp = vn_lookup (tmp, NULL);
! 			}
! 		      if (tmp
! 			  && tmp != newt
! 			  && (TREE_CODE (tmp) == VALUE_HANDLE
! 			      || is_gimple_min_invariant (tmp)))
! 			vn_add (lhs, tmp);
! 		      else
! 			{
! 			  tree val = vn_lookup_or_add (newt, stmt);
! 			  vn_add (lhs, val);
! 			  value_insert_into_set (EXP_GEN (block), newt);
! 			}
! 		      bitmap_insert_into_set (TMP_GEN (block), lhs);
! 		      bitmap_value_insert_into_set (AVAIL_OUT (block), lhs);
  		      continue;
  		    }
  		}
Index: testsuite/gcc.dg/tree-ssa/ssa-fre-1.c
===================================================================
*** testsuite/gcc.dg/tree-ssa/ssa-fre-1.c	(revision 0)
--- testsuite/gcc.dg/tree-ssa/ssa-fre-1.c	(revision 0)
***************
*** 0 ****
--- 1,16 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O -fdump-tree-fre-details" } */
+ 
+ /* From PR27090.  */
+ 
+ int f(int *a)
+ {
+   int t = *a;
+   unsigned *b = (unsigned *)a;
+   int *c = (int*)b;
+   return *c + t;
+ }
+ 
+ /* { dg-final { scan-tree-dump "Replaced \\\(int \\\*\\\) b_.*with a_" "fre" } } */
+ /* { dg-final { scan-tree-dump "Replaced \\\*c_.*with t_" "fre" } } */
+ /* { dg-final { cleanup-tree-dump "fre" } } */
Index: testsuite/gcc.dg/tree-ssa/ssa-fre-2.c
===================================================================
*** testsuite/gcc.dg/tree-ssa/ssa-fre-2.c	(revision 0)
--- testsuite/gcc.dg/tree-ssa/ssa-fre-2.c	(revision 0)
***************
*** 0 ****
--- 1,18 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O -fdump-tree-fre-details" } */
+ 
+ /* From PR14287.  */
+ 
+ short g, h;
+ 
+ void
+ foo (long a)
+ {
+   short b = a & 3;
+   long c = b;
+   g = c;
+   h = c;
+ }
+ 
+ /* { dg-final { scan-tree-dump "Replaced \\\(short int\\\) c_.*with b_" "fre" } } */
+ /* { dg-final { cleanup-tree-dump "fre" } } */
Index: testsuite/gcc.dg/tree-ssa/ssa-fre-3.c
===================================================================
*** testsuite/gcc.dg/tree-ssa/ssa-fre-3.c	(revision 0)
--- testsuite/gcc.dg/tree-ssa/ssa-fre-3.c	(revision 0)
***************
*** 0 ****
--- 1,15 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O -fwrapv -fdump-tree-fre-details" } */
+ 
+ /* From PR14844.  */
+ 
+ int
+ foo (int a, int b)
+ {
+   long long aa = a;
+   long long bb = b;
+   return aa + bb;
+ }
+ 
+ /* { dg-final { scan-tree-dump "Replaced \\\(int\\\) aa_.*with a_" "fre" } } */
+ /* { dg-final { cleanup-tree-dump "fre" } } */
Index: testsuite/gcc.dg/tree-ssa/ssa-fre-4.c
===================================================================
*** testsuite/gcc.dg/tree-ssa/ssa-fre-4.c	(revision 0)
--- testsuite/gcc.dg/tree-ssa/ssa-fre-4.c	(revision 0)
***************
*** 0 ****
--- 1,15 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O -fdump-tree-fre-details" } */
+ 
+ /* From PR21608.  */
+ 
+ #define bool _Bool
+ static inline bool wrap(bool f) { return f; }
+ bool bar(bool f)
+ {
+         return wrap(f);
+ }
+ 
+ /* { dg-final { scan-tree-dump "Replaced \\\(_Bool\\\) D.*with f_" "fre" } } */
+ /* { dg-final { scan-tree-dump "Replaced \\\(int\\\) f_.*with D" "fre" } } */
+ /* { dg-final { cleanup-tree-dump "fre" } } */
Index: testsuite/gcc.dg/tree-ssa/ssa-fre-5.c
===================================================================
*** testsuite/gcc.dg/tree-ssa/ssa-fre-5.c	(revision 0)
--- testsuite/gcc.dg/tree-ssa/ssa-fre-5.c	(revision 0)
***************
*** 0 ****
--- 1,14 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O -fdump-tree-fre-details" } */
+ 
+ /* From PR19792.  */
+ 
+ int
+ bar (unsigned int t)
+ {
+   int a = t;
+   return a == t;
+ }
+ 
+ /* { dg-final { scan-tree-dump "Replaced \\\(unsigned int\\\) a_.*with t_" "fre" } } */
+ /* { dg-final { cleanup-tree-dump "fre" } } */


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