https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88788

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED

--- Comment #13 from Richard Biener <rguenth at gcc dot gnu.org> ---
I think that using a bitmap to mark SSA names already visited and return
true on those would work as well given returning false should (quickly)
propagate.

thus

diff --git a/gcc/ipa-pure-const.c b/gcc/ipa-pure-const.c
index 37b58853fe1..e14394e9853 100644
--- a/gcc/ipa-pure-const.c
+++ b/gcc/ipa-pure-const.c
@@ -878,10 +878,14 @@ check_retval_uses (tree retval, gimple *stmt)
 }

 static bool
-malloc_candidate_p_1 (function *fun, tree retval, gimple *ret_stmt, bool ipa)
+malloc_candidate_p_1 (function *fun, tree retval, gimple *ret_stmt, bool ipa,
+                     bitmap visited)
 {
   cgraph_node *node = cgraph_node::get_create (fun->decl);

+  if (!bitmap_set_bit (visited, SSA_NAME_VERSION (retval)))
+    return true;
+
   if (!check_retval_uses (retval, ret_stmt))
     DUMP_AND_RETURN("Return value has uses outside return stmt"
                    " and comparisons against 0.")
@@ -925,7 +929,7 @@ malloc_candidate_p_1 (function *fun, tree retval, gimple
*ret_stmt, bool ipa)
            gimple *arg_def = SSA_NAME_DEF_STMT (arg);
            if (is_a<gphi *> (arg_def))
              {
-               if (!malloc_candidate_p_1 (fun, arg, phi, ipa))
+               if (!malloc_candidate_p_1 (fun, arg, phi, ipa, visited))
                    DUMP_AND_RETURN ("nested phi fail")
                continue;
              }
@@ -987,7 +991,8 @@ malloc_candidate_p (function *fun, bool ipa)
          || TREE_CODE (TREE_TYPE (retval)) != POINTER_TYPE)
        DUMP_AND_RETURN("Return value is not SSA_NAME or not a pointer type.")

-      if (!malloc_candidate_p_1 (fun, retval, ret_stmt, ipa))
+      auto_bitmap visited;
+      if (!malloc_candidate_p_1 (fun, retval, ret_stmt, ipa, visited))
        return false;
     }

Reply via email to