[llvm] [SROA] Support dbg_declare_value (PR #225902)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 24 11:05:12 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-debuginfo
Author: Ellis Hoag (ellishg)
<details>
<summary>Changes</summary>
Handle `#dbg_declare_value` in the SROA pass to avoid an `undef` argument, similar to https://github.com/llvm/llvm-project/pull/94070. This prevents an assert in the `instcombine` pass down the line.
---
Full diff: https://github.com/llvm/llvm-project/pull/225902.diff
2 Files Affected:
- (modified) llvm/lib/Transforms/Scalar/SROA.cpp (+8)
- (modified) llvm/test/DebugInfo/Generic/sroa-alloca-offset.ll (+21)
``````````diff
diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp
index f12ab1e590678..e5a5b9109edd2 100644
--- a/llvm/lib/Transforms/Scalar/SROA.cpp
+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
@@ -5946,6 +5946,14 @@ insertNewDbgInst(DIBuilder &DIB, DbgVariableRecord *Orig, AllocaInst *NewAddr,
return;
}
+ if (Orig->isDbgDeclareValue()) {
+ DbgVariableRecord *DVR = DbgVariableRecord::createDVRDeclareValue(
+ NewAddr, Orig->getVariable(), NewFragmentExpr, Orig->getDebugLoc());
+ BeforeInst->getParent()->insertDbgRecordBefore(DVR,
+ BeforeInst->getIterator());
+ return;
+ }
+
// Apply a DIAssignID to the store if it doesn't already have it.
if (!NewAddr->hasMetadata(LLVMContext::MD_DIAssignID)) {
NewAddr->setMetadata(LLVMContext::MD_DIAssignID,
diff --git a/llvm/test/DebugInfo/Generic/sroa-alloca-offset.ll b/llvm/test/DebugInfo/Generic/sroa-alloca-offset.ll
index 6718711f83e04..79e5cc4b3cf3c 100644
--- a/llvm/test/DebugInfo/Generic/sroa-alloca-offset.ll
+++ b/llvm/test/DebugInfo/Generic/sroa-alloca-offset.ll
@@ -204,6 +204,21 @@ entry:
ret i32 %2
}
+; COMMON-LABEL: @fun5
+define i32 @fun5(ptr %source) !dbg !70 {
+entry:
+ %t = alloca %struct.four, align 4
+ #dbg_declare_value(ptr %t, !74, !DIExpression(DW_OP_plus_uconst, 8), !75)
+ ; COMMON: [[FUN5_LOCAL:%.*]] = alloca %struct.two, align 8
+ ; COMMON: #dbg_declare_value(ptr [[FUN5_LOCAL]], ![[t:[0-9]+]], !DIExpression(DW_OP_LLVM_fragment, 0, 64),
+ ; COMMON-NOT: #dbg_assign
+ call void @llvm.memcpy.p0.p0.i64(ptr align 4 %t, ptr align 4 %source, i64 16, i1 false)
+ %1 = getelementptr inbounds %struct.four, ptr %t, i32 0, i32 0
+ %2 = getelementptr inbounds %struct.two, ptr %1, i32 0, i32 1
+ %3 = load i32, ptr %2, align 4
+ ret i32 %3
+}
+
; COMMON-DAG: ![[x0]] = !DILocalVariable(name: "x",
; COMMON-DAG: ![[y0]] = !DILocalVariable(name: "y",
; COMMON-DAG: ![[A0]] = !DILocalVariable(scope:
@@ -221,6 +236,8 @@ entry:
; COMMON-DAG: ![[q]] = !DILocalVariable(name: "q"
; COMMON-DAG: ![[r]] = !DILocalVariable(name: "r"
+; COMMON-DAG: ![[t]] = !DILocalVariable(name: "t"
+
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg)
!llvm.dbg.cu = !{!2}
@@ -273,3 +290,7 @@ declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias
!67 = !DILocalVariable(name: "p", scope: !65, file: !3, line: 9, type: !13)
!68 = !DILocalVariable(name: "q", scope: !65, file: !3, line: 9, type: !13)
!69 = !DILocalVariable(name: "r", scope: !65, file: !3, line: 9, type: !13)
+!70 = distinct !DISubprogram(name: "fun5", scope: !3, file: !3, line: 1, type: !24, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2)
+!73 = !DICompositeType(tag: DW_TAG_structure_type, name: "declare_value", size: 256)
+!74 = !DILocalVariable(name: "t", scope: !70, file: !3, line: 1, type: !73)
+!75 = !DILocation(line: 1, column: 1, scope: !70)
``````````
</details>
https://github.com/llvm/llvm-project/pull/225902
More information about the llvm-commits
mailing list