1; RUN: opt -passes='loop(simple-loop-unswitch)' -S < %s | FileCheck %s 2; RUN: opt -passes='loop-mssa(simple-loop-unswitch)' -S < %s | FileCheck %s 3 4; Check that SimpleLoopUnswitch's unswitchTrivialBranch() and unswitchTrivialSwitch() 5; propagates debug locations to the new terminators replacing the old ones. 6 7define i32 @test1(ptr %var, i1 %cond1, i1 %cond2) !dbg !5 { 8; CHECK-LABEL: define i32 @test1( 9; CHECK: loop_begin: 10; CHECK-NEXT: br label %[[CONTINUE:.*]], !dbg [[DBG8:![0-9]+]] 11; 12entry: 13 br label %loop_begin, !dbg !8 14 15loop_begin: ; preds = %do_something, %entry 16 br i1 %cond1, label %continue, label %loop_exit, !dbg !9 17 18continue: ; preds = %loop_begin 19 %var_val = load i32, ptr %var, align 4, !dbg !10 20 br i1 %cond2, label %do_something, label %loop_exit, !dbg !11 21 22do_something: ; preds = %continue 23 call void @some_func(), !dbg !12 24 br label %loop_begin, !dbg !13 25 26loop_exit: ; preds = %continue, %loop_begin 27 ret i32 0, !dbg !14 28} 29 30define i32 @test7(i32 %cond1, i32 %x, i32 %y) !dbg !15 { 31; CHECK-LABEL: define i32 @test7( 32; CHECK-SAME: i32 [[COND1:%.*]], i32 [[X:%.*]], i32 [[Y:%.*]]) 33; CHECK-NEXT: entry: 34; CHECK-NEXT: switch i32 [[COND1]], label %[[ENTRY_SPLIT:.*]] [ 35; CHECK-NEXT: i32 0, label %[[LOOP_EXIT:.*]] 36; CHECK-NEXT: i32 1, label %[[LOOP_EXIT]] 37; CHECK-NEXT: ], !dbg [[DBG16:![0-9]+]] 38; CHECK: loop_begin: 39; CHECK-NEXT: br label %[[LATCH:.*]], !dbg [[DBG16]] 40; 41entry: 42 br label %loop_begin, !dbg !16 43 44loop_begin: ; preds = %latch, %entry 45 switch i32 %cond1, label %latch [ 46 i32 0, label %loop_exit 47 i32 1, label %loop_exit 48 ], !dbg !17 49 50latch: ; preds = %loop_begin 51 call void @some_func(), !dbg !18 52 br label %loop_begin, !dbg !19 53 54loop_exit: ; preds = %loop_begin, %loop_begin 55 %result1 = phi i32 [ %x, %loop_begin ], [ %x, %loop_begin ], !dbg !20 56 %result2 = phi i32 [ %y, %loop_begin ], [ %y, %loop_begin ], !dbg !21 57 %result = add i32 %result1, %result2, !dbg !22 58 ret i32 %result, !dbg !23 59} 60 61; Function Attrs: noreturn 62declare void @some_func() 63 64!llvm.dbg.cu = !{!0} 65!llvm.debugify = !{!2, !3} 66!llvm.module.flags = !{!4} 67 68; CHECK: [[DBG8]] = !DILocation(line: 2, 69 70; CHECK: [[DBG16]] = !DILocation(line: 9, 71 72!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug) 73!1 = !DIFile(filename: "test2.ll", directory: "/") 74!2 = !{i32 15} 75!3 = !{i32 0} 76!4 = !{i32 2, !"Debug Info Version", i32 3} 77!5 = distinct !DISubprogram(name: "test1", linkageName: "test1", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0) 78!6 = !DISubroutineType(types: !7) 79!7 = !{} 80!8 = !DILocation(line: 1, column: 1, scope: !5) 81!9 = !DILocation(line: 2, column: 1, scope: !5) 82!10 = !DILocation(line: 3, column: 1, scope: !5) 83!11 = !DILocation(line: 4, column: 1, scope: !5) 84!12 = !DILocation(line: 5, column: 1, scope: !5) 85!13 = !DILocation(line: 6, column: 1, scope: !5) 86!14 = !DILocation(line: 7, column: 1, scope: !5) 87!15 = distinct !DISubprogram(name: "test7", linkageName: "test7", scope: null, file: !1, line: 8, type: !6, scopeLine: 8, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0) 88!16 = !DILocation(line: 8, column: 1, scope: !15) 89!17 = !DILocation(line: 9, column: 1, scope: !15) 90!18 = !DILocation(line: 10, column: 1, scope: !15) 91!19 = !DILocation(line: 11, column: 1, scope: !15) 92!20 = !DILocation(line: 12, column: 1, scope: !15) 93!21 = !DILocation(line: 13, column: 1, scope: !15) 94!22 = !DILocation(line: 14, column: 1, scope: !15) 95!23 = !DILocation(line: 15, column: 1, scope: !15) 96