GlobalOpt SRA curretly drop debug info for globals with existing fragment
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
When a global variable is split by SRA that already has a DW_OP_LLVM_fragment expression the debug info is dropped.
Reproducer that currently fail:
```
; RUN: opt -S -passes=globalopt %s -o - | FileCheck %s
; GlobalOpt SRA splits an existing DW_OP_LLVM_fragment into sub-fragments.
; The global describes bits 32-95 of a 128-bit variable. After SRA into two
; i32 globals, they get fragments (32,32) and (64,32).
@frag_gv = internal global { i32, i32 } zeroinitializer, !dbg !0
; CHECK: @frag_gv.0 = internal unnamed_addr global i32 0{{.*}}!dbg ![[FF0:[0-9]+]]
; CHECK: @frag_gv.1 = internal unnamed_addr global i32 0{{.*}}!dbg ![[FF1:[0-9]+]]
; CHECK-DAG: ![[FF0]] = !DIGlobalVariableExpression(var: ![[FVAR:[0-9]+]], expr: !DIExpression(DW_OP_LLVM_fragment, 32, 32))
; CHECK-DAG: ![[FF1]] = !DIGlobalVariableExpression(var: ![[FVAR]], expr: !DIExpression(DW_OP_LLVM_fragment, 64, 32))
; CHECK-DAG: ![[FVAR]] = distinct !DIGlobalVariable(name: "whole"
declare i32 @get()
define void @frag_writer() {
%a = call i32 @get()
store i32 %a, ptr @frag_gv
%b = call i32 @get()
store i32 %b, ptr getelementptr ({ i32, i32 }, ptr @frag_gv, i32 0, i32 1)
ret void
}
define i32 @frag_reader() {
%v0 = load i32, ptr @frag_gv
%v1 = load i32, ptr getelementptr ({ i32, i32 }, ptr @frag_gv, i32 0, i32 1)
%r = add i32 %v0, %v1
ret i32 %r
}
!llvm.dbg.cu = !{!7}
!llvm.module.flags = !{!12}
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression(DW_OP_LLVM_fragment, 32, 64))
!1 = distinct !DIGlobalVariable(name: "whole", scope: !2, file: !3, line: 1, type: !9, isLocal: true, isDefinition: true)
!2 = distinct !DISubprogram(name: "test", scope: !3, file: !3, line: 1, type: !8, spFlags: DISPFlagDefinition, unit: !7)
!3 = !DIFile(filename: "test.c", directory: "/")
!7 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
!8 = !DISubroutineType(types: !11)
!9 = !DIBasicType(name: "i128", size: 128, encoding: DW_ATE_unsigned)
!11 = !{null}
!12 = !{i32 2, !"Debug Info Version", i32 3}
```
Contributor guide
Assessment
This issue has not been assessed yet.