|
| 1 | +; RUN: opt -S -passes=tailcallelim < %s | FileCheck %s |
| 2 | + |
| 3 | +; Check that TailCallElim's cleanupAndFinalize drops the debug location of `AccRecInstrNew`, |
| 4 | +; because it is cloned from `AccRecInstr` (`%accumulate*` in the following IR) with the |
| 5 | +; debug location and inserted into the block of a different branch. |
| 6 | +; @test6_multiple_returns tests that when RetSelects.empty() is false (no select instruction is inserted) |
| 7 | +; @test7_multiple_accumulators tests it when RetSelects.empty() is true |
| 8 | + |
| 9 | +define i32 @test6_multiple_returns(i32 %x, i32 %y) local_unnamed_addr !dbg !5 { |
| 10 | +; CHECK-LABEL: define i32 @test6_multiple_returns( |
| 11 | +; CHECK: case0: |
| 12 | +; CHECK: [[ACCUMULATOR_RET_TR2:%.*]] = add i32 %accumulator.tr, %helper{{$}} |
| 13 | +; CHECK: case99: |
| 14 | +; CHECK: [[ACCUMULATOR_RET_TR:%.*]] = add i32 %accumulator.tr, 18{{$}} |
| 15 | +; CHECK: default: |
| 16 | +; |
| 17 | +entry: |
| 18 | + switch i32 %x, label %default [ |
| 19 | + i32 0, label %case0 |
| 20 | + i32 99, label %case99 |
| 21 | + ], !dbg !8 |
| 22 | + |
| 23 | +case0: ; preds = %entry |
| 24 | + %helper = call i32 @test6_helper(), !dbg !9 |
| 25 | + ret i32 %helper, !dbg !10 |
| 26 | + |
| 27 | +case99: ; preds = %entry |
| 28 | + %sub1 = add i32 %x, -1, !dbg !11 |
| 29 | + %recurse1 = call i32 @test6_multiple_returns(i32 %sub1, i32 %y), !dbg !12 |
| 30 | + ret i32 18, !dbg !13 |
| 31 | + |
| 32 | +default: ; preds = %entry |
| 33 | + %sub2 = add i32 %x, -1, !dbg !14 |
| 34 | + %recurse2 = call i32 @test6_multiple_returns(i32 %sub2, i32 %y), !dbg !15 |
| 35 | + %accumulate = add i32 %recurse2, %y, !dbg !16 |
| 36 | + ret i32 %accumulate, !dbg !17 |
| 37 | +} |
| 38 | + |
| 39 | +declare i32 @test6_helper() |
| 40 | + |
| 41 | +define i32 @test7_multiple_accumulators(i32 %a) local_unnamed_addr !dbg !18 { |
| 42 | +; CHECK-LABEL: define i32 @test7_multiple_accumulators( |
| 43 | +; CHECK: if.end3: |
| 44 | +; CHECK: [[ACCUMULATOR_RET_TR:%.*]] = add nsw i32 %accumulator.tr, [[ACCUMULATE2:.*]]{{$}} |
| 45 | +; CHECK: return: |
| 46 | +; CHECK: [[ACCUMULATOR_RET_TR1:%.*]] = add nsw i32 %accumulator.tr, 0{{$}} |
| 47 | +; |
| 48 | +entry: |
| 49 | + %tobool = icmp eq i32 %a, 0, !dbg !19 |
| 50 | + br i1 %tobool, label %return, label %if.end, !dbg !20 |
| 51 | + |
| 52 | +if.end: ; preds = %entry |
| 53 | + %and = and i32 %a, 1, !dbg !21 |
| 54 | + %tobool1 = icmp eq i32 %and, 0, !dbg !22 |
| 55 | + %sub = add nsw i32 %a, -1, !dbg !23 |
| 56 | + br i1 %tobool1, label %if.end3, label %if.then2, !dbg !24 |
| 57 | + |
| 58 | +if.then2: ; preds = %if.end |
| 59 | + %recurse1 = tail call i32 @test7_multiple_accumulators(i32 %sub), !dbg !25 |
| 60 | + %accumulate1 = add nsw i32 %recurse1, 1, !dbg !26 |
| 61 | + br label %return, !dbg !27 |
| 62 | + |
| 63 | +if.end3: ; preds = %if.end |
| 64 | + %recurse2 = tail call i32 @test7_multiple_accumulators(i32 %sub), !dbg !28 |
| 65 | + %accumulate2 = mul nsw i32 %recurse2, 2, !dbg !29 |
| 66 | + br label %return, !dbg !30 |
| 67 | + |
| 68 | +return: ; preds = %if.end3, %if.then2, %entry |
| 69 | + %retval.0 = phi i32 [ %accumulate1, %if.then2 ], [ %accumulate2, %if.end3 ], [ 0, %entry ], !dbg !31 |
| 70 | + ret i32 %retval.0, !dbg !32 |
| 71 | +} |
| 72 | + |
| 73 | +!llvm.dbg.cu = !{!0} |
| 74 | +!llvm.debugify = !{!2, !3} |
| 75 | +!llvm.module.flags = !{!4} |
| 76 | + |
| 77 | +!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug) |
| 78 | +!1 = !DIFile(filename: "all.ll", directory: "/") |
| 79 | +!2 = !{i32 24} |
| 80 | +!3 = !{i32 0} |
| 81 | +!4 = !{i32 2, !"Debug Info Version", i32 3} |
| 82 | +!5 = distinct !DISubprogram(name: "test6_multiple_returns", linkageName: "test6_multiple_returns", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0) |
| 83 | +!6 = !DISubroutineType(types: !7) |
| 84 | +!7 = !{} |
| 85 | +!8 = !DILocation(line: 1, column: 1, scope: !5) |
| 86 | +!9 = !DILocation(line: 2, column: 1, scope: !5) |
| 87 | +!10 = !DILocation(line: 3, column: 1, scope: !5) |
| 88 | +!11 = !DILocation(line: 4, column: 1, scope: !5) |
| 89 | +!12 = !DILocation(line: 5, column: 1, scope: !5) |
| 90 | +!13 = !DILocation(line: 6, column: 1, scope: !5) |
| 91 | +!14 = !DILocation(line: 7, column: 1, scope: !5) |
| 92 | +!15 = !DILocation(line: 8, column: 1, scope: !5) |
| 93 | +!16 = !DILocation(line: 9, column: 1, scope: !5) |
| 94 | +!17 = !DILocation(line: 10, column: 1, scope: !5) |
| 95 | +!18 = distinct !DISubprogram(name: "test7_multiple_accumulators", linkageName: "test7_multiple_accumulators", scope: null, file: !1, line: 11, type: !6, scopeLine: 11, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0) |
| 96 | +!19 = !DILocation(line: 11, column: 1, scope: !18) |
| 97 | +!20 = !DILocation(line: 12, column: 1, scope: !18) |
| 98 | +!21 = !DILocation(line: 13, column: 1, scope: !18) |
| 99 | +!22 = !DILocation(line: 14, column: 1, scope: !18) |
| 100 | +!23 = !DILocation(line: 15, column: 1, scope: !18) |
| 101 | +!24 = !DILocation(line: 16, column: 1, scope: !18) |
| 102 | +!25 = !DILocation(line: 17, column: 1, scope: !18) |
| 103 | +!26 = !DILocation(line: 18, column: 1, scope: !18) |
| 104 | +!27 = !DILocation(line: 19, column: 1, scope: !18) |
| 105 | +!28 = !DILocation(line: 20, column: 1, scope: !18) |
| 106 | +!29 = !DILocation(line: 21, column: 1, scope: !18) |
| 107 | +!30 = !DILocation(line: 22, column: 1, scope: !18) |
| 108 | +!31 = !DILocation(line: 23, column: 1, scope: !18) |
| 109 | +!32 = !DILocation(line: 24, column: 1, scope: !18) |
0 commit comments