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: [patch] Perform anonymous constant propagation during inlining


> OK, how aggressive then?  We could as well do the substitution for all
> copies:
> 
>       /* For EXPAND_INITIALIZER try harder to get something simpler.
> 	 Otherwise, substitute copies on the RHS, this can propagate
> 	 constants at -O0 and thus simplify arithmetic operations.  */
>       if (g == NULL
> 	  && !SSA_NAME_IS_DEFAULT_DEF (exp)
> 	  && (optimize || DECL_IGNORED_P (SSA_NAME_VAR (exp)))
> 	  && (modifier == EXPAND_INITIALIZER
> 
> 	      || (modifier != EXPAND_WRITE
> 
> 		  && gimple_assign_copy_p (SSA_NAME_DEF_STMT (exp))))
> 	  && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp)))
> 	g = SSA_NAME_DEF_STMT (exp);

This doesn't work (this generates wrong code because this creates overlapping 
live ranges for SSA_NAMEs with the same base variable).  Here's the latest 
working version, all the predicates and accessors used are inlined.

Tested on x86_64-suse-linux, OK for the mainline?


2015-05-01  Eric Botcazou  <ebotcazou@adacore.com>

	* expr.c (expand_expr_real_1) <SSA_NAME>: Try to substitute constants
	on the RHS of expressions.
	* gimple-expr.h (is_gimple_constant): Reorder.


-- 
Eric Botcazou
Index: expr.c
===================================================================
--- expr.c	(revision 222673)
+++ expr.c	(working copy)
@@ -9511,11 +9511,17 @@ expand_expr_real_1 (tree exp, rtx target
 	}
 
       g = get_gimple_for_ssa_name (exp);
-      /* For EXPAND_INITIALIZER try harder to get something simpler.  */
+      /* For EXPAND_INITIALIZER try harder to get something simpler.
+	 Otherwise, substitute constants on the RHS, this can make
+	 it possible to simplify arithmetic operations at -O0.  */
       if (g == NULL
-	  && modifier == EXPAND_INITIALIZER
 	  && !SSA_NAME_IS_DEFAULT_DEF (exp)
 	  && (optimize || DECL_IGNORED_P (SSA_NAME_VAR (exp)))
+	  && (modifier == EXPAND_INITIALIZER
+	      || (modifier != EXPAND_WRITE
+		  && gimple_assign_single_p (SSA_NAME_DEF_STMT (exp))
+		  && is_gimple_constant
+		     (gimple_assign_rhs1 (SSA_NAME_DEF_STMT (exp)))))
 	  && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp)))
 	g = SSA_NAME_DEF_STMT (exp);
       if (g)
Index: gimple-expr.h
===================================================================
--- gimple-expr.h	(revision 222673)
+++ gimple-expr.h	(working copy)
@@ -136,9 +136,9 @@ is_gimple_constant (const_tree t)
     case INTEGER_CST:
     case REAL_CST:
     case FIXED_CST:
-    case STRING_CST:
     case COMPLEX_CST:
     case VECTOR_CST:
+    case STRING_CST:
       return true;
 
     default:

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