[PATCH] Stop putting operations after a tail call

Tobias Grosser tobias at grosser.es
Tue Jul 2 15:38:11 PDT 2013


On 07/02/2013 12:25 PM, Tim Northover wrote:
> Hi,
>
> compnerd recently pointed out a disturbingly trivial failure when
> enabling tail calls on ARM Linux targets (though fortunately probably
> inaccessible from clang):
>
>      declare i8* @g(i8*)
>
>      define i8* @f(i8* %a) {
>      entry:
>        %0 = tail call i8* @g(i8* %a)
>        ret i8* %0
>      }
>
> When compiled at -O0 this hits an assertion failure[1]. There are many
> steps along the way, but I think the first objectively wrong decision
> is putting a tokenfactor for vreg exports (and hence possibly other
> operations) after the TC_RETURN instruction.
>
> The attached patch simply forgets about any pending vreg exports when
> a tail-call is encountered. Intuitively this seems like right (or at
> least harmless) behaviour, but I'm not familiar enough with FastISel
> to be sure.
>
> Does it seem reasonable?

Without knowing a whole lot about this, I cite the langref:

"The optional “tail” marker indicates that the callee function does not 
access any allocas or varargs in the caller. Note that calls may be 
marked “tail” even if they do not occur before a ret instruction. If the 
“tail” marker is present, the function call is eligible for tail call 
optimization, but might not in fact be optimized into a jump. [...]"

Especially the last sentence makes me wonder if this change is legal.

Tobias



More information about the llvm-commits mailing list