jhc vs ghc and the surprising result involving ghcgeneratedassembly.

Florian Weimer fw at deneb.enyo.de
Wed Nov 2 11:56:26 EST 2005


* Simon Marlow:

>> However, beginning with GCC 3.4, you can use:
>> 
>> extern void bar();
>> 
>> void foo()
>> {
>>   void (*p)(void) = bar;
>>   p();
>> }
>
> Interesting.. though I'm not sure I'm comfortable with relying on gcc's
> tail call optimisation to do the right thing.  Aren't there side
> conditions that might prevent it from kicking in?

It's a target-specific optimization.  For i386, the requirements are
roughly speaking, (a) it works with -fPIC only for very special cases
(direct calls within the same module), (b) the return values must be
the same, (c) for indirect calls, there must be a free register
(currently, this means that regparam must be less than 3; irrelevant
if you don't pass any arguments).

AMD64 has only very few restrictions, none of which seem particularly
relevant.

ia64 may need additional hints before the optimization is performed
(non-default visibility of the target function), otherwise the
optimization is only performed within the same translation unit.
PowerPC and SPARC cannot optimize indirect calls.

Common MIPS targets should be fine.

So your concern is valid; this optimization is not always available.
It might be possible to extend GCC with something that violates the
ABI and fits your needs, though, in case the current goto hack no
longer works.


More information about the Glasgow-haskell-users mailing list