xref: /llvm-project/llvm/test/Transforms/SimplifyCFG/hoist-dbgvalue-inlined.ll (revision 094572701dce4aaf36f4521d6cf750420d39f206)
1; RUN: opt -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -hoist-common-insts=true -S < %s | FileCheck %s
2; RUN: opt --try-experimental-debuginfo-iterators -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -hoist-common-insts=true -S < %s | FileCheck %s
3; Verify that we don't crash due an invalid !dbg location on the hoisted llvm.dbg.value
4
5define i64 @caller(ptr %ptr, i64 %flag) !dbg !10 {
6init:
7  %v9 = icmp eq i64 %flag, 0
8  br i1 %v9, label %a, label %b
9
10; CHECK:  %vala = load i64, ptr %ptr
11; CHECK-NEXT:  #dbg_value(i64 %vala, [[MD:![0-9]*]]
12; CHECK-NEXT:  #dbg_value(i64 %vala, [[MD]]
13; CHECK-NEXT:  %valbmasked = and i64 %vala, 1
14
15a:                                              ; preds = %init
16  %vala = load i64, ptr %ptr, align 8
17  call void @llvm.dbg.value(metadata i64 %vala, metadata !8, metadata !DIExpression()), !dbg !12
18  br label %test.exit
19
20b:                                              ; preds = %init
21  %valb = load i64, ptr %ptr, align 8
22  call void @llvm.dbg.value(metadata i64 %valb, metadata !8, metadata !DIExpression()), !dbg !13
23  %valbmasked = and i64 %valb, 1
24  br label %test.exit
25
26test.exit:                                      ; preds = %a, %b
27  %retv = phi i64 [ %vala, %a ], [ %valbmasked, %b ]
28  ret i64 %retv
29}
30
31; CHECK: [[MD]] = !DILocalVariable(name: "var"
32
33; Function Attrs: nounwind readnone speculatable
34declare void @llvm.dbg.value(metadata, metadata, metadata) #0
35
36attributes #0 = { nounwind readnone speculatable }
37
38!llvm.module.flags = !{!0}
39!llvm.dbg.cu = !{!1}
40
41!0 = !{i32 2, !"Debug Info Version", i32 3}
42!1 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !2, isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !3)
43!2 = !DIFile(filename: "optbug", directory: "")
44!3 = !{}
45!4 = distinct !DISubprogram(name: "callee", scope: !2, file: !2, line: 1, type: !5, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: false, unit: !1, retainedNodes: !7)
46!5 = !DISubroutineType(types: !6)
47!6 = !{null}
48!7 = !{!8}
49!8 = !DILocalVariable(name: "var", scope: !4, file: !2, type: !9)
50!9 = !DIBasicType(name: "var_t", size: 64, encoding: DW_ATE_unsigned)
51!10 = distinct !DISubprogram(name: "caller", scope: !2, file: !2, line: 5, type: !5, isLocal: false, isDefinition: true, scopeLine: 5, isOptimized: false, unit: !1, retainedNodes: !3)
52!11 = distinct !DILocation(line: 6, scope: !10)
53!12 = !DILocation(line: 2, scope: !4, inlinedAt: !11)
54!13 = !DILocation(line: 3, scope: !4, inlinedAt: !11)
55