Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Apochens wants to merge2 commits intollvm:main
base:main
Choose a base branch
Loading
fromApochens:147634_newgvn_dbgvalue_loss_on_trivially_dead_inst

Conversation

Apochens
Copy link
Contributor

@ApochensApochens commentedJul 17, 2025
edited
Loading

@ApochensApochens added debuginfo llvm:GVNGVN and NewGVN stages (Global value numbering) labelsJul 17, 2025
@llvmbot
Copy link
Member

llvmbot commentedJul 17, 2025
edited
Loading

@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-debuginfo

Author: Shan Huang (Apochens)

Changes

fix #147634


Full diff:https://github.com/llvm/llvm-project/pull/149304.diff

2 Files Affected:

  • (modified) llvm/lib/Transforms/Scalar/NewGVN.cpp (+1)
  • (added) llvm/test/Transforms/NewGVN/salvage-trivially-dead-inst.ll (+58)
diff --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cppindex 7eeaaa0d99602..17c4fd9c2aae9 100644--- a/llvm/lib/Transforms/Scalar/NewGVN.cpp+++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp@@ -3044,6 +3044,7 @@ std::pair<unsigned, unsigned> NewGVN::assignDFSNumbers(BasicBlock *B,     if (isInstructionTriviallyDead(&I, TLI)) {       InstrDFS[&I] = 0;       LLVM_DEBUG(dbgs() << "Skipping trivially dead instruction " << I << "\n");+      salvageDebugInfo(I);       markInstructionForDeletion(&I);       continue;     }diff --git a/llvm/test/Transforms/NewGVN/salvage-trivially-dead-inst.ll b/llvm/test/Transforms/NewGVN/salvage-trivially-dead-inst.llnew file mode 100644index 0000000000000..1845cf6f0852c--- /dev/null+++ b/llvm/test/Transforms/NewGVN/salvage-trivially-dead-inst.ll@@ -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)\ No newline at end of file

@github-actionsGitHub Actions
Copy link

github-actionsbot commentedJul 17, 2025
edited
Loading

✅ With the latest revision this PR passed the undef deprecator.

Copy link
Contributor

@OCHyamsOCHyams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Are there are other calls tomarkInstructionForDeletion that should be accompanied by a salvage? What's the consequences of putting the salvage call inmarkInstructionForDeletion instead?

#dbg_value(i1 %tmp2, !11, !DIExpression(), !26)
br label %bb3

bb3:
Copy link
Contributor

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?

definevoid@test13()!dbg!5 {entry:%tmp =loadi8,ptrnull,align1%tmp2 =icmpeqi8%tmp,8,!dbg!26    #dbg_value(i1%tmp2,!11,!DIExpression(),!26)retvoid}

If you do need the extra instructions, I think you'll want to replace theundef withpoison.

Copy link
ContributorAuthor

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.

@Apochens
Copy link
ContributorAuthor

Are there are other calls to markInstructionForDeletion that should be accompanied by a salvage?

For now, I found this call tomarkInstructionForDeletion and the prior issue (#147511) should be accompanied by a salvage. The other ones mark instructions likestore orphi instructions. For these instructions, we don't need to salvage the corresponding debug values (salvageDebugInfo cannot handle them).

What's the consequences of putting the salvage call in markInstructionForDeletion instead?

As discussed in the prior issue (#147511), placing the salvage call into the following loop would introduce unnecessary computation overhead of salvaging.

for (Instruction *ToErase : InstructionsToErase) {

Similarly, putting the salvage call intomarkInstructionForDeletion would lead to extra salvage operations on instructions likestore orphi instructions marked for deletion. So, IMO, it's better to put the salvage at a place where fewer or no extra salvage operations would be introduced.

OCHyams reacted with thumbs up emoji

Copy link
Contributor

@OCHyamsOCHyams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM, thanks

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@OCHyamsOCHyamsOCHyams approved these changes

@SLTozerSLTozerAwaiting requested review from SLTozer

Assignees
No one assigned
Labels
debuginfollvm:GVNGVN and NewGVN stages (Global value numbering)llvm:transforms
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

[DebugInfo][NewGVN] Debug value loss caused by the missing salvage
3 participants
@Apochens@llvmbot@OCHyams

[8]ページ先頭

©2009-2025 Movatter.jp