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 4 5define i32 @foo(i32 %i) nounwind ssp !dbg !0 { 6; CHECK-LABEL: @foo( 7; CHECK-NEXT: entry: 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: [[CALL_1:%.*]] = call i32 (...) @bar(), !dbg [[DBG12:![0-9]+]] 11; CHECK-NEXT: #dbg_value(i32 [[CALL_1]], [[META9]], !DIExpression(), [[META13:![0-9]+]]) 12; CHECK-NEXT: #dbg_value(i32 [[CALL_1]], [[META9]], !DIExpression(), [[META15:![0-9]+]]) 13; CHECK-NEXT: ret i32 [[CALL_1]], !dbg [[DBG17:![0-9]+]] 14; 15entry: 16 call void @llvm.dbg.value(metadata i32 %i, metadata !6, metadata !DIExpression()), !dbg !7 17 call void @llvm.dbg.value(metadata i32 0, metadata !9, metadata !DIExpression()), !dbg !11 18 %cond = icmp ne i32 %i, 0, !dbg !12 19 br i1 %cond, label %then, label %else, !dbg !12 20 21then: 22 %call.1 = call i32 (...) @bar(), !dbg !13 23 call void @llvm.dbg.value(metadata i32 %call.1, metadata !9, metadata !DIExpression()), !dbg !13 24 br label %exit, !dbg !15 25 26else: 27 %call.2 = call i32 (...) @bar(), !dbg !16 28 call void @llvm.dbg.value(metadata i32 %call.2, metadata !9, metadata !DIExpression()), !dbg !16 29 br label %exit, !dbg !18 30 31exit: 32 %k.0 = phi i32 [ %call.1, %then ], [ %call.2, %else ] 33 ret i32 %k.0, !dbg !19 34} 35 36define i1 @hoist_with_debug2(i32 %x) !dbg !22 { 37; CHECK-LABEL: @hoist_with_debug2( 38; CHECK-NEXT: entry: 39; CHECK-NEXT: [[TOBOOL_NOT:%.*]] = icmp ugt i32 [[X:%.*]], 2 40; CHECK-NEXT: #dbg_value(i32 [[X]], [[META19:![0-9]+]], !DIExpression(), [[META21:![0-9]+]]) 41; CHECK-NEXT: #dbg_value(i32 [[X]], [[META19]], !DIExpression(), [[META21]]) 42; CHECK-NEXT: [[DOT:%.*]] = select i1 [[TOBOOL_NOT]], i1 false, i1 true 43; CHECK-NEXT: ret i1 [[DOT]] 44; 45entry: 46 %tobool.not = icmp ugt i32 %x, 2 47 br i1 %tobool.not, label %cond.end.thread, label %cond.end.thread19 48 49cond.end.thread19: ; preds = %land.lhs.true 50 call void @llvm.dbg.value(metadata i32 %x, metadata !24, metadata !DIExpression()), !dbg !25 51 br label %exit 52 53cond.end.thread: ; preds = %land.lhs.true 54 call void @llvm.dbg.value(metadata i32 %x, metadata !24, metadata !DIExpression()), !dbg !25 55 br label %exit 56 57exit: 58 %p = phi i1 [ true, %cond.end.thread19 ], [ false, %cond.end.thread ] 59 ret i1 %p 60} 61 62; Test case for PR49982. 63define i16 @hoist_with_debug3_pr49982(i32 %x, i1 %c.2) !dbg !26 { 64; CHECK-LABEL: @hoist_with_debug3_pr49982( 65; CHECK-NEXT: entry: 66; CHECK-NEXT: br label [[FOR_COND:%.*]] 67; CHECK: for.cond: 68; CHECK-NEXT: [[C_0:%.*]] = icmp sgt i32 [[X:%.*]], 0 69; CHECK-NEXT: [[BRMERGE:%.*]] = select i1 [[C_0]], i1 true, i1 [[C_2:%.*]] 70; CHECK-NEXT: [[DOTMUX:%.*]] = select i1 [[C_0]], i16 0, i16 20 71; CHECK-NEXT: br i1 [[BRMERGE]], label [[COMMON_RET:%.*]], label [[FOR_COND]] 72; CHECK: common.ret: 73; CHECK-NEXT: ret i16 [[DOTMUX]] 74; 75entry: 76 br label %for.cond 77 78for.cond: 79 %c.0 = icmp sgt i32 %x, 0 80 br i1 %c.0, label %check, label %latch 81 82check: 83 %c.1 = icmp ugt i32 %x, 2 84 br i1 %c.1, label %then, label %else 85 86then: 87 call void @llvm.dbg.value(metadata i32 %x, metadata !28, metadata !DIExpression()), !dbg !29 88 br label %exit.2 89 90else: 91 call void @llvm.dbg.value(metadata i32 %x, metadata !28, metadata !DIExpression()), !dbg !29 92 br label %exit.2 93 94latch: 95 br i1 %c.2, label %exit.1, label %for.cond 96 97exit.1: 98 ret i16 20 99 100exit.2: 101 ret i16 0 102} 103 104declare void @llvm.dbg.declare(metadata, metadata, metadata) nounwind readnone 105 106declare i32 @bar(...) 107 108declare void @llvm.dbg.value(metadata, metadata, metadata) nounwind readnone 109 110!llvm.module.flags = !{!21} 111!llvm.dbg.cu = !{!2} 112 113!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) 114!1 = !DIFile(filename: "b.c", directory: "/private/tmp") 115!2 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang", isOptimized: true, emissionKind: FullDebug, file: !20) 116!3 = !DISubroutineType(types: !4) 117!4 = !{!5} 118!5 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed) 119!6 = !DILocalVariable(name: "i", line: 2, arg: 1, scope: !0, file: !1, type: !5) 120!7 = !DILocation(line: 2, column: 13, scope: !0) 121!9 = !DILocalVariable(name: "k", line: 3, scope: !10, file: !1, type: !5) 122!10 = distinct !DILexicalBlock(line: 2, column: 16, file: !20, scope: !0) 123!11 = !DILocation(line: 3, column: 12, scope: !10) 124!12 = !DILocation(line: 4, column: 3, scope: !10) 125!13 = !DILocation(line: 5, column: 5, scope: !14) 126!14 = distinct !DILexicalBlock(line: 4, column: 10, file: !20, scope: !10) 127!15 = !DILocation(line: 6, column: 3, scope: !14) 128!16 = !DILocation(line: 7, column: 5, scope: !17) 129!17 = distinct !DILexicalBlock(line: 6, column: 10, file: !20, scope: !10) 130!18 = !DILocation(line: 8, column: 3, scope: !17) 131!19 = !DILocation(line: 9, column: 3, scope: !10) 132!20 = !DIFile(filename: "b.c", directory: "/private/tmp") 133!21 = !{i32 1, !"Debug Info Version", i32 3} 134 135!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) 136!23 = distinct !DILexicalBlock(line: 21, column: 33, file: !20, scope: !22) 137!24 = !DILocalVariable(name: "y", line: 21, scope: !23, file: !1, type: !5) 138!25 = !DILocation(line: 23, column: 3, scope: !23) 139 140!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) 141!27 = distinct !DILexicalBlock(line: 31, column: 33, file: !20, scope: !26) 142!28 = !DILocalVariable(name: "y", line: 21, scope: !27, file: !1, type: !5) 143!29 = !DILocation(line: 33, column: 3, scope: !27) 144