TargetLowering::CallLoweringInfo.IsTailCall

As far as I know, when SelectionDAG Builder meets a “call” Node, it will trigger the TargetLowering::LowerCall() implemented by specified target.

For “tail call” Node in llvm IR, as below

%call = tail call i32 @callee4(i32 1, i32 %a0) nounwind

How can I know is it a normal call or tail call in TargetLowering::LowerCall() ? Since the CallLoweringInfo.IsTailCall is always false, said by llvm doxygen:

 // IsTailCall should be modified by implementations of
    // TargetLowering::LowerCall that perform tail call conversions.
    bool IsTailCall = false;

I use .ll file whicn include tail call node to test the CallLoweringInfo.IsTailCall in LowerCall(), and it always be false , no matter it’s a normal call or tail call.

what about using CallLoweringInfo::CB?

1 Like

I afraid LLVM 10.0.0 doesn’t have CLI.CB.

Any way, I check other target’s(RISCV,MIPS) implementation of lowercall, they also use CLI.IsTailCall to identify a taill call node.

So I guess, before entering TargetLowering::lowercall(), LLVM did some optimization that convert the tail call in llvm IR into normal call.

Could any one provide me a test C program that definitely leaves a taill call node ?

You also need to implement mayBeEmittedAsTailCall

1 Like

Thank you !
Should I implement it as:

bool LoongArchTargetLowering::mayBeEmittedAsTailCall(const CallInst *CI) const {
    return CI->isTailCall();
}

or :

bool LoongArchTargetLowering::mayBeEmittedAsTailCall(const CallInst *CI) const {
    return true;
}

I implemented mayBeEmittedAsTailCall() in targetLowering, but Nothing changed . I used gdb to test it(seting a breakpoint in it), it turns out to be unused , nothing referenced it.

But it is called by llvm/lib/CodeGen/CodeGenPrepare.cpp, at least, it could be. Perhaps you could break where CodeGenPrepare calls the function and see if that path is taken. Then you can look at all the other conditions and find what else you need to add.