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

--- Comment #12 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #9)
> Ah, I see, expression_expensive_p is called, but
> number_of_iterations_popcount when creating a CALL_EXPR only cares about
> TYPE_PRECISION and happily creates
> __builtin_popcountl with unsigned long long argument because it has the same
> precision.  tree_builtin_call_types_compatible_p says it is not valid
> builtin call and so we don't consider it expensive.

Shouldn't it run into

      if (!is_inexpensive_builtin (get_callee_fndecl (expr)))
        return true;

then?  Or does that simply consider all popcount as inexpensive?
Yes it does.

I think we should change the above to

diff --git a/gcc/tree-scalar-evolution.cc b/gcc/tree-scalar-evolution.cc
index 44157265ce8..b53d7aaa71d 100644
--- a/gcc/tree-scalar-evolution.cc
+++ b/gcc/tree-scalar-evolution.cc
@@ -3420,12 +3420,15 @@ expression_expensive_p (tree expr, hash_map<tree,
uint64_t> &cache,
                  break;
              return true;
            }
+         break;
+
        default:
+         if (cfn == CFN_LAST
+             || !is_inexpensive_builtin (get_callee_fndecl (expr)))
+           return true;
          break;
        }

-      if (!is_inexpensive_builtin (get_callee_fndecl (expr)))
-       return true;
       FOR_EACH_CALL_EXPR_ARG (arg, iter, expr)
        if (expression_expensive_p (arg, cache, op_cost))
          return true;

> Either we make number_of_iterations_popcount more accurate on the types, or
> better in tree_builtin_call_types_compatible_p use something like:
>   bool in_gimple_form = (cfun && (cfun->curr_properties & PROP_gimple)) != 0;
> and if in_gimple_form, use useless_type_conversion_p instead of the
> TYPE_MAIN_VARIANT / tree_nop_conversion_p checks.
> That is my strong preference...
> 
> What do you think?

Hmm, but still tree_nop_conversion_p would work there, no?

Reply via email to