Skip to content

-tailcallopt misses optimization for default(CallingConv::C) calling conversion #9594

@llvmbot

Description

@llvmbot
Bugzilla Link 9222
Version trunk
OS All
Reporter LLVM Bugzilla Contributor

Extended Description

I understand -tailcallopt enables "fastcc" as "guaranteed tailcall", to emit fastcc functions as callee stack rewind. It is known to work well.

In contrast, it seems -tailcallopt disables tailjmp optimization for default calling conversions. I guess it would be misoptimization.

In X86ISelLowering.cpp:

static bool IsTailCallConvention(CallingConv::ID CC) {
  return (CC == CallingConv::Fast || CC == CallingConv::GHC);
}

X86TargetLowering::IsEligibleForTailCallOptimization(),

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

It seems CallingConv::C would be missed.

; 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

; llc -mtriple=x86_64-linux #(w/o -tailcallopt)

caller_c:
        jmp     callee_c                # TAILCALL
caller_f:
        jmp     callee_f                # TAILCALL

; llc -mtriple=x86_64-linux -tailcallopt
caller_c:
        pushq   %rax
        callq   callee_c
        popq    %rax
        ret
caller_f:
        pushq   %rax       # bug 8925
        popq    %rax
        jmp     callee_f                # TAILCALL

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions