Index: llvm/lib/Transforms/Utils/FunctionComparator.cpp =================================================================== --- llvm/lib/Transforms/Utils/FunctionComparator.cpp +++ llvm/lib/Transforms/Utils/FunctionComparator.cpp @@ -557,31 +557,20 @@ } if (const CmpInst *CI = dyn_cast(L)) return cmpNumbers(CI->getPredicate(), cast(R)->getPredicate()); - if (const CallInst *CI = dyn_cast(L)) { - if (int Res = cmpNumbers(CI->getCallingConv(), - cast(R)->getCallingConv())) + if (auto CSL = CallSite(const_cast(L))) { + auto CSR = CallSite(const_cast(R)); + if (int Res = cmpNumbers(CSL.getCallingConv(), CSR.getCallingConv())) return Res; - if (int Res = - cmpAttrs(CI->getAttributes(), cast(R)->getAttributes())) - return Res; - if (int Res = cmpOperandBundlesSchema(CI, R)) + if (int Res = cmpAttrs(CSL.getAttributes(), CSR.getAttributes())) return Res; - return cmpRangeMetadata( - CI->getMetadata(LLVMContext::MD_range), - cast(R)->getMetadata(LLVMContext::MD_range)); - } - if (const InvokeInst *II = dyn_cast(L)) { - if (int Res = cmpNumbers(II->getCallingConv(), - cast(R)->getCallingConv())) + if (int Res = cmpOperandBundlesSchema(L, R)) return Res; - if (int Res = - cmpAttrs(II->getAttributes(), cast(R)->getAttributes())) - return Res; - if (int Res = cmpOperandBundlesSchema(II, R)) - return Res; - return cmpRangeMetadata( - II->getMetadata(LLVMContext::MD_range), - cast(R)->getMetadata(LLVMContext::MD_range)); + if (const CallInst *CI = dyn_cast(L)) + if (int Res = cmpNumbers(CI->getTailCallKind(), + cast(R)->getTailCallKind())) + return Res; + return cmpRangeMetadata(L->getMetadata(LLVMContext::MD_range), + R->getMetadata(LLVMContext::MD_range)); } if (const InsertValueInst *IVI = dyn_cast(L)) { ArrayRef LIndices = IVI->getIndices(); Index: llvm/test/Transforms/MergeFunc/tailcall.ll =================================================================== --- /dev/null +++ llvm/test/Transforms/MergeFunc/tailcall.ll @@ -0,0 +1,21 @@ +; RUN: opt -mergefunc -S < %s | FileCheck %s + +declare void @dummy() + +; CHECK-LABEL: define{{.*}}@foo +; CHECK: call {{.*}}@dummy +; CHECK: musttail {{.*}}@dummy +define void @foo() { + call void @dummy() + musttail call void @dummy() + ret void +} + +; CHECK-LABEL: define{{.*}}@bar +; CHECK: call {{.*}}@dummy +; CHECK: call {{.*}}@dummy +define void @bar() { + call void @dummy() + call void @dummy() + ret void +}