[llvm-commits] [PATCH] Tail recursion elimination and memory loads.

Chris Lattner clattner at apple.com
Thu Jun 18 21:22:55 PDT 2009

On Jun 16, 2009, at 1:49 PM, Frits van Bommel wrote:

> When tail recursion elimination (opt -tailcallelim) sees other  
> instructions between the recursive call and the return instruction,  
> it tries to figure out if it's safe to move them above the call  
> (putting the call in tail position).
> However, it refuses to do that for load instructions after the call.
> The attached patch checks for some conditions in which it is safe to  
> do this for loads as well.
> There are two basic cases:
> 1) The call has no side-effects, in which case it's always safe  
> since the load would happen anyway and it shouldn't matter if it's  
> done a bit sooner.
> 2) The load is non-volatile, the call does not write to memory, and  
> the pointer isSafeToLoadUnconditionally() at that point in the code.  
> In this case, the load has no side-effects (and won't trap) and the  
> memory it loads from won't contain different data after the call,  
> making it safe to raise the load above the call.

Looks great, applied here:

Note that volatile loads return true for "may write to memory" so they  
don't need special handling,

Thanks Frits!


More information about the llvm-commits mailing list