Skip to content

Commit 6f4e4f7

Browse files
authored
[Debug Info] Prioritize optimization over debug info in metadata comparisons (#7732)
Ignore debug info there, allowing e.g. DuplicateFunctionElimination to merge functions identical in all ways but for debug info.
1 parent c303248 commit 6f4e4f7

File tree

2 files changed

+48
-7
lines changed

2 files changed

+48
-7
lines changed

src/ir/metadata.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,14 @@ bool equal(Function* a, Function* b) {
105105
return false;
106106
}
107107

108-
if (a->debugLocations.empty() && b->debugLocations.empty() &&
109-
a->codeAnnotations.empty() && b->codeAnnotations.empty()) {
108+
// TODO: We do not consider debug locations here. This is often what is
109+
// desired in optimized builds (e.g. if we are trying to fold two
110+
// pieces of code together, that benefit outweighs slightly inaccurate
111+
// debug info). If we find that non-optimizer locations call this in
112+
// ways that lead to degraded debug info, we could add an option to
113+
// control it.
114+
115+
if (a->codeAnnotations.empty() && b->codeAnnotations.empty()) {
110116
// Nothing to compare; no differences.
111117
return true;
112118
}
@@ -121,11 +127,6 @@ bool equal(Function* a, Function* b) {
121127
assert(aList.list.size() == bList.list.size());
122128
for (Index i = 0; i < aList.list.size(); i++) {
123129
if (!compare(aList.list[i],
124-
bList.list[i],
125-
a->debugLocations,
126-
b->debugLocations,
127-
Function::DebugLocation()) ||
128-
!compare(aList.list[i],
129130
bList.list[i],
130131
a->codeAnnotations,
131132
b->codeAnnotations,

test/lit/passes/duplicate-function-elimination_branch-hints.wast

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,43 @@
218218
)
219219
)
220220

221+
;; Source file location (debug info) does *not* prevent optimization. We
222+
;; prioritize optimization over debug info quality.
223+
(module
224+
;; CHECK: (type $0 (func (param i32)))
225+
226+
;; CHECK: (export "a" (func $a))
227+
228+
;; CHECK: (export "b" (func $a))
229+
230+
;; CHECK: (func $a (type $0) (param $x i32)
231+
;; CHECK-NEXT: ;;@ src.cpp:10:1
232+
;; CHECK-NEXT: (if
233+
;; CHECK-NEXT: (local.get $x)
234+
;; CHECK-NEXT: (then
235+
;; CHECK-NEXT: (unreachable)
236+
;; CHECK-NEXT: )
237+
;; CHECK-NEXT: )
238+
;; CHECK-NEXT: )
239+
(func $a (export "a") (param $x i32)
240+
;; After we merge, this hint will remain in the single function.
241+
;;@ src.cpp:10:1
242+
(if
243+
(local.get $x)
244+
(then
245+
(unreachable)
246+
)
247+
)
248+
)
249+
250+
(func $b (export "b") (param $x i32)
251+
;;@ src.cpp:20:1
252+
(if
253+
(local.get $x)
254+
(then
255+
(unreachable)
256+
)
257+
)
258+
)
259+
)
260+

0 commit comments

Comments
 (0)