1 ; RUN: opt -passes='require<memoryssa>,adce' -o - -S -debug-pass-manager < %s 2>&1 | FileCheck %s
3 ; ADCE should remove the dbg.declare in test1, but it should preserve
4 ; MemorySSA since it only removed a debug instruction.
6 ; Invalidating MemorySSA when only removing debug instructions may lead
7 ; to different code with/without debug info present.
9 ; https://github.com/llvm/llvm-project/issues/58285
10 ; we saw how ADCE removed a dbg.declare, invalidated all analyses, and later
11 ; DSE behaved in some way. Without the dbg.declare in the input ADCE kept
12 ; analysis info, and DSE behaved differently.
14 ; CHECK: Running analysis: MemorySSAAnalysis on test1
15 ; CHECK: Running pass: ADCEPass on test1 (1 instruction)
16 ; CHECK-NOT: Invalidating analysis: MemorySSAAnalysis on test1
18 ; In test2 ADCE also removes an instruction, but since we remove a non-debug
19 ; instruction as well we invalidate several analyses, including MemorySSA.
21 ; CHECK: Running analysis: MemorySSAAnalysis on test2
22 ; CHECK: Running pass: ADCEPass on test2 (2 instructions)
23 ; CHECK: Invalidating analysis: MemorySSAAnalysis on test2
24 ; CHECK: Running pass: PrintModulePass
26 ; CHECK-LABEL: @test1(
28 ; CHECK-NEXT: ret i16 0
30 ; CHECK-LABEL: @test2(
32 ; CHECK-NEXT: ret i16 0
36 call void @llvm.dbg.declare(metadata ptr undef, metadata !4, metadata !DIExpression()), !dbg !16
46 ; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
47 declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
49 attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
52 !llvm.module.flags = !{!0, !1, !2, !3}
54 !0 = !{i32 7, !"Dwarf Version", i32 4}
55 !1 = !{i32 2, !"Debug Info Version", i32 3}
56 !2 = !{i32 1, !"wchar_size", i32 1}
57 !3 = !{i32 7, !"frame-pointer", i32 2}
58 !4 = !DILocalVariable(name: "w", scope: !5, file: !6, line: 18, type: !11)
59 !5 = distinct !DILexicalBlock(scope: !7, file: !6, line: 18, column: 8)
60 !6 = !DIFile(filename: "foo2.c", directory: "/llvm")
61 !7 = distinct !DISubprogram(name: "test1", scope: !6, file: !6, line: 14, type: !8, scopeLine: 14, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !10)
62 !8 = !DISubroutineType(types: !9)
64 !10 = distinct !DICompileUnit(language: DW_LANG_C99, file: !6, producer: "clang version 16.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !9, splitDebugInlining: false, nameTableKind: None)
65 !11 = !DIDerivedType(tag: DW_TAG_typedef, name: "uint64_t", file: !12, line: 60, baseType: !13)
66 !12 = !DIFile(filename: "/include/sys/_stdint.h", directory: "")
67 !13 = !DIDerivedType(tag: DW_TAG_typedef, name: "__uint64_t", file: !14, line: 108, baseType: !15)
68 !14 = !DIFile(filename: "/include/machine/_default_types.h", directory: "")
69 !15 = !DIBasicType(name: "unsigned long long", size: 64, encoding: DW_ATE_unsigned)
70 !16 = !DILocation(line: 18, column: 8, scope: !5)