[llvm] [InstCombine] Retain debug information on store to null instruction (PR #86105)

Orlando Cazalet-Hyams via llvm-commits llvm-commits at lists.llvm.org
Tue May 21 02:57:22 PDT 2024


OCHyams wrote:

Reducing `test.txt` (attached earlier) using `llvm-reduce` gets me:
```
source_filename = "test.ll"
target triple = "hexagon"

define void @_Z3foov() {
entry:
  tail call void null(), !dbg !11
  ret void
}

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!10}

!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "QuIC LLVM Hexagon Clang version 8.7-alpha1 Engineering Release: hexagon-clang-87-43126", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3, splitDebugInlining: false, debugInfoForProfiling: true, nameTableKind: None)
!1 = !DIFile(filename: "test_sym_mod.cpp", directory: "/local/mnt/workspace/asaravan/QTOOL-111650/test_bugpoint")
!2 = !{}
!3 = !{!4, !7}
!4 = !DIGlobalVariableExpression(var: !5, expr: !DIExpression())
!5 = distinct !DIGlobalVariable(name: "def", scope: !0, file: !1, line: 1, type: !6, isLocal: false, isDefinition: true)
!6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 32)
!7 = !DIGlobalVariableExpression(var: !8, expr: !DIExpression())
!8 = distinct !DIGlobalVariable(name: "struct_4", scope: !0, file: !1, line: 70, type: !9, isLocal: true, isDefinition: true)
!9 = distinct !DICompositeType(tag: DW_TAG_structure_type, file: !1, line: 67, size: 160, flags: DIFlagTypePassByValue, elements: !2)
!10 = !{i32 2, !"Debug Info Version", i32 3}
!11 = !DILocation(line: 83, column: 3, scope: !12)
!12 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !1, file: !1, line: 77, type: !13, scopeLine: 78, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
!13 = !DISubroutineType(types: !14)
!14 = !{null}
```

`opt -passes=instcombine test.ll -S`
```
define void @_Z3foov() {
entry:
  store i1 true, ptr poison, align 1  ; missing !dbg
  ret void
}

... metadata ...
```

That only tests one of the 6 call sites of `CreateNonTerminatorUnreachable`. @dwblaikie is that enough coverage?

All the call sites of `CreateNonTerminatorUnreachable` pass the instruction that's being replaced/marked as unreachable in as the `InsertAt` argument. That is to say that this patch does the right thing currently - it applies the source location from an instruction that is being replaced to the one replacing it. However, there's no guarantee that a future usage of `CreateNonTerminatorUnreachable` passes in the to-be-replaced instruction as `InsertAt`, but it seems unlikely that wouldn't be the case.

Overall SGTM once the test has been added.

https://github.com/llvm/llvm-project/pull/86105


More information about the llvm-commits mailing list