1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S < %s | FileCheck %s
4 define i32 @foo(i32 %i) nounwind ssp !dbg !0 {
7 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 [[I:%.*]], metadata [[META7:![0-9]+]], metadata !DIExpression()), !dbg [[DBG8:![0-9]+]]
8 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 0, metadata [[META9:![0-9]+]], metadata !DIExpression()), !dbg [[DBG11:![0-9]+]]
9 ; CHECK-NEXT: [[COND:%.*]] = icmp ne i32 [[I]], 0, !dbg [[DBG12:![0-9]+]]
10 ; CHECK-NEXT: br i1 [[COND]], label [[THEN:%.*]], label [[ELSE:%.*]], !dbg [[DBG12]]
12 ; CHECK-NEXT: [[CALL_1:%.*]] = call i32 (...) @bar(), !dbg [[DBG13:![0-9]+]]
13 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 [[CALL_1]], metadata [[META9]], metadata !DIExpression()), !dbg [[DBG13]]
14 ; CHECK-NEXT: br label [[EXIT:%.*]], !dbg [[DBG15:![0-9]+]]
16 ; CHECK-NEXT: [[CALL_2:%.*]] = call i32 (...) @bar(), !dbg [[DBG16:![0-9]+]]
17 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 [[CALL_2]], metadata [[META9]], metadata !DIExpression()), !dbg [[DBG16]]
18 ; CHECK-NEXT: br label [[EXIT]], !dbg [[DBG18:![0-9]+]]
20 ; CHECK-NEXT: [[K_0:%.*]] = phi i32 [ [[CALL_1]], [[THEN]] ], [ [[CALL_2]], [[ELSE]] ]
21 ; CHECK-NEXT: ret i32 [[K_0]], !dbg [[DBG19:![0-9]+]]
24 call void @llvm.dbg.value(metadata i32 %i, metadata !6, metadata !DIExpression()), !dbg !7
25 call void @llvm.dbg.value(metadata i32 0, metadata !9, metadata !DIExpression()), !dbg !11
26 %cond = icmp ne i32 %i, 0, !dbg !12
27 br i1 %cond, label %then, label %else, !dbg !12
30 %call.1 = call i32 (...) @bar(), !dbg !13
31 call void @llvm.dbg.value(metadata i32 %call.1, metadata !9, metadata !DIExpression()), !dbg !13
32 br label %exit, !dbg !15
35 %call.2 = call i32 (...) @bar(), !dbg !16
36 call void @llvm.dbg.value(metadata i32 %call.2, metadata !9, metadata !DIExpression()), !dbg !16
37 br label %exit, !dbg !18
40 %k.0 = phi i32 [ %call.1, %then ], [ %call.2, %else ]
41 ret i32 %k.0, !dbg !19
44 define i1 @hoist_with_debug2(i32 %x) !dbg !22 {
45 ; CHECK-LABEL: @hoist_with_debug2(
47 ; CHECK-NEXT: [[TOBOOL_NOT:%.*]] = icmp ugt i32 [[X:%.*]], 2
48 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 [[X]], metadata [[META21:![0-9]+]], metadata !DIExpression()), !dbg [[DBG23:![0-9]+]]
49 ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 [[X]], metadata [[META21]], metadata !DIExpression()), !dbg [[DBG23]]
50 ; CHECK-NEXT: [[DOT:%.*]] = select i1 [[TOBOOL_NOT]], i1 false, i1 true
51 ; CHECK-NEXT: ret i1 [[DOT]]
54 %tobool.not = icmp ugt i32 %x, 2
55 br i1 %tobool.not, label %cond.end.thread, label %cond.end.thread19
57 cond.end.thread19: ; preds = %land.lhs.true
58 call void @llvm.dbg.value(metadata i32 %x, metadata !24, metadata !DIExpression()), !dbg !25
61 cond.end.thread: ; preds = %land.lhs.true
62 call void @llvm.dbg.value(metadata i32 %x, metadata !24, metadata !DIExpression()), !dbg !25
66 %p = phi i1 [ true, %cond.end.thread19 ], [ false, %cond.end.thread ]
70 ; Test case for PR49982.
71 define i16 @hoist_with_debug3_pr49982(i32 %x, i1 %c.2) !dbg !26 {
72 ; CHECK-LABEL: @hoist_with_debug3_pr49982(
74 ; CHECK-NEXT: br label [[FOR_COND:%.*]]
76 ; CHECK-NEXT: [[C_0:%.*]] = icmp sgt i32 [[X:%.*]], 0
77 ; CHECK-NEXT: [[BRMERGE:%.*]] = select i1 [[C_0]], i1 true, i1 [[C_2:%.*]]
78 ; CHECK-NEXT: [[DOTMUX:%.*]] = select i1 [[C_0]], i16 0, i16 20
79 ; CHECK-NEXT: br i1 [[BRMERGE]], label [[COMMON_RET:%.*]], label [[FOR_COND]]
81 ; CHECK-NEXT: ret i16 [[DOTMUX]]
87 %c.0 = icmp sgt i32 %x, 0
88 br i1 %c.0, label %check, label %latch
91 %c.1 = icmp ugt i32 %x, 2
92 br i1 %c.1, label %then, label %else
95 call void @llvm.dbg.value(metadata i32 %x, metadata !28, metadata !DIExpression()), !dbg !29
99 call void @llvm.dbg.value(metadata i32 %x, metadata !28, metadata !DIExpression()), !dbg !29
103 br i1 %c.2, label %exit.1, label %for.cond
112 declare void @llvm.dbg.declare(metadata, metadata, metadata) nounwind readnone
114 declare i32 @bar(...)
116 declare void @llvm.dbg.value(metadata, metadata, metadata) nounwind readnone
118 !llvm.module.flags = !{!21}
121 !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)
122 !1 = !DIFile(filename: "b.c", directory: "/private/tmp")
123 !2 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang", isOptimized: true, emissionKind: FullDebug, file: !20)
124 !3 = !DISubroutineType(types: !4)
126 !5 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
127 !6 = !DILocalVariable(name: "i", line: 2, arg: 1, scope: !0, file: !1, type: !5)
128 !7 = !DILocation(line: 2, column: 13, scope: !0)
129 !9 = !DILocalVariable(name: "k", line: 3, scope: !10, file: !1, type: !5)
130 !10 = distinct !DILexicalBlock(line: 2, column: 16, file: !20, scope: !0)
131 !11 = !DILocation(line: 3, column: 12, scope: !10)
132 !12 = !DILocation(line: 4, column: 3, scope: !10)
133 !13 = !DILocation(line: 5, column: 5, scope: !14)
134 !14 = distinct !DILexicalBlock(line: 4, column: 10, file: !20, scope: !10)
135 !15 = !DILocation(line: 6, column: 3, scope: !14)
136 !16 = !DILocation(line: 7, column: 5, scope: !17)
137 !17 = distinct !DILexicalBlock(line: 6, column: 10, file: !20, scope: !10)
138 !18 = !DILocation(line: 8, column: 3, scope: !17)
139 !19 = !DILocation(line: 9, column: 3, scope: !10)
140 !20 = !DIFile(filename: "b.c", directory: "/private/tmp")
141 !21 = !{i32 1, !"Debug Info Version", i32 3}
143 !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)
144 !23 = distinct !DILexicalBlock(line: 21, column: 33, file: !20, scope: !22)
145 !24 = !DILocalVariable(name: "y", line: 21, scope: !23, file: !1, type: !5)
146 !25 = !DILocation(line: 23, column: 3, scope: !23)
148 !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)
149 !27 = distinct !DILexicalBlock(line: 31, column: 33, file: !20, scope: !26)
150 !28 = !DILocalVariable(name: "y", line: 21, scope: !27, file: !1, type: !5)
151 !29 = !DILocation(line: 33, column: 3, scope: !27)