This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Can I force gcc not to optimize calling to leaf functions with `-O2' option?
- From: John Fine <johnsfine at verizon dot net>
- To: PRC <panruochen at gmail dot com>
- Cc: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Sat, 29 Mar 2008 10:24:12 -0400
- Subject: Re: Can I force gcc not to optimize calling to leaf functions with `-O2' option?
- References: <200803291611208655796@gmail.com>
The optimization you described is called a "function tail merge". You
can disable that optimization without disabling the rest of -O2. I
forget the exact switch, but I expect a search for "tail merge" would
find it.
PRC wrote:
> Hi All,
> I wonder if I can inform gcc not to optimize calling to leaf functions.
>
> For example
> -------------------
> void say_hello()
> {
> printf("Hello\n");
> }
> void func()
> {
> say_hello();
> }
>
>
> with -O2 option, gcc will optimize
> jal say_hello
> ...
> jr ra
> ...
> to
> j say_hello
>
> This is not what I want in some case. The start of the function can be located
> by searching `addiu sp, XXXX' instruction, and the end of the function by
> searching `jr ra', beginning with EPC when expctions arise, if all function calls
> have their own exits. By this way, I can trace down the calling frames. But this
> optimization breaks the rule and will confused the tracer. And the `-O2' option
> is neccessary since some bugs are only exposed on `-O2'.
>
> Is there an approach for this purpose?
>
> Best Regards
> PRC
> Mar 29, 2008
>
>
>