[LLVMdev] opt -std-compile-opts breaks tail calls

Jon Harrop jon at ffconsultancy.com
Fri Nov 13 03:34:48 PST 2009


On Friday 13 November 2009 04:57:43 David Terei wrote:
> I've run into some issues with tail calls in the past, make sure you
> are doing the following:
>
> 1. Call should be marked with tail (obviously)
> 2. Next statement after tail call should be 'return void'
> 3. Use fast call convention for tail calls
> 4. Make sure the function you are calling doesn't use the 'noreturn'
> attribute. 5. Turn on tail calls in llc (if using the static compiler),
> with
> '-tailcallopt' option.
>
> Point 4 is the one that caused me trouble for some time. Unfortunately
> it causes a bad interaction with the optimiser, specifically the
> 'simplifycfg' pass. What seems to happen is that since the function
> you are calling is marked with 'noreturn', the simplifycfg pass will
> then put a 'unreachable' statement after the tail call to that
> function. This stuffs up the tail call though as the llc compiler
> requires tail calls be followed by a 'return void' statement. In my
> case this caused my compiled programs to segfault if the llvm
> optimiser was run on them.

Isn't that a bug in LLVM?

> I haven't fully investigated this yet so not really sure if it is
> specific to my case or applies universally but it sure did cause me
> some pains for a while.

HLVM is certainly abiding by the requirements for tail calls or they wouldn't 
be working with the JIT and unoptimized static compilation. The problem only 
appears when the code is run through "opt". However, I am assuming that this 
segmentation fault is the result of a broken tail call. Perhaps it is 
something else...

-- 
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e



More information about the llvm-dev mailing list