Skip to content

Commit 61ab43a

Browse files
authored
[IROutliner] Skip dbg values during the candidate search. (#72945)
dbg value don't really have a value number associated as they have no semantic value associated, i.e. they don't change the code being generated. Use the correct API to go over them. Fixes #62876
1 parent 9be9f62 commit 61ab43a

File tree

2 files changed

+178
-1
lines changed

2 files changed

+178
-1
lines changed

llvm/lib/Transforms/IPO/IROutliner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ Value *OutlinableRegion::findCorrespondingValueIn(const OutlinableRegion &Other,
198198
BasicBlock *
199199
OutlinableRegion::findCorrespondingBlockIn(const OutlinableRegion &Other,
200200
BasicBlock *BB) {
201-
Instruction *FirstNonPHI = BB->getFirstNonPHI();
201+
Instruction *FirstNonPHI = BB->getFirstNonPHIOrDbg();
202202
assert(FirstNonPHI && "block is empty?");
203203
Value *CorrespondingVal = findCorrespondingValueIn(Other, FirstNonPHI);
204204
if (!CorrespondingVal)
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2+
; RUN: opt -S -passes=verify,iroutliner -ir-outlining-no-cost < %s | FileCheck %s
3+
4+
target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
5+
target triple = "thumbv7-none-linux-android19"
6+
7+
define i32 @r() {
8+
; CHECK-LABEL: define i32 @r() {
9+
; CHECK-NEXT: entry:
10+
; CHECK-NEXT: [[DOTLOC:%.*]] = alloca ptr, align 4
11+
; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 -1, ptr [[DOTLOC]])
12+
; CHECK-NEXT: [[TMP0:%.*]] = call i1 @outlined_ir_func_0(ptr [[DOTLOC]], i32 0)
13+
; CHECK-NEXT: [[DOTRELOAD:%.*]] = load ptr, ptr [[DOTLOC]], align 4
14+
; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 -1, ptr [[DOTLOC]])
15+
; CHECK-NEXT: br i1 [[TMP0]], label [[IF_END8:%.*]], label [[ENTRY_AFTER_OUTLINE:%.*]]
16+
; CHECK: entry_after_outline:
17+
; CHECK-NEXT: [[CALL7:%.*]] = call i32 [[DOTRELOAD]]()
18+
; CHECK-NEXT: br label [[IF_END8]]
19+
; CHECK: if.end8:
20+
; CHECK-NEXT: ret i32 0
21+
;
22+
entry:
23+
%.fca.2.insert = insertvalue [5 x i32] zeroinitializer, i32 0, 2
24+
%.fca.3.load = load i32, ptr null, align 4
25+
%.fca.3.insert = insertvalue [5 x i32] zeroinitializer, i32 0, 3
26+
%.fca.4.load = load i32, ptr null, align 4
27+
%.fca.4.insert = insertvalue [5 x i32] zeroinitializer, i32 0, 4
28+
%call = call i32 @p()
29+
%tobool.not = icmp eq i32 0, 0
30+
br i1 false, label %if.end8, label %if.then
31+
32+
if.then: ; preds = %entry
33+
%0 = load i32, ptr null, align 4
34+
%tobool1.not = icmp eq i32 0, 0
35+
%1 = load i32, ptr null, align 4
36+
%2 = load i32, ptr null, align 4
37+
%cond = select i1 false, i32 0, i32 0
38+
%tobool5.not = icmp eq i32 0, 0
39+
br i1 false, label %if.end8, label %if.then6
40+
41+
if.then6: ; preds = %if.then
42+
%3 = load ptr, ptr null, align 4
43+
%call7 = call i32 %3()
44+
br label %if.end8
45+
46+
if.end8: ; preds = %if.then6, %if.then, %entry
47+
ret i32 0
48+
}
49+
50+
declare i32 @p()
51+
52+
define i32 @u() {
53+
; CHECK-LABEL: define i32 @u() {
54+
; CHECK-NEXT: entry:
55+
; CHECK-NEXT: [[TMP0:%.*]] = call i1 @outlined_ir_func_0(ptr null, i32 -1)
56+
; CHECK-NEXT: br i1 [[TMP0]], label [[IF_END8:%.*]], label [[ENTRY_AFTER_OUTLINE:%.*]]
57+
; CHECK: entry_after_outline:
58+
; CHECK-NEXT: br label [[IF_END8]]
59+
; CHECK: if.end8:
60+
; CHECK-NEXT: ret i32 0
61+
;
62+
entry:
63+
%.fca.2.insert = insertvalue [5 x i32] zeroinitializer, i32 0, 2
64+
%.fca.3.load = load i32, ptr null, align 4
65+
%.fca.3.insert = insertvalue [5 x i32] zeroinitializer, i32 0, 3
66+
%.fca.4.load = load i32, ptr null, align 4
67+
%.fca.4.insert = insertvalue [5 x i32] zeroinitializer, i32 0, 4
68+
%call = call i32 @p()
69+
%tobool.not = icmp eq i32 0, 0
70+
br i1 false, label %if.end8, label %if.then
71+
72+
if.then: ; preds = %entry
73+
%0 = load i32, ptr null, align 4
74+
%tobool1.not = icmp eq i32 0, 0
75+
%1 = load i32, ptr null, align 4
76+
%2 = load i32, ptr null, align 4
77+
%cond = select i1 false, i32 0, i32 0
78+
%tobool5.not = icmp eq i32 0, 0
79+
br i1 false, label %if.end8, label %if.then6
80+
81+
if.then6: ; preds = %if.then
82+
%3 = load ptr, ptr null, align 4
83+
br label %if.end8
84+
85+
if.end8: ; preds = %if.then6, %if.then, %entry
86+
ret i32 0
87+
}
88+
89+
define i32 @w() !dbg !8 {
90+
; CHECK-LABEL: define i32 @w(
91+
; CHECK-SAME: ) !dbg [[DBG8:![0-9]+]] {
92+
; CHECK-NEXT: entry:
93+
; CHECK-NEXT: [[RETVAL_1_CE_LOC:%.*]] = alloca i32, align 4
94+
; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 -1, ptr [[RETVAL_1_CE_LOC]])
95+
; CHECK-NEXT: [[TMP0:%.*]] = call i1 @outlined_ir_func_0(ptr [[RETVAL_1_CE_LOC]], i32 1), !dbg [[DBG11:![0-9]+]]
96+
; CHECK-NEXT: [[RETVAL_1_CE_RELOAD:%.*]] = load i32, ptr [[RETVAL_1_CE_LOC]], align 4
97+
; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 -1, ptr [[RETVAL_1_CE_LOC]])
98+
; CHECK-NEXT: br i1 [[TMP0]], label [[CLEANUP10:%.*]], label [[ENTRY_AFTER_OUTLINE:%.*]]
99+
; CHECK: entry_after_outline:
100+
; CHECK-NEXT: [[CALL8:%.*]] = call i32 @llvm.bswap.i32(i32 0)
101+
; CHECK-NEXT: br label [[CLEANUP10]]
102+
; CHECK: cleanup10:
103+
; CHECK-NEXT: [[RETVAL_1:%.*]] = phi i32 [ 0, [[ENTRY_AFTER_OUTLINE]] ], [ [[RETVAL_1_CE_RELOAD]], [[ENTRY:%.*]] ]
104+
; CHECK-NEXT: ret i32 0
105+
;
106+
entry:
107+
%.fca.2.insert = insertvalue [5 x i32] zeroinitializer, i32 0, 2
108+
%.fca.3.load = load i32, ptr null, align 4
109+
%.fca.3.insert = insertvalue [5 x i32] zeroinitializer, i32 0, 3
110+
%.fca.4.load = load i32, ptr null, align 4
111+
%.fca.4.insert = insertvalue [5 x i32] zeroinitializer, i32 0, 4
112+
%call = call i32 @p()
113+
%tobool.not = icmp eq i32 0, 0
114+
br i1 false, label %cleanup10, label %if.then
115+
116+
if.then: ; preds = %entry
117+
call void @llvm.dbg.value(metadata i32 0, metadata !11, metadata !DIExpression()), !dbg !15
118+
%0 = load i32, ptr null, align 4
119+
%tobool1.not = icmp eq i32 0, 0
120+
%1 = load i32, ptr null, align 4
121+
%2 = load i32, ptr null, align 4
122+
%cond = select i1 false, i32 0, i32 0
123+
%tobool5.not = icmp eq i32 0, 0
124+
br i1 false, label %cleanup10, label %cleanup
125+
126+
cleanup: ; preds = %if.then
127+
%3 = load ptr, ptr null, align 4
128+
%call8 = call i32 @llvm.bswap.i32(i32 0)
129+
br label %cleanup10
130+
131+
cleanup10: ; preds = %cleanup, %if.then, %entry
132+
%retval.1 = phi i32 [ 0, %cleanup ], [ 0, %entry ], [ 0, %if.then ]
133+
ret i32 0
134+
}
135+
136+
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
137+
declare void @llvm.dbg.value(metadata, metadata, metadata) #0
138+
139+
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
140+
declare i32 @llvm.bswap.i32(i32) #0
141+
142+
attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
143+
144+
!llvm.dbg.cu = !{!0}
145+
!llvm.module.flags = !{!7}
146+
147+
!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 18.0.0 (https://github.com/llvm/llvm-project.git 2ca028ce7c6de5f1350440012355a65383b8729a)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !2, splitDebugInlining: false, nameTableKind: None)
148+
!1 = !DIFile(filename: "/tmp/foo.c", directory: "/home/davidino/llvm-build-upstream")
149+
!2 = !{!3}
150+
!3 = !DIGlobalVariableExpression(var: !4, expr: !DIExpression())
151+
!4 = distinct !DIGlobalVariable(name: "n", scope: !0, file: !5, line: 19, type: !6, isLocal: false, isDefinition: true)
152+
!5 = !DIFile(filename: "/tmp/foo.c", directory: "")
153+
!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
154+
!7 = !{i32 2, !"Debug Info Version", i32 3}
155+
!8 = distinct !DISubprogram(name: "w", scope: !5, file: !5, line: 54, type: !9, scopeLine: 54, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !10)
156+
!9 = !DISubroutineType(types: !10)
157+
!10 = !{}
158+
!11 = !DILocalVariable(name: "t", scope: !12, file: !5, line: 57, type: !14)
159+
!12 = distinct !DILexicalBlock(scope: !13, file: !5, line: 56, column: 17)
160+
!13 = distinct !DILexicalBlock(scope: !8, file: !5, line: 56, column: 11)
161+
!14 = !DIDerivedType(tag: DW_TAG_typedef, name: "a", file: !5, line: 2, baseType: !6)
162+
!15 = !DILocation(line: 0, scope: !12)
163+
;.
164+
; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C11, file: [[META1:![0-9]+]], producer: "{{.*}}clang version {{.*}}", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: [[META2:![0-9]+]], splitDebugInlining: false, nameTableKind: None)
165+
; CHECK: [[META1]] = !DIFile(filename: "/tmp/foo.c", directory: {{.*}})
166+
; CHECK: [[META2]] = !{[[META3:![0-9]+]]}
167+
; CHECK: [[META3]] = !DIGlobalVariableExpression(var: [[META4:![0-9]+]], expr: !DIExpression())
168+
; CHECK: [[META4]] = distinct !DIGlobalVariable(name: "n", scope: [[META0]], file: [[META5:![0-9]+]], line: 19, type: [[META6:![0-9]+]], isLocal: false, isDefinition: true)
169+
; CHECK: [[META5]] = !DIFile(filename: "/tmp/foo.c", directory: "")
170+
; CHECK: [[META6]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
171+
; CHECK: [[DBG8]] = distinct !DISubprogram(name: "w", scope: [[META5]], file: [[META5]], line: 54, type: [[META9:![0-9]+]], scopeLine: 54, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META10:![0-9]+]])
172+
; CHECK: [[META9]] = !DISubroutineType(types: [[META10]])
173+
; CHECK: [[META10]] = !{}
174+
; CHECK: [[DBG11]] = !DILocation(line: 0, scope: [[META12:![0-9]+]])
175+
; CHECK: [[META12]] = distinct !DILexicalBlock(scope: [[META13:![0-9]+]], file: [[META5]], line: 56, column: 17)
176+
; CHECK: [[META13]] = distinct !DILexicalBlock(scope: [[DBG8]], file: [[META5]], line: 56, column: 11)
177+
;.

0 commit comments

Comments
 (0)