diff mbox series

Do not check gimple_call_chain in tree-ssa-alias

Message ID 20211125131105.GA85959@kam.mff.cuni.cz
State Committed
Commit f4e470d44e8104bada6a95c12765f6ed8bd505e2
Headers show
Series Do not check gimple_call_chain in tree-ssa-alias | expand

Commit Message

Jan Hubicka Nov. 25, 2021, 1:11 p.m. UTC
Hi,
this pach removes gimple_call_cahin checkin ref_maybe_used_by_call_p that
disables check for CONST functions.  I suppose it was meant to allow consts
to read variables from the static chain but this is not what other places
do.  The testcase:

int
main()
{
        int a =0;
        __attribute__ ((noinline,const))
        int reta ()
        {
                return a;
        }
        int val = reta();
        a=1;
        return val+reta ();
}

Gets optimized to single call of reta since at least gcc 4.1.

LTO bootstrapped and regtested x86_64-linux all languages. OK?

	* tree-ssa-alias.c (ref_maybe_used_by_call_p_1): Do not check
	gimple_call_call when treating const functions.

Comments

Richard Biener Nov. 25, 2021, 1:35 p.m. UTC | #1
On Thu, 25 Nov 2021, Jan Hubicka wrote:

> Hi,
> this pach removes gimple_call_cahin checkin ref_maybe_used_by_call_p that
> disables check for CONST functions.  I suppose it was meant to allow consts
> to read variables from the static chain but this is not what other places
> do.  The testcase:
> 
> int
> main()
> {
>         int a =0;
>         __attribute__ ((noinline,const))
>         int reta ()
>         {
>                 return a;
>         }
>         int val = reta();
>         a=1;
>         return val+reta ();
> }
> 
> Gets optimized to single call of reta since at least gcc 4.1.
> 
> LTO bootstrapped and regtested x86_64-linux all languages. OK?

I suppose at some point it broke.

But yes, I agree, thus OK.

Thanks,
Richard.

> 	* tree-ssa-alias.c (ref_maybe_used_by_call_p_1): Do not check
> 	gimple_call_call when treating const functions.
> 
> diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c
> index cd6a0b2f67b..3c253e2843f 100644
> --- a/gcc/tree-ssa-alias.c
> +++ b/gcc/tree-ssa-alias.c
> @@ -2743,9 +2743,7 @@ ref_maybe_used_by_call_p_1 (gcall *call, ao_ref *ref, bool tbaa_p)
>    unsigned i;
>    int flags = gimple_call_flags (call);
>  
> -  /* Const functions without a static chain do not implicitly use memory.  */
> -  if (!gimple_call_chain (call)
> -      && (flags & (ECF_CONST|ECF_NOVOPS)))
> +  if (flags & (ECF_CONST|ECF_NOVOPS))
>      goto process_args;
>  
>    /* A call that is not without side-effects might involve volatile
>
diff mbox series

Patch

diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c
index cd6a0b2f67b..3c253e2843f 100644
--- a/gcc/tree-ssa-alias.c
+++ b/gcc/tree-ssa-alias.c
@@ -2743,9 +2743,7 @@  ref_maybe_used_by_call_p_1 (gcall *call, ao_ref *ref, bool tbaa_p)
   unsigned i;
   int flags = gimple_call_flags (call);
 
-  /* Const functions without a static chain do not implicitly use memory.  */
-  if (!gimple_call_chain (call)
-      && (flags & (ECF_CONST|ECF_NOVOPS)))
+  if (flags & (ECF_CONST|ECF_NOVOPS))
     goto process_args;
 
   /* A call that is not without side-effects might involve volatile