Skip to content

Commit d8863df

Browse files
committed
resolve review comments
1 parent 3d6997c commit d8863df

File tree

4 files changed

+79
-92
lines changed

4 files changed

+79
-92
lines changed

clang/docs/UsersManual.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2360,15 +2360,15 @@ are listed below.
23602360
the assumption before making the direct call, and if the check fails,
23612361
the original virtual call is made instead. This optimization can enable
23622362
more inlining opportunities and better optimization of the direct call.
2363-
This is different from other whole program devirtualization optimizations
2363+
This is different from whole program devirtualization optimization
23642364
that rely on global analysis and hidden visibility of the objects to prove
23652365
that the object is always of a particular type at a virtual call site.
23662366
This optimization doesn't require global analysis or hidden visibility.
23672367
This optimization doesn't devirtualize all virtual calls, but only
2368-
when there's a single implementation of the virtual function.
2369-
There could be a single implementaiton of the virtual function
2368+
when there's a single implementation of the virtual function in the module.
2369+
There could be a single implementation of the virtual function
23702370
either because the function is not overridden in any derived class,
2371-
or because there is a sinlge instantiated object that is using the funciton.
2371+
or because there is a single instantiated object that is using the function.
23722372

23732373
Ex of IR before the optimization:
23742374
.. code-block:: llvm
@@ -2395,7 +2395,7 @@ are listed below.
23952395
if.end.icp: ; preds = %if.false.orig_indirect, %if.true.direct_targ
23962396
ret void
23972397
This feature is temporarily ignored at the LLVM side when LTO is enabled.
2398-
TODO: Update the comment when the LLVM side supports it.
2398+
TODO: Update the comment when the LLVM side supports this feature for LTO.
23992399
This feature is turned off by default.
24002400

24012401
.. option:: -f[no-]unique-source-file-names

clang/test/CodeGenCXX/speculative-devirt-metadata.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Test that Clang emits vtable metadata when speculative devirtualization is enabled.
2-
// RUN: %clang_cc1 -triple x86_64-unknown-linux -fdevirtualize-speculatively -emit-llvm -o - %s | FileCheck --check-prefix=VTABLE-OPT --check-prefix=TT-ITANIUM-DEFAULT-NOLTO-SPECULATIVE-DEVIRT %s
2+
// RUN: %clang_cc1 -triple x86_64-unknown-linux -fdevirtualize-speculatively -emit-llvm -o - %s | FileCheck --check-prefix=CHECK %s
33

44
struct A {
55
A();
@@ -39,25 +39,26 @@ void D::h() {
3939
}
4040

4141
void af(A *a) {
42-
// TT-ITANIUM-DEFAULT-NOLTO-SPECULATIVE-DEVIRT: [[P:%[^ ]*]] = call i1 @llvm.public.type.test(ptr [[VT:%[^ ]*]], metadata !"_ZTS1A")
43-
// VTABLE-OPT: call void @llvm.assume(i1 [[P]])
42+
// CHECK: [[P:%[^ ]*]] = call i1 @llvm.public.type.test(ptr [[VT:%[^ ]*]], metadata !"_ZTS1A")
43+
// CHECK-NEXT: call void @llvm.assume(i1 [[P]])
4444
a->f();
4545
}
4646

4747
void dg1(D *d) {
48-
// TT-ITANIUM-DEFAULT-NOLTO-SPECULATIVE-DEVIRT: [[P:%[^ ]*]] = call i1 @llvm.public.type.test(ptr [[VT:%[^ ]*]], metadata !"_ZTS1B")
49-
// VTABLE-OPT: call void @llvm.assume(i1 [[P]])
48+
// CHECK: [[P:%[^ ]*]] = call i1 @llvm.public.type.test(ptr [[VT:%[^ ]*]], metadata !"_ZTS1B")
49+
// CHECK-NEXT: call void @llvm.assume(i1 [[P]])
5050
d->g();
5151
}
52+
5253
void df1(D *d) {
53-
// TT-ITANIUM-DEFAULT-NOLTO-SPECULATIVE-DEVIRT: [[P:%[^ ]*]] = call i1 @llvm.type.test(ptr [[VT:%[^ ]*]], metadata !11)
54-
// VTABLE-OPT: call void @llvm.assume(i1 [[P]])
54+
// CHECK: [[P:%[^ ]*]] = call i1 @llvm.type.test(ptr [[VT:%[^ ]*]], metadata !11)
55+
// CHECK-NEXT: call void @llvm.assume(i1 [[P]])
5556
d->f();
5657
}
5758

5859
void dh1(D *d) {
59-
// TT-ITANIUM-DEFAULT-NOLTO-SPECULATIVE-DEVIRT: [[P:%[^ ]*]] = call i1 @llvm.type.test(ptr [[VT:%[^ ]*]], metadata !11)
60-
// VTABLE-OPT: call void @llvm.assume(i1 [[P]])
60+
// CHECK: [[P:%[^ ]*]] = call i1 @llvm.type.test(ptr [[VT:%[^ ]*]], metadata !11)
61+
// CHECK-NEXT: call void @llvm.assume(i1 [[P]])
6162
d->h();
6263
}
6364

clang/test/CodeGenCXX/speculative-devirt.cpp

Lines changed: 0 additions & 78 deletions
This file was deleted.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
; Test that the needed intrinsics for devirtualization are preserved and not dropped by other
2+
; optimizations.
3+
4+
; RUN: opt -S -O3 %s 2>&1 | FileCheck %s
5+
6+
target datalayout = "e-p:64:64"
7+
target triple = "x86_64-unknown-linux-gnu"
8+
9+
@vt1 = constant [1 x ptr] [ptr @vf], !type !8
10+
@vt2 = constant [1 x ptr] [ptr @vf2], !type !12
11+
12+
define i1 @vf(ptr %this) #0 !dbg !7 {
13+
ret i1 true
14+
}
15+
16+
define i1 @vf2(ptr %this) !dbg !11 {
17+
ret i1 false
18+
}
19+
20+
define void @call(ptr %obj) #1 !dbg !5 {
21+
%vtable = load ptr, ptr %obj
22+
; CHECK: [[P:%[^ ]*]] = tail call i1 @llvm.public.type.test(ptr [[VT:%[^ ]*]], metadata !"typeid")
23+
; CHECK-NEXT: call void @llvm.assume(i1 [[P]])
24+
%p = call i1 @llvm.public.type.test(ptr %vtable, metadata !"typeid")
25+
call void @llvm.assume(i1 %p)
26+
%fptr = load ptr, ptr %vtable
27+
call i1 %fptr(ptr %obj), !dbg !6
28+
ret void
29+
}
30+
31+
define void @call1(ptr %obj) #1 !dbg !9 {
32+
%vtable = load ptr, ptr %obj
33+
; CHECK: [[P:%[^ ]*]] = tail call i1 @llvm.type.test(ptr [[VT:%[^ ]*]], metadata !"typeid1")
34+
; CHECK-NEXT: call void @llvm.assume(i1 [[P]])
35+
%p = call i1 @llvm.type.test(ptr %vtable, metadata !"typeid1")
36+
call void @llvm.assume(i1 %p)
37+
%fptr = load ptr, ptr %vtable, align 8
38+
%1 = call i1 %fptr(ptr %obj), !dbg !10
39+
ret void
40+
}
41+
42+
declare i1 @llvm.type.test(ptr, metadata)
43+
declare i1 @llvm.public.type.test(ptr, metadata)
44+
declare void @llvm.assume(i1)
45+
46+
!llvm.dbg.cu = !{!0}
47+
!llvm.module.flags = !{!2, !3}
48+
!llvm.ident = !{!4}
49+
50+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 4.0.0 (trunk 278098)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
51+
!1 = !DIFile(filename: "devirt-single.cc", directory: ".")
52+
!2 = !{i32 2, !"Dwarf Version", i32 4}
53+
!3 = !{i32 2, !"Debug Info Version", i32 3}
54+
!4 = !{!"clang version 4.0.0 (trunk 278098)"}
55+
!5 = distinct !DISubprogram(name: "call", linkageName: "_Z4callPv", scope: !1, file: !1, line: 29, isLocal: false, isDefinition: true, scopeLine: 9, flags: DIFlagPrototyped, isOptimized: false, unit: !0)
56+
!6 = !DILocation(line: 30, column: 32, scope: !5)
57+
!7 = distinct !DISubprogram(name: "vf", linkageName: "_ZN3vt12vfEb", scope: !1, file: !1, line: 13, isLocal: false, isDefinition: true, scopeLine: 13, flags: DIFlagPrototyped, isOptimized: false, unit: !0)
58+
!8 = !{i32 0, !"typeid"}
59+
60+
!9 = distinct !DISubprogram(name: "call1", linkageName: "_Z5call1Pv", scope: !1, file: !1, line: 31, isLocal: false, isDefinition: true, scopeLine: 9, flags: DIFlagPrototyped, isOptimized: false, unit: !0)
61+
!10 = !DILocation(line: 35, column: 32, scope: !9)
62+
!11 = distinct !DISubprogram(name: "vf2", linkageName: "_ZN3vt13vf2Eb", scope: !1, file: !1, line: 23, isLocal: false, isDefinition: true, scopeLine: 23, flags: DIFlagPrototyped, isOptimized: false, unit: !0)
63+
!12 = !{i32 0, !"typeid1"}
64+

0 commit comments

Comments
 (0)