Skip to content

Commit e21ab22

Browse files
committed
[FunctionComparator] Consider tail call kinds
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
1 parent 685565a commit e21ab22

File tree

2 files changed

+32
-22
lines changed

2 files changed

+32
-22
lines changed

llvm/lib/Transforms/Utils/FunctionComparator.cpp

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -557,31 +557,20 @@ int FunctionComparator::cmpOperations(const Instruction *L,
557557
}
558558
if (const CmpInst *CI = dyn_cast<CmpInst>(L))
559559
return cmpNumbers(CI->getPredicate(), cast<CmpInst>(R)->getPredicate());
560-
if (const CallInst *CI = dyn_cast<CallInst>(L)) {
561-
if (int Res = cmpNumbers(CI->getCallingConv(),
562-
cast<CallInst>(R)->getCallingConv()))
560+
if (auto CSL = CallSite(const_cast<Instruction *>(L))) {
561+
auto CSR = CallSite(const_cast<Instruction *>(R));
562+
if (int Res = cmpNumbers(CSL.getCallingConv(), CSR.getCallingConv()))
563563
return Res;
564-
if (int Res =
565-
cmpAttrs(CI->getAttributes(), cast<CallInst>(R)->getAttributes()))
566-
return Res;
567-
if (int Res = cmpOperandBundlesSchema(CI, R))
564+
if (int Res = cmpAttrs(CSL.getAttributes(), CSR.getAttributes()))
568565
return Res;
569-
return cmpRangeMetadata(
570-
CI->getMetadata(LLVMContext::MD_range),
571-
cast<CallInst>(R)->getMetadata(LLVMContext::MD_range));
572-
}
573-
if (const InvokeInst *II = dyn_cast<InvokeInst>(L)) {
574-
if (int Res = cmpNumbers(II->getCallingConv(),
575-
cast<InvokeInst>(R)->getCallingConv()))
566+
if (int Res = cmpOperandBundlesSchema(L, R))
576567
return Res;
577-
if (int Res =
578-
cmpAttrs(II->getAttributes(), cast<InvokeInst>(R)->getAttributes()))
579-
return Res;
580-
if (int Res = cmpOperandBundlesSchema(II, R))
581-
return Res;
582-
return cmpRangeMetadata(
583-
II->getMetadata(LLVMContext::MD_range),
584-
cast<InvokeInst>(R)->getMetadata(LLVMContext::MD_range));
568+
if (const CallInst *CI = dyn_cast<CallInst>(L))
569+
if (int Res = cmpNumbers(CI->getTailCallKind(),
570+
cast<CallInst>(R)->getTailCallKind()))
571+
return Res;
572+
return cmpRangeMetadata(L->getMetadata(LLVMContext::MD_range),
573+
R->getMetadata(LLVMContext::MD_range));
585574
}
586575
if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(L)) {
587576
ArrayRef<unsigned> LIndices = IVI->getIndices();
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
; RUN: opt -mergefunc -S < %s | FileCheck %s
2+
3+
declare void @dummy()
4+
5+
; CHECK-LABEL: define{{.*}}@foo
6+
; CHECK: call {{.*}}@dummy
7+
; CHECK: musttail {{.*}}@dummy
8+
define void @foo() {
9+
call void @dummy()
10+
musttail call void @dummy()
11+
ret void
12+
}
13+
14+
; CHECK-LABEL: define{{.*}}@bar
15+
; CHECK: call {{.*}}@dummy
16+
; CHECK: call {{.*}}@dummy
17+
define void @bar() {
18+
call void @dummy()
19+
call void @dummy()
20+
ret void
21+
}

0 commit comments

Comments
 (0)