public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Sandiford <richard.sandiford@arm.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: Richard Biener <rguenther@suse.de>,
	Richard Biener via Gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] gimple.cc: Adjust gimple_call_builtin_p and gimple_call_combined_fn [PR105150]
Date: Wed, 06 Apr 2022 11:30:55 +0100	[thread overview]
Message-ID: <mptk0c2qza8.fsf@arm.com> (raw)
In-Reply-To: <Yk1mpOJaB/mEBTI/@tucnak> (Jakub Jelinek's message of "Wed, 6 Apr 2022 12:08:36 +0200")

Jakub Jelinek <jakub@redhat.com> writes:
> On Wed, Apr 06, 2022 at 11:52:23AM +0200, Richard Biener wrote:
>> On Wed, 6 Apr 2022, Jakub Jelinek wrote:
>> 
>> > On Wed, Apr 06, 2022 at 09:41:44AM +0100, Richard Sandiford wrote:
>> > > But it seems like the magic incantation to detect “real” built-in
>> > > function calls is getting longer and longer.  Can we not abstract this
>> > > in a single place rather than have to repeat the same long sequence in
>> > > multiple places?
>> > 
>> > I've already committed it, so it can be only dealt with an incremental
>> > patch.
>> > One possibility is to do it inside of
>> > gimple_builtin_call_types_compatible_p, after the assert do that:
>> >   if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
>> >     if (tree decl = builtin_decl_explicit (DECL_FUNCTION_CODE (fndecl)))
>> >       fndecl = decl;
>> > but we then lose the theoretical possibility of comparing against the
>> > actual user declaration.  Though I guess in the
>> > gimple-fold.cc
>> > gimple-low.cc
>> > gimple-match-head.cc
>> > calls to that function we also want this rather than what they do currently.
>> 
>> Yes, I think it would be clearer to pass a BUILT_IN_* code to
>> gimple_builtin_call_types_compatible_p and no decl and simply return
>> false if we cannot get out hands at the "proper" decl from
>> builtin_decl_explicit ...
>
> That would mean we wouldn't verify the md or FE builtins anymore
> and we would need to check for BUILT_IN_NORMAL in every caller (right now
> we do that only in some of them).
>
> Here is what I had in mind (untested so far):
>
> 2022-04-06  Jakub Jelinek  <jakub@redhat.com>
>
> 	PR tree-optimization/105150
> 	* gimple.cc (gimple_builtin_call_types_compatible_p): Use
> 	builtin_decl_explicit here...
> 	(gimple_call_builtin_p, gimple_call_combined_fn): ... rather than
> 	here.

Nice!  Thanks for doing this.

Richard

> --- gcc/gimple.cc.jj	2022-04-06 10:07:23.043064595 +0200
> +++ gcc/gimple.cc	2022-04-06 11:31:31.704255242 +0200
> @@ -2788,6 +2788,10 @@ gimple_builtin_call_types_compatible_p (
>  {
>    gcc_checking_assert (DECL_BUILT_IN_CLASS (fndecl) != NOT_BUILT_IN);
>  
> +  if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
> +    if (tree decl = builtin_decl_explicit (DECL_FUNCTION_CODE (fndecl)))
> +      fndecl = decl;
> +
>    tree ret = gimple_call_lhs (stmt);
>    if (ret
>        && !useless_type_conversion_p (TREE_TYPE (ret),
> @@ -2841,12 +2845,7 @@ gimple_call_builtin_p (const gimple *stm
>    if (is_gimple_call (stmt)
>        && (fndecl = gimple_call_fndecl (stmt)) != NULL_TREE
>        && DECL_BUILT_IN_CLASS (fndecl) != NOT_BUILT_IN)
> -    {
> -      if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
> -	if (tree decl = builtin_decl_explicit (DECL_FUNCTION_CODE (fndecl)))
> -	  fndecl = decl;
> -      return gimple_builtin_call_types_compatible_p (stmt, fndecl);
> -    }
> +    return gimple_builtin_call_types_compatible_p (stmt, fndecl);
>    return false;
>  }
>  
> @@ -2859,12 +2858,7 @@ gimple_call_builtin_p (const gimple *stm
>    if (is_gimple_call (stmt)
>        && (fndecl = gimple_call_fndecl (stmt)) != NULL_TREE
>        && DECL_BUILT_IN_CLASS (fndecl) == klass)
> -    {
> -      if (klass == BUILT_IN_NORMAL)
> -	if (tree decl = builtin_decl_explicit (DECL_FUNCTION_CODE (fndecl)))
> -	  fndecl = decl;
> -      return gimple_builtin_call_types_compatible_p (stmt, fndecl);
> -    }
> +    return gimple_builtin_call_types_compatible_p (stmt, fndecl);
>    return false;
>  }
>  
> @@ -2877,11 +2871,7 @@ gimple_call_builtin_p (const gimple *stm
>    if (is_gimple_call (stmt)
>        && (fndecl = gimple_call_fndecl (stmt)) != NULL_TREE
>        && fndecl_built_in_p (fndecl, code))
> -    {
> -      if (tree decl = builtin_decl_explicit (DECL_FUNCTION_CODE (fndecl)))
> -	fndecl = decl;
> -      return gimple_builtin_call_types_compatible_p (stmt, fndecl);
> -    }
> +    return gimple_builtin_call_types_compatible_p (stmt, fndecl);
>    return false;
>  }
>  
> @@ -2898,14 +2888,10 @@ gimple_call_combined_fn (const gimple *s
>  	return as_combined_fn (gimple_call_internal_fn (call));
>  
>        tree fndecl = gimple_call_fndecl (stmt);
> -      if (fndecl && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
> -	{
> -	  tree decl = builtin_decl_explicit (DECL_FUNCTION_CODE (fndecl));
> -	  if (!decl)
> -	    decl = fndecl;
> -	  if (gimple_builtin_call_types_compatible_p (stmt, decl))
> -	    return as_combined_fn (DECL_FUNCTION_CODE (fndecl));
> -	}
> +      if (fndecl
> +	  && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)
> +	  && gimple_builtin_call_types_compatible_p (stmt, fndecl))
> +	return as_combined_fn (DECL_FUNCTION_CODE (fndecl));
>      }
>    return CFN_LAST;
>  }
>
>
> 	Jakub

      parent reply	other threads:[~2022-04-06 10:30 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-05  4:39 [PATCH] match.pd: Punt on optimizing sqrt with incorrect arg type [PR105150] Jakub Jelinek
2022-04-05  8:50 ` Richard Biener
2022-04-05  9:15   ` Jakub Jelinek
2022-04-05  9:28     ` Richard Biener
2022-04-05 14:21       ` [PATCH] gimple.cc: Adjust gimple_call_builtin_p and gimple_call_combined_fn [PR105150] Jakub Jelinek
2022-04-06  6:13         ` Richard Biener
2022-04-06  7:10           ` Jakub Jelinek
2022-04-06  7:40             ` Richard Biener
2022-04-06  8:41               ` Richard Sandiford
2022-04-06  9:02                 ` Jakub Jelinek
2022-04-06  9:52                   ` Richard Biener
2022-04-06 10:08                     ` Jakub Jelinek
2022-04-06 10:25                       ` Richard Biener
2022-04-06 10:30                       ` Richard Sandiford [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=mptk0c2qza8.fsf@arm.com \
    --to=richard.sandiford@arm.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=rguenther@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).