-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[DebugInfo][NewGVN] Salvage debug values of trivially dead instructions #149304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Apochens
merged 2 commits into
llvm:main
from
Apochens:147634_newgvn_dbgvalue_loss_on_trivially_dead_inst
Jul 21, 2025
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
llvm/test/Transforms/NewGVN/salvage-trivially-dead-inst.ll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| ; RUN: opt -passes=newgvn -S %s | FileCheck %s | ||
|
|
||
| ; Check that assignDFSNumbers() in NewGVN salvages the debug values of the | ||
| ; trivially dead instructions that are marked for deletion. | ||
|
|
||
| ; CHECK: #dbg_value(i8 %tmp, [[META11:![0-9]+]], !DIExpression(DW_OP_constu, 8, DW_OP_eq, DW_OP_stack_value), [[META26:![0-9]+]]) | ||
| ; CHECK: [[META11]] = !DILocalVariable(name: "2" | ||
| ; CHECK: [[META26]] = !DILocation(line: 3 | ||
|
|
||
| define void @test13() !dbg !5 { | ||
| bb: | ||
| br label %bb1 | ||
|
|
||
| bb1: | ||
| %tmp = load i8, ptr null, align 1 | ||
| %tmp2 = icmp eq i8 %tmp, 8, !dbg !26 | ||
| #dbg_value(i1 %tmp2, !11, !DIExpression(), !26) | ||
| br label %bb3 | ||
|
|
||
| bb3: | ||
| %tmp4 = phi ptr [ null, %bb1 ], [ %tmp6, %bb3 ] | ||
| %tmp5 = phi i32 [ undef, %bb1 ], [ %tmp9, %bb3 ] | ||
| %tmp6 = getelementptr i8, ptr %tmp4, i64 1 | ||
| %tmp7 = load i8, ptr %tmp4, align 1 | ||
| %tmp8 = sext i8 %tmp7 to i32 | ||
| %tmp9 = mul i32 %tmp5, %tmp8 | ||
| %tmp10 = load i8, ptr %tmp6, align 1 | ||
| %tmp11 = icmp eq i8 %tmp10, 0 | ||
| br i1 %tmp11, label %bb12, label %bb3 | ||
|
|
||
| bb12: | ||
| %tmp13 = phi i32 [ %tmp9, %bb3 ] | ||
| %tmp14 = icmp eq i32 %tmp13, 0 | ||
| br i1 %tmp14, label %bb1, label %bb15 | ||
|
|
||
| bb15: | ||
| call void (...) @bar() | ||
| br label %bb1 | ||
| } | ||
|
|
||
| declare void @bar(...) | ||
|
|
||
| !llvm.dbg.cu = !{!0} | ||
| !llvm.debugify = !{!2, !3} | ||
| !llvm.module.flags = !{!4} | ||
|
|
||
| !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug) | ||
| !1 = !DIFile(filename: "/app/example.ll", directory: "/") | ||
| !2 = !{i32 18} | ||
| !3 = !{i32 12} | ||
| !4 = !{i32 2, !"Debug Info Version", i32 3} | ||
| !5 = distinct !DISubprogram(name: "test13", linkageName: "test13", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !8) | ||
| !6 = !DISubroutineType(types: !7) | ||
| !7 = !{} | ||
| !8 = !{!11} | ||
| !10 = !DIBasicType(name: "ty8", size: 8, encoding: DW_ATE_unsigned) | ||
| !11 = !DILocalVariable(name: "2", scope: !5, file: !1, line: 3, type: !10) | ||
| !26 = !DILocation(line: 3, column: 1, scope: !5) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need all the instructions below, or is the following sufficient to exercise the behaviour?
If you do need the extra instructions, I think you'll want to replace the
undefwithpoison.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I think this concise test case is enough.