X86 -tailcallopt and C calling conversion

Happy 2011, everybody!

It seems -tailcallopt prevents tailcall optimization when both caller
and callee have ccc,
even when it is optimized without an option -tailcallopt.
Is it intended or misoptimized?

In X86ISelLowering.cpp:X86TargetLowering::IsEligibleForTailCallOptimization():

  if (GuaranteedTailCallOpt) {
    if (IsTailCallConvention(CalleeCC) && CCMatch)
      return true;
    return false;
  }

I know -tailcallopt changes calling conversion of fastcc to callee-pop.

ps. I am tweaking tailcallopt on Win64.

...Takumi

Happy 2011, everybody!

It seems -tailcallopt prevents tailcall optimization when both caller
and callee have ccc,
even when it is optimized without an option -tailcallopt.

Sorry, I don't understand your question. What do you mean by both caller and callee have ccc?

Evan

Hello Evan,

I am sorry for my poor question.
s/ccc/default calling conversion/g :wink:
("ccc" should be accepted as calling conversion specifier)

When "-tailcallopt" is specified (GuaranteedTailCallOpt),
tailcall optimizer would not touch functions of default calling conversion.

; for example
define void @caller_c() nounwind {
entry:
  tail call void @callee_c()
  ret void
}
declare void @callee_c() nounwind

define fastcc void @caller_f() nounwind {
entry:
  tail call fastcc void @callee_f()
  ret void
}
declare fastcc void @callee_f() nounwind

On {i686|x86_64}-linux without -tailcallopt,
caller_c:
        jmp callee_c # TAILCALL
caller_f:
        jmp callee_f # TAILCALL

With -tailcallopt, (on x86-64. simila on i686 too)
caller_c:
        pushq %rax
        callq callee_c
        popq %rax
        ret
caller_f:
        pushq %rax
        popq %rax
        jmp callee_f # TAILCALL

...Takumi