This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Fix handling of call clobbering readonly-result


> 
> Richard Earnshaw wrote:
> > Simply build arm-elf cross compilers (--target=arm-elf) with and without 
> > that patch (no need for an assembler).  Then build the testcase using
> > 
> > <gcc-build-dir>/gcc/cc1 -O2 -ffast-math -isystem <gcc-build-dir>
> > /gcc/include <gcc-src-dir>/gcc/testsuite/builtins-6.c
> > 
> > Compare the assembly file differences (there rather obvious ;-)
> 
>  OK, thanks. There are indeed obvious differences, and I wonder if it could
>  be a pre-patch latent bug exposed.
> 
>  Consider the following reduced testcase:
> 
>      int one ()
>      {
>        return 1;
>      }
> 
>      int false (int x)
>      {
>        return 0;
>      }
> 
>      int true ()
>      {
>        return one ();
>      }
> 
>      int main()
>      {
>        int x;
> 
>        x = 80;
>        if (false (x))
> 	 abort ();
>        if (! true ())
> 	 abort ();
> 
>        x = 100;
>        if (false (x))
> 	 abort ();
>        if (! true ())
> 	 abort ();
> 
>        return 0;
>      }
> 
> Both compilers produce the output below, which does not seem quite right
> to me (second call to true() missing):

The second call to true can be eliminated because true() is a const 
function (has no side-effects) -- put a breakpoint on 
mark_const_function).  The compiler has therefore noted that the result of 
the first call can be used in place of the second, and what is more, that 
abort() can never be called from the second point, because if it were, it 
would have been called after the first call.

So I think the compiler has handled this particular example correctly.

R.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]