1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S < %s | FileCheck %s
3 ; RUN: opt -try-experimental-debuginfo-iterators -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S < %s | FileCheck %s
5 define i32 @foo(i32 %i) nounwind ssp !dbg !0 {
8 ; CHECK-NEXT: #dbg_value(i32 [[I:%.*]], [[META7:![0-9]+]], !DIExpression(), [[META8:![0-9]+]])
9 ; CHECK-NEXT: #dbg_value(i32 0, [[META9:![0-9]+]], !DIExpression(), [[META11:![0-9]+]])
10 ; CHECK-NEXT: [[COND:%.*]] = icmp ne i32 [[I]], 0, !dbg [[DBG12:![0-9]+]]
11 ; CHECK-NEXT: br i1 [[COND]], label [[THEN:%.*]], label [[ELSE:%.*]], !dbg [[DBG12]]
13 ; CHECK-NEXT: [[CALL_1:%.*]] = call i32 (...) @bar(), !dbg [[DBG13:![0-9]+]]
14 ; CHECK-NEXT: #dbg_value(i32 [[CALL_1]], [[META9]], !DIExpression(), [[DBG13]])
15 ; CHECK-NEXT: br label [[EXIT:%.*]], !dbg [[DBG15:![0-9]+]]
17 ; CHECK-NEXT: [[CALL_2:%.*]] = call i32 (...) @bar(), !dbg [[DBG16:![0-9]+]]
18 ; CHECK-NEXT: #dbg_value(i32 [[CALL_2]], [[META9]], !DIExpression(), [[DBG16]])
19 ; CHECK-NEXT: br label [[EXIT]], !dbg [[DBG18:![0-9]+]]
21 ; CHECK-NEXT: [[K_0:%.*]] = phi i32 [ [[CALL_1]], [[THEN]] ], [ [[CALL_2]], [[ELSE]] ]
22 ; CHECK-NEXT: ret i32 [[K_0]], !dbg [[DBG19:![0-9]+]]
25 call void @llvm.dbg.value(metadata i32 %i, metadata !6, metadata !DIExpression()), !dbg !7
26 call void @llvm.dbg.value(metadata i32 0, metadata !9, metadata !DIExpression()), !dbg !11
27 %cond = icmp ne i32 %i, 0, !dbg !12
28 br i1 %cond, label %then, label %else, !dbg !12
31 %call.1 = call i32 (...) @bar(), !dbg !13
32 call void @llvm.dbg.value(metadata i32 %call.1, metadata !9, metadata !DIExpression()), !dbg !13
33 br label %exit, !dbg !15
36 %call.2 = call i32 (...) @bar(), !dbg !16
37 call void @llvm.dbg.value(metadata i32 %call.2, metadata !9, metadata !DIExpression()), !dbg !16
38 br label %exit, !dbg !18
41 %k.0 = phi i32 [ %call.1, %then ], [ %call.2, %else ]
42 ret i32 %k.0, !dbg !19
45 define i1 @hoist_with_debug2(i32 %x) !dbg !22 {
46 ; CHECK-LABEL: @hoist_with_debug2(
48 ; CHECK-NEXT: [[TOBOOL_NOT:%.*]] = icmp ugt i32 [[X:%.*]], 2
49 ; CHECK-NEXT: #dbg_value(i32 [[X]], [[META21:![0-9]+]], !DIExpression(), [[META23:![0-9]+]])
50 ; CHECK-NEXT: #dbg_value(i32 [[X]], [[META21]], !DIExpression(), [[META23]])
51 ; CHECK-NEXT: [[DOT:%.*]] = select i1 [[TOBOOL_NOT]], i1 false, i1 true
52 ; CHECK-NEXT: ret i1 [[DOT]]
55 %tobool.not = icmp ugt i32 %x, 2
56 br i1 %tobool.not, label %cond.end.thread, label %cond.end.thread19
58 cond.end.thread19: ; preds = %land.lhs.true
59 call void @llvm.dbg.value(metadata i32 %x, metadata !24, metadata !DIExpression()), !dbg !25
62 cond.end.thread: ; preds = %land.lhs.true
63 call void @llvm.dbg.value(metadata i32 %x, metadata !24, metadata !DIExpression()), !dbg !25
67 %p = phi i1 [ true, %cond.end.thread19 ], [ false, %cond.end.thread ]
71 ; Test case for PR49982.
72 define i16 @hoist_with_debug3_pr49982(i32 %x, i1 %c.2) !dbg !26 {
73 ; CHECK-LABEL: @hoist_with_debug3_pr49982(
75 ; CHECK-NEXT: br label [[FOR_COND:%.*]]
77 ; CHECK-NEXT: [[C_0:%.*]] = icmp sgt i32 [[X:%.*]], 0
78 ; CHECK-NEXT: [[BRMERGE:%.*]] = select i1 [[C_0]], i1 true, i1 [[C_2:%.*]]
79 ; CHECK-NEXT: [[DOTMUX:%.*]] = select i1 [[C_0]], i16 0, i16 20
80 ; CHECK-NEXT: br i1 [[BRMERGE]], label [[COMMON_RET:%.*]], label [[FOR_COND]]
82 ; CHECK-NEXT: ret i16 [[DOTMUX]]
88 %c.0 = icmp sgt i32 %x, 0
89 br i1 %c.0, label %check, label %latch
92 %c.1 = icmp ugt i32 %x, 2
93 br i1 %c.1, label %then, label %else
96 call void @llvm.dbg.value(metadata i32 %x, metadata !28, metadata !DIExpression()), !dbg !29
100 call void @llvm.dbg.value(metadata i32 %x, metadata !28, metadata !DIExpression()), !dbg !29
104 br i1 %c.2, label %exit.1, label %for.cond
113 declare void @llvm.dbg.declare(metadata, metadata, metadata) nounwind readnone
115 declare i32 @bar(...)
117 declare void @llvm.dbg.value(metadata, metadata, metadata) nounwind readnone
119 !llvm.module.flags = !{!21}
122 !0 = distinct !DISubprogram(name: "foo", line: 2, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !2, file: !20, scope: !1, type: !3)
123 !1 = !DIFile(filename: "b.c", directory: "/private/tmp")
124 !2 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang", isOptimized: true, emissionKind: FullDebug, file: !20)
125 !3 = !DISubroutineType(types: !4)
127 !5 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
128 !6 = !DILocalVariable(name: "i", line: 2, arg: 1, scope: !0, file: !1, type: !5)
129 !7 = !DILocation(line: 2, column: 13, scope: !0)
130 !9 = !DILocalVariable(name: "k", line: 3, scope: !10, file: !1, type: !5)
131 !10 = distinct !DILexicalBlock(line: 2, column: 16, file: !20, scope: !0)
132 !11 = !DILocation(line: 3, column: 12, scope: !10)
133 !12 = !DILocation(line: 4, column: 3, scope: !10)
134 !13 = !DILocation(line: 5, column: 5, scope: !14)
135 !14 = distinct !DILexicalBlock(line: 4, column: 10, file: !20, scope: !10)
136 !15 = !DILocation(line: 6, column: 3, scope: !14)
137 !16 = !DILocation(line: 7, column: 5, scope: !17)
138 !17 = distinct !DILexicalBlock(line: 6, column: 10, file: !20, scope: !10)
139 !18 = !DILocation(line: 8, column: 3, scope: !17)
140 !19 = !DILocation(line: 9, column: 3, scope: !10)
141 !20 = !DIFile(filename: "b.c", directory: "/private/tmp")
142 !21 = !{i32 1, !"Debug Info Version", i32 3}
144 !22 = distinct !DISubprogram(name: "bar", line: 20, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !2, file: !20, scope: !1, type: !3)
145 !23 = distinct !DILexicalBlock(line: 21, column: 33, file: !20, scope: !22)
146 !24 = !DILocalVariable(name: "y", line: 21, scope: !23, file: !1, type: !5)
147 !25 = !DILocation(line: 23, column: 3, scope: !23)
149 !26 = distinct !DISubprogram(name: "zar", line: 20, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !2, file: !20, scope: !1, type: !3)
150 !27 = distinct !DILexicalBlock(line: 31, column: 33, file: !20, scope: !26)
151 !28 = !DILocalVariable(name: "y", line: 21, scope: !27, file: !1, type: !5)
152 !29 = !DILocation(line: 33, column: 3, scope: !27)