public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] More maybe_fold_reference TLC
@ 2021-05-11 10:54 Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2021-05-11 10:54 UTC (permalink / raw)
  To: gcc-patches

This adjusts maybe_fold_reference to adhere to its desired behavior
of performing constant folding and thus explicitely avoid returning
unfolded reference trees.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

2021-05-11  Richard Biener  <rguenther@suse.de>

	* gimple-fold.c (maybe_fold_reference): Only return
	is_gimple_min_invariant values.
---
 gcc/gimple-fold.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index 6beb4f3d305..74ec36e3a78 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -311,27 +311,28 @@ get_symbol_constant_value (tree sym)
 static tree
 maybe_fold_reference (tree expr)
 {
-  tree result;
+  tree result = NULL_TREE;
 
   if ((TREE_CODE (expr) == VIEW_CONVERT_EXPR
        || TREE_CODE (expr) == REALPART_EXPR
        || TREE_CODE (expr) == IMAGPART_EXPR)
       && CONSTANT_CLASS_P (TREE_OPERAND (expr, 0)))
-    return fold_unary_loc (EXPR_LOCATION (expr),
-			   TREE_CODE (expr),
-			   TREE_TYPE (expr),
-			   TREE_OPERAND (expr, 0));
-  else if (TREE_CODE (expr) == BIT_FIELD_REF
-	   && CONSTANT_CLASS_P (TREE_OPERAND (expr, 0)))
-    return fold_ternary_loc (EXPR_LOCATION (expr),
+    result = fold_unary_loc (EXPR_LOCATION (expr),
 			     TREE_CODE (expr),
 			     TREE_TYPE (expr),
-			     TREE_OPERAND (expr, 0),
-			     TREE_OPERAND (expr, 1),
-			     TREE_OPERAND (expr, 2));
+			     TREE_OPERAND (expr, 0));
+  else if (TREE_CODE (expr) == BIT_FIELD_REF
+	   && CONSTANT_CLASS_P (TREE_OPERAND (expr, 0)))
+    result = fold_ternary_loc (EXPR_LOCATION (expr),
+			       TREE_CODE (expr),
+			       TREE_TYPE (expr),
+			       TREE_OPERAND (expr, 0),
+			       TREE_OPERAND (expr, 1),
+			       TREE_OPERAND (expr, 2));
+  else
+    result = fold_const_aggregate_ref (expr);
 
-  if ((result = fold_const_aggregate_ref (expr))
-      && is_gimple_min_invariant (result))
+  if (result && is_gimple_min_invariant (result))
     return result;
 
   return NULL_TREE;
-- 
2.26.2

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH] More maybe_fold_reference TLC
@ 2021-05-11 13:59 Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2021-05-11 13:59 UTC (permalink / raw)
  To: gcc-patches

This removes stale users of maybe_fold_reference where IL constraints
make it never do anything.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

2021-05-11  Richard Biener  <rguenther@suse.de>

	* gimple-fold.c (gimple_fold_call): Do not call
	maybe_fold_reference on call arguments or the static chain.
	(fold_stmt_1): Do not call maybe_fold_reference on GIMPLE_ASM
	inputs.
---
 gcc/gimple-fold.c | 59 -----------------------------------------------
 1 file changed, 59 deletions(-)

diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index 74ec36e3a78..68717cf1542 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -5447,19 +5447,6 @@ gimple_fold_call (gimple_stmt_iterator *gsi, bool inplace)
   gcall *stmt = as_a <gcall *> (gsi_stmt (*gsi));
   tree callee;
   bool changed = false;
-  unsigned i;
-
-  /* Fold *& in call arguments.  */
-  for (i = 0; i < gimple_call_num_args (stmt); ++i)
-    if (REFERENCE_CLASS_P (gimple_call_arg (stmt, i)))
-      {
-	tree tmp = maybe_fold_reference (gimple_call_arg (stmt, i));
-	if (tmp)
-	  {
-	    gimple_call_set_arg (stmt, i, tmp);
-	    changed = true;
-	  }
-      }
 
   /* Check for virtual calls that became direct calls.  */
   callee = gimple_call_fn (stmt);
@@ -5562,15 +5549,6 @@ gimple_fold_call (gimple_stmt_iterator *gsi, bool inplace)
 	  gimple_call_set_chain (stmt, NULL);
 	  changed = true;
 	}
-      else
-	{
-	  tree tmp = maybe_fold_reference (gimple_call_chain (stmt));
-	  if (tmp)
-	    {
-	      gimple_call_set_chain (stmt, tmp);
-	      changed = true;
-	    }
-	}
     }
 
   if (inplace)
@@ -6285,43 +6263,6 @@ fold_stmt_1 (gimple_stmt_iterator *gsi, bool inplace, tree (*valueize) (tree))
       changed |= gimple_fold_call (gsi, inplace);
       break;
 
-    case GIMPLE_ASM:
-      /* Fold *& in asm operands.  */
-      {
-	gasm *asm_stmt = as_a <gasm *> (stmt);
-	size_t noutputs;
-	const char **oconstraints;
-	const char *constraint;
-	bool allows_mem, allows_reg;
-
-	noutputs = gimple_asm_noutputs (asm_stmt);
-	oconstraints = XALLOCAVEC (const char *, noutputs);
-
-	for (i = 0; i < noutputs; ++i)
-	  {
-	    tree link = gimple_asm_output_op (asm_stmt, i);
-	    oconstraints[i]
-	      = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link)));
-	  }
-	for (i = 0; i < gimple_asm_ninputs (asm_stmt); ++i)
-	  {
-	    tree link = gimple_asm_input_op (asm_stmt, i);
-	    tree op = TREE_VALUE (link);
-	    constraint
-	      = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link)));
-	    parse_input_constraint (&constraint, 0, 0, noutputs, 0,
-				    oconstraints, &allows_mem, &allows_reg);
-	    if (REFERENCE_CLASS_P (op)
-		&& (allows_reg || !allows_mem)
-		&& (op = maybe_fold_reference (op)) != NULL_TREE)
-	      {
-		TREE_VALUE (link) = op;
-		changed = true;
-	      }
-	  }
-      }
-      break;
-
     case GIMPLE_DEBUG:
       if (gimple_debug_bind_p (stmt))
 	{
-- 
2.26.2

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-11 13:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-11 10:54 [PATCH] More maybe_fold_reference TLC Richard Biener
2021-05-11 13:59 Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).