]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
cselib: Simplify references_value_p
authorRichard Sandiford <rdsandiford@googlemail.com>
Wed, 20 May 2026 16:36:02 +0000 (17:36 +0100)
committerRichard Sandiford <rdsandiford@googlemail.com>
Wed, 20 May 2026 16:36:02 +0000 (17:36 +0100)
The previous patch removed the only caller of references_value_p
to want the only_useless behaviour.  This patch therefore removes
that parameter and converts the function to an iterator.

I don't have numbers to show that using an iterator is better after the
previous patch.  But converting to an iterator was the first low-hanging
fruit that I tried for the insn-extract.cc slowness, at a time when
references_value_p accounted for over 50% of compile time on aarch64.
It made a significant difference then.

gcc/
* cselib.h (references_value_p): Remove only_useless parameter.
* cselib.cc (references_value_p): Likewise.  Use rtx iterators.
(invariant_or_equiv_p): Update accordingly.
* postreload.cc (reload_cse_simplify_set): Likewise.
* var-tracking.cc (reverse_op): Likewise.

gcc/cselib.cc
gcc/cselib.h
gcc/postreload.cc
gcc/var-tracking.cc

index e029d827fcdd6e5caf6eed19565b248a6e7fcc4c..53f2ea1856885a5b4a1e4870d76703ac0980a50a 100644 (file)
@@ -515,7 +515,7 @@ invariant_or_equiv_p (cselib_val *v)
     {
       if (CONSTANT_P (v->locs->loc)
          && (GET_CODE (v->locs->loc) != CONST
-             || !references_value_p (v->locs->loc, 0)))
+             || !references_value_p (v->locs->loc)))
        return true;
       /* Although a debug expr may be bound to different expressions,
         we can preserve it as if it was constant, to get unification
@@ -673,27 +673,12 @@ cselib_find_slot (machine_mode mode, rtx x, hashval_t hash,
    removed.  */
 
 bool
-references_value_p (const_rtx x, int only_useless)
+references_value_p (const_rtx x)
 {
-  const enum rtx_code code = GET_CODE (x);
-  const char *fmt = GET_RTX_FORMAT (code);
-  int i, j;
-
-  if (GET_CODE (x) == VALUE
-      && (! only_useless
-         || (CSELIB_VAL_PTR (x)->locs == 0 && !PRESERVED_VALUE_P (x))))
-    return true;
-
-  for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
-    {
-      if (fmt[i] == 'e' && references_value_p (XEXP (x, i), only_useless))
-       return true;
-      else if (fmt[i] == 'E')
-       for (j = 0; j < XVECLEN (x, i); j++)
-         if (references_value_p (XVECEXP (x, i, j), only_useless))
-           return true;
-    }
-
+  subrtx_iterator::array_type array;
+  FOR_EACH_SUBRTX (iter, array, x, ALL)
+    if (GET_CODE (*iter) == VALUE)
+      return true;
   return false;
 }
 
index 69256a02632a475aae52522a9805634dec9d2c13..df7771e030ef29b6ccf8ab5c357f52c09d36ed8e 100644 (file)
@@ -94,7 +94,7 @@ extern bool fp_setter_insn (rtx_insn *);
 extern machine_mode cselib_reg_set_mode (const_rtx);
 extern bool rtx_equal_for_cselib_1 (rtx, rtx, machine_mode, int);
 extern bool cselib_redundant_set_p (rtx);
-extern bool references_value_p (const_rtx, int);
+extern bool references_value_p (const_rtx);
 extern rtx cselib_expand_value_rtx (rtx, bitmap, int);
 typedef rtx (*cselib_expand_callback)(rtx, bitmap, int, void *);
 extern rtx cselib_expand_value_rtx_cb (rtx, bitmap, int,
index 80a65796efb87591d97299887f7e44c13c35b8f3..117e449fedd2d8868c87faf065cd83ed79f73f0c 100644 (file)
@@ -387,7 +387,7 @@ reload_cse_simplify_set (rtx set, rtx_insn *insn)
       rtx this_rtx = l->loc;
       int this_cost;
 
-      if (CONSTANT_P (this_rtx) && ! references_value_p (this_rtx, 0))
+      if (CONSTANT_P (this_rtx) && ! references_value_p (this_rtx))
        {
          if (extend_op != UNKNOWN)
            {
index e7065e81ca55984b05502a0473f23ca92d3f8958..8bf9bd58079815d2c52dd8c0bc9e94f078e267b9 100644 (file)
@@ -5900,7 +5900,7 @@ reverse_op (rtx val, const_rtx expr, rtx_insn *insn)
      prefer non-ENTRY_VALUE locations whenever possible.  */
   for (l = v->locs, count = 0; l; l = l->next, count++)
     if (CONSTANT_P (l->loc)
-       && (GET_CODE (l->loc) != CONST || !references_value_p (l->loc, 0)))
+       && (GET_CODE (l->loc) != CONST || !references_value_p (l->loc)))
       return;
     /* Avoid creating too large locs lists.  */
     else if (count == param_max_vartrack_reverse_op_size)