Skip to content

Commit 93841e1

Browse files
committed
[MergeFuncs] Use sizeWithoutDebug for canCreateThunkFor
I noticed that when we determine the size of the function to figure out if its profitable, we include debug instructions which can end up making larger functions than necessary.
1 parent c81dfa8 commit 93841e1

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

llvm/lib/Transforms/IPO/MergeFunctions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ static bool canCreateThunkFor(Function *F) {
653653
// Don't merge tiny functions using a thunk, since it can just end up
654654
// making the function larger.
655655
if (F->size() == 1) {
656-
if (F->front().size() <= 2) {
656+
if (F->front().sizeWithoutDebug() < 2) {
657657
LLVM_DEBUG(dbgs() << "canCreateThunkFor: " << F->getName()
658658
<< " is too small to bother creating a thunk for\n");
659659
return false;
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2+
;; Make sure debug instructions are not counted when deciding to merge functions
3+
; RUN: opt -S -passes=mergefunc < %s | FileCheck %s
4+
5+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
6+
7+
; Function Attrs: nounwind readnone
8+
define hidden i32 @f(i32 %t) {
9+
; CHECK-LABEL: define hidden i32 @f
10+
; CHECK-SAME: (i32 [[T:%.*]]) {
11+
; CHECK-NEXT: entry:
12+
; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 [[T]], metadata [[META6:![0-9]+]], metadata !DIExpression()), !dbg [[DBG12:![0-9]+]]
13+
; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 [[T]], metadata [[META6]], metadata !DIExpression()), !dbg [[DBG12]]
14+
; CHECK-NEXT: ret i32 0
15+
;
16+
entry:
17+
call void @llvm.dbg.value(metadata i32 %t, metadata !12, metadata !DIExpression()), !dbg !13
18+
call void @llvm.dbg.value(metadata i32 %t, metadata !12, metadata !DIExpression()), !dbg !13
19+
ret i32 0
20+
}
21+
22+
; Function Attrs: nounwind readnone
23+
define hidden i32 @f_thunk(i32 %t) {
24+
; CHECK-LABEL: define hidden i32 @f_thunk
25+
; CHECK-SAME: (i32 [[T:%.*]]) {
26+
; CHECK-NEXT: entry:
27+
; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 [[T]], metadata [[META6]], metadata !DIExpression()), !dbg [[DBG12]]
28+
; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 [[T]], metadata [[META6]], metadata !DIExpression()), !dbg [[DBG12]]
29+
; CHECK-NEXT: ret i32 0
30+
;
31+
entry:
32+
call void @llvm.dbg.value(metadata i32 %t, metadata !12, metadata !DIExpression()), !dbg !13
33+
call void @llvm.dbg.value(metadata i32 %t, metadata !12, metadata !DIExpression()), !dbg !13
34+
ret i32 0
35+
}
36+
37+
; Function Attrs: nounwind readnone speculatable
38+
declare void @llvm.dbg.value(metadata, metadata, metadata)
39+
40+
!llvm.dbg.cu = !{!0}
41+
!llvm.module.flags = !{!3, !4, !5}
42+
43+
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
44+
!1 = !DIFile(filename: "no-merge-debug-thunks.c", directory: "/tmp")
45+
!2 = !{}
46+
!3 = !{i32 2, !"Dwarf Version", i32 4}
47+
!4 = !{i32 2, !"Debug Info Version", i32 3}
48+
!5 = !{i32 1, !"wchar_size", i32 4}
49+
!7 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 3, type: !8, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !11)
50+
!8 = !DISubroutineType(types: !9)
51+
!9 = !{!10, !10}
52+
!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
53+
!11 = !{!12}
54+
!12 = !DILocalVariable(name: "t", arg: 1, scope: !7, file: !1, line: 3, type: !10)
55+
!13 = !DILocation(line: 3, column: 14, scope: !7)
56+
!14 = !DILocation(line: 4, column: 12, scope: !7)
57+
!16 = distinct !DISubprogram(name: "_start", scope: !1, file: !1, line: 7, type: !17, isLocal: false, isDefinition: true, scopeLine: 7, isOptimized: true, unit: !0, retainedNodes: !2)
58+
!17 = !DISubroutineType(types: !18)
59+
!18 = !{!10}
60+
!19 = !DILocation(line: 8, column: 3, scope: !16)
61+
!20 = !DILocation(line: 9, column: 3, scope: !16)

0 commit comments

Comments
 (0)