[llvm] [DebugInfo][GVNSink] Merging debug locations of sinked instructions (PR #92859)
via llvm-commits
llvm-commits at lists.llvm.org
Mon May 20 22:21:26 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Shan Huang (Apochens)
<details>
<summary>Changes</summary>
Fix #<!-- -->85069 .
---
Full diff: https://github.com/llvm/llvm-project/pull/92859.diff
2 Files Affected:
- (modified) llvm/lib/Transforms/Scalar/GVNSink.cpp (+3-1)
- (modified) llvm/test/Transforms/GVNSink/sink-ignore-dbg-intrinsics.ll (+5-2)
``````````diff
diff --git a/llvm/lib/Transforms/Scalar/GVNSink.cpp b/llvm/lib/Transforms/Scalar/GVNSink.cpp
index b0f716cb17598..3dfa2dd9df27f 100644
--- a/llvm/lib/Transforms/Scalar/GVNSink.cpp
+++ b/llvm/lib/Transforms/Scalar/GVNSink.cpp
@@ -921,8 +921,10 @@ void GVNSink::sinkLastInstruction(ArrayRef<BasicBlock *> Blocks,
}
for (auto *I : Insts)
- if (I != I0)
+ if (I != I0) {
I->replaceAllUsesWith(I0);
+ I0->applyMergedLocation(I0->getDebugLoc(), I->getDebugLoc());
+ }
foldPointlessPHINodes(BBEnd);
// Finally nuke all instructions apart from the common instruction.
diff --git a/llvm/test/Transforms/GVNSink/sink-ignore-dbg-intrinsics.ll b/llvm/test/Transforms/GVNSink/sink-ignore-dbg-intrinsics.ll
index 8aafd689e781d..e54a17a155b8c 100644
--- a/llvm/test/Transforms/GVNSink/sink-ignore-dbg-intrinsics.ll
+++ b/llvm/test/Transforms/GVNSink/sink-ignore-dbg-intrinsics.ll
@@ -1,6 +1,8 @@
; RUN: opt < %s -passes=gvn-sink -S | FileCheck %s
; Test that GVNSink correctly performs the sink optimization in the presence of debug information
+; Test that GVNSink correctly merges the debug locations of sinked instruction, eg, propagating
+; the merged debug location of `%add` and `%add1` to the sinked add instruction.
; Function Attrs: noinline nounwind uwtable
define dso_local i32 @fun(i32 noundef %a, i32 noundef %b) #0 !dbg !10 {
@@ -8,8 +10,9 @@ define dso_local i32 @fun(i32 noundef %a, i32 noundef %b) #0 !dbg !10 {
; CHECK-SAME: i32 noundef [[A:%.*]], i32 noundef [[B:%.*]])
; CHECK: if.end:
; CHECK: [[B_SINK:%.*]] = phi i32 [ [[B]], %if.else ], [ [[A]], %if.then ]
-; CHECK: [[ADD1:%.*]] = add nsw i32 [[B_SINK]], 1
-; CHECK: [[XOR2:%.*]] = xor i32 [[ADD1]], 1
+; CHECK: [[ADD1:%.*]] = add nsw i32 [[B_SINK]], 1, !dbg [[DBG:![0-9]+]]
+; CHECK: [[XOR2:%.*]] = xor i32 [[ADD1]], 1, !dbg [[DBG:![0-9]+]]
+; CHECK: [[DBG]] = !DILocation(line: 0,
;
entry:
tail call void @llvm.dbg.value(metadata i32 %a, metadata !15, metadata !DIExpression()), !dbg !16
``````````
</details>
https://github.com/llvm/llvm-project/pull/92859
More information about the llvm-commits
mailing list