Skip to content

Commit

Permalink
[FunctionComparator] Consider tail call kinds
Browse files Browse the repository at this point in the history
Essentially, do not treat `call` and `musttail call` as the same thing.

As a drive-by, fold CallInst and InvokeInst handling together using the
CallSite helper.

Differential Revision: https://reviews.llvm.org/D56815

llvm-svn: 351405
  • Loading branch information
vedantk committed Jan 17, 2019
1 parent 685565a commit e21ab22
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
33 changes: 11 additions & 22 deletions llvm/lib/Transforms/Utils/FunctionComparator.cpp
Expand Up @@ -557,31 +557,20 @@ int FunctionComparator::cmpOperations(const Instruction *L,
}
if (const CmpInst *CI = dyn_cast<CmpInst>(L))
return cmpNumbers(CI->getPredicate(), cast<CmpInst>(R)->getPredicate());
if (const CallInst *CI = dyn_cast<CallInst>(L)) {
if (int Res = cmpNumbers(CI->getCallingConv(),
cast<CallInst>(R)->getCallingConv()))
if (auto CSL = CallSite(const_cast<Instruction *>(L))) {
auto CSR = CallSite(const_cast<Instruction *>(R));
if (int Res = cmpNumbers(CSL.getCallingConv(), CSR.getCallingConv()))
return Res;
if (int Res =
cmpAttrs(CI->getAttributes(), cast<CallInst>(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<CallInst>(R)->getMetadata(LLVMContext::MD_range));
}
if (const InvokeInst *II = dyn_cast<InvokeInst>(L)) {
if (int Res = cmpNumbers(II->getCallingConv(),
cast<InvokeInst>(R)->getCallingConv()))
if (int Res = cmpOperandBundlesSchema(L, R))
return Res;
if (int Res =
cmpAttrs(II->getAttributes(), cast<InvokeInst>(R)->getAttributes()))
return Res;
if (int Res = cmpOperandBundlesSchema(II, R))
return Res;
return cmpRangeMetadata(
II->getMetadata(LLVMContext::MD_range),
cast<InvokeInst>(R)->getMetadata(LLVMContext::MD_range));
if (const CallInst *CI = dyn_cast<CallInst>(L))
if (int Res = cmpNumbers(CI->getTailCallKind(),
cast<CallInst>(R)->getTailCallKind()))
return Res;
return cmpRangeMetadata(L->getMetadata(LLVMContext::MD_range),
R->getMetadata(LLVMContext::MD_range));
}
if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(L)) {
ArrayRef<unsigned> LIndices = IVI->getIndices();
Expand Down
21 changes: 21 additions & 0 deletions 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
}

0 comments on commit e21ab22

Please sign in to comment.