Skip to content

Commit 55ea3e2

Browse files
committed
Add tailcall tests.
Created using spr 1.3.6-beta.1
2 parents 3eee130 + 9ceb54c commit 55ea3e2

14 files changed

+132
-6
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -4111,6 +4111,11 @@ Instruction *InstCombinerImpl::visitCallBase(CallBase &Call) {
41114111
Call, Builder.CreateBitOrPointerCast(ReturnedArg, CallTy));
41124112
}
41134113

4114+
// Drop unnecessary callee_type metadata from calls that were converted
4115+
// into direct calls.
4116+
if (Call.getMetadata(LLVMContext::MD_callee_type) && !Call.isIndirectCall())
4117+
Call.setMetadata(LLVMContext::MD_callee_type, nullptr);
4118+
41144119
// Drop unnecessary kcfi operand bundles from calls that were converted
41154120
// into direct calls.
41164121
auto Bundle = Call.getOperandBundle(LLVMContext::OB_kcfi);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
;; Tests that call site callee type ids can be extracted and set from
2+
;; callee_type metadata for indirect tail calls.
3+
4+
;; Verify the exact calleeTypeId value to ensure it is not garbage but the value
5+
;; computed as the type id from the callee_type metadata.
6+
; RUN: llc --call-graph-section -mtriple aarch64-linux-gnu < %s -stop-after=finalize-isel -o - | FileCheck %s
7+
8+
define dso_local noundef i32 @_Z13call_indirectPFicEc(ptr noundef readonly captures(none) %func, i8 noundef signext %x) local_unnamed_addr !type !0 {
9+
entry:
10+
; CHECK: callSites:
11+
; CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [], calleeTypeIds:
12+
; CHECK-NEXT: [ 3498816979441845844 ] }
13+
%call = tail call noundef i32 %func(i8 noundef signext %x), !callee_type !1
14+
ret i32 %call
15+
}
16+
17+
!0 = !{i64 0, !"_ZTSFiPvcE.generalized"}
18+
!1 = !{!2}
19+
!2 = !{i64 0, !"_ZTSFicE.generalized"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
;; Tests that call site callee type ids can be extracted and set from
2+
;; callee_type metadata for indirect tail calls.
3+
4+
;; Verify the exact calleeTypeId value to ensure it is not garbage but the value
5+
;; computed as the type id from the callee_type metadata.
6+
; RUN: llc --call-graph-section -mtriple arm-linux-gnu < %s -stop-after=finalize-isel -o - | FileCheck %s
7+
8+
define dso_local noundef i32 @_Z13call_indirectPFicEc(ptr noundef readonly captures(none) %func, i8 noundef signext %x) local_unnamed_addr !type !0 {
9+
entry:
10+
; CHECK: callSites:
11+
; CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [], calleeTypeIds:
12+
; CHECK-NEXT: [ 3498816979441845844 ] }
13+
%call = tail call noundef i32 %func(i8 noundef signext %x), !callee_type !1
14+
ret i32 %call
15+
}
16+
17+
!0 = !{i64 0, !"_ZTSFiPvcE.generalized"}
18+
!1 = !{!2}
19+
!2 = !{i64 0, !"_ZTSFicE.generalized"}

llvm/test/CodeGen/MIR/X86/call-site-info-direct-calls-typeid.mir

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
# CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: []
1414

1515
--- |
16-
declare noundef i32 @_Z4fizzii(i32 noundef %x, i32 noundef %y)
17-
18-
declare noundef i32 @_Z4buzzii(i32 noundef %x, i32 noundef %y)
19-
20-
define dso_local noundef i32 @_Z3barii(i32 noundef %x, i32 noundef %y) {
16+
declare !type !0 noundef i32 @_Z4fizzii(i32 noundef %x, i32 noundef %y)
17+
18+
declare !type !0 noundef i32 @_Z4buzzii(i32 noundef %x, i32 noundef %y)
19+
20+
define dso_local noundef i32 @_Z3barii(i32 noundef %x, i32 noundef %y) !type !0 {
2121
entry:
2222
%x.addr = alloca i32, align 4
2323
%y.addr = alloca i32, align 4
@@ -33,7 +33,7 @@
3333
ret i32 %sub
3434
}
3535

36-
define dso_local noundef i32 @_Z3fooii(i32 noundef %x, i32 noundef %y) {
36+
define dso_local noundef i32 @_Z3fooii(i32 noundef %x, i32 noundef %y) !type !0 {
3737
entry:
3838
%x.addr = alloca i32, align 4
3939
%y.addr = alloca i32, align 4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
;; Tests that call site callee type ids can be extracted and set from
2+
;; callee_type metadata for indirect tail calls.
3+
4+
;; Verify the exact calleeTypeId value to ensure it is not garbage but the value
5+
;; computed as the type id from the callee_type metadata.
6+
; RUN: llc --call-graph-section -mtriple=mips-linux-gnu < %s -stop-after=finalize-isel -o - | FileCheck %s
7+
8+
define dso_local noundef i32 @_Z13call_indirectPFicEc(ptr noundef readonly captures(none) %func, i8 noundef signext %x) local_unnamed_addr !type !0 {
9+
entry:
10+
; CHECK: callSites:
11+
; CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [], calleeTypeIds:
12+
; CHECK-NEXT: [ 3498816979441845844 ] }
13+
%call = tail call noundef i32 %func(i8 noundef signext %x), !callee_type !1
14+
ret i32 %call
15+
}
16+
17+
!0 = !{i64 0, !"_ZTSFiPvcE.generalized"}
18+
!1 = !{!2}
19+
!2 = !{i64 0, !"_ZTSFicE.generalized"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
;; Tests that call site callee type ids can be extracted and set from
2+
;; callee_type metadata for indirect tail calls.
3+
4+
;; Verify the exact calleeTypeIds value to ensure it is not garbage but the value
5+
;; computed as the type id from the callee_type operand bundle.
6+
; RUN: llc --call-graph-section -mtriple riscv64 < %s -stop-after=finalize-isel -o - | FileCheck %s
7+
; RUN: llc --call-graph-section -mtriple riscv32 < %s -stop-after=finalize-isel -o - | FileCheck %s
8+
9+
define dso_local noundef i32 @_Z13call_indirectPFicEc(ptr noundef readonly captures(none) %func, i8 noundef signext %x) local_unnamed_addr !type !0 {
10+
entry:
11+
; CHECK: callSites:
12+
; CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [], calleeTypeIds:
13+
; CHECK-NEXT: [ 3498816979441845844 ] }
14+
%call = tail call noundef i32 %func(i8 noundef signext %x), !callee_type !1
15+
ret i32 %call
16+
}
17+
18+
!0 = !{i64 0, !"_ZTSFiPvcE.generalized"}
19+
!1 = !{!2}
20+
!2 = !{i64 0, !"_ZTSFicE.generalized"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
;; Tests that call site callee type ids can be extracted and set from
2+
;; callee_type metadata for indirect tail calls.
3+
4+
;; Verify the exact calleeTypeIds value to ensure it is not garbage but the value
5+
;; computed as the type id from the callee_type metadata.
6+
; RUN: llc --call-graph-section -mtriple=x86_64-unknown-linux < %s -stop-after=finalize-isel -o - | FileCheck %s
7+
8+
define dso_local noundef i32 @_Z13call_indirectPFicEc(ptr noundef readonly captures(none) %func, i8 noundef signext %x) local_unnamed_addr !type !0 {
9+
entry:
10+
; CHECK: callSites:
11+
; CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [], calleeTypeIds:
12+
; CHECK-NEXT: [ 3498816979441845844 ] }
13+
%call = tail call noundef i32 %func(i8 noundef signext %x), !callee_type !1
14+
ret i32 %call
15+
}
16+
17+
!0 = !{i64 0, !"_ZTSFiPvcE.generalized"}
18+
!1 = !{!2}
19+
!2 = !{i64 0, !"_ZTSFicE.generalized"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
;; Test if the callee_type metadata is dropped when an indirect function call through a function ptr is promoted
2+
;; to a direct function call during instcombine.
3+
4+
; RUN: opt < %s -O2 | llvm-dis | FileCheck %s
5+
6+
define dso_local noundef i32 @_Z13call_indirectPFicEc(ptr noundef %func, i8 noundef signext %x) local_unnamed_addr !type !0 {
7+
entry:
8+
%call = call noundef i32 %func(i8 noundef signext %x), !callee_type !1
9+
ret i32 %call
10+
}
11+
12+
define dso_local noundef i32 @_Z3barv() local_unnamed_addr !type !3 {
13+
entry:
14+
; CHECK: %call.i = tail call noundef i32 @_Z3fooc(i8 noundef signext 97)
15+
; CHECK-NOT: %call.i = tail call noundef i32 @_Z3fooc(i8 noundef signext 97), !callee_type !1
16+
%call = call noundef i32 @_Z13call_indirectPFicEc(ptr noundef nonnull @_Z3fooc, i8 noundef signext 97)
17+
ret i32 %call
18+
}
19+
20+
declare !type !2 noundef i32 @_Z3fooc(i8 noundef signext)
21+
22+
!0 = !{i64 0, !"_ZTSFiPvcE.generalized"}
23+
!1 = !{!2}
24+
!2 = !{i64 0, !"_ZTSFicE.generalized"}
25+
!3 = !{i64 0, !"_ZTSFivE.generalized"}

0 commit comments

Comments
 (0)