|
| 1 | +; Test that hoisting conditional branches copies the debug and profiling info |
| 2 | +; metadata from the branch being hoisted. |
| 3 | +; RUN: opt -S -passes=licm -licm-control-flow-hoisting=1 %s -o - | FileCheck %s |
| 4 | + |
| 5 | +; CHECK-LABEL: @triangle_phi |
| 6 | +define void @triangle_phi(i32 %x, ptr %p) { |
| 7 | +; CHECK-LABEL: entry: |
| 8 | +; CHECK: %cmp1 = icmp sgt i32 %x, 0 |
| 9 | +; CHECK: br i1 %cmp1, label %[[IF_LICM:.*]], label %[[THEN_LICM:.*]], !dbg [[ORIG_DBG:![0-9]+]], !prof [[ORIG_PROF:![0-9]+]] |
| 10 | +entry: |
| 11 | + br label %loop, !dbg !5 |
| 12 | + |
| 13 | +; CHECK: [[IF_LICM]]: |
| 14 | +; CHECK: %add = add i32 %x, 1 |
| 15 | +; CHECK: br label %[[THEN_LICM]] |
| 16 | + |
| 17 | +; CHECK: [[THEN_LICM]]: |
| 18 | +; CHECK: phi i32 [ %add, %[[IF_LICM]] ], [ %x, %entry ] |
| 19 | +; CHECK: store i32 %phi, ptr %p |
| 20 | +; CHECK: %cmp2 = icmp ne i32 %phi, 0 |
| 21 | +; CHECK: br label %loop |
| 22 | + |
| 23 | +; CHECK-LABEL: loop: |
| 24 | +loop: |
| 25 | + %cmp1 = icmp sgt i32 %x, 0 |
| 26 | +; CHECK: br i1 %cmp1, label %if, label %then, !dbg [[ORIG_DBG]], !prof [[ORIG_PROF]] |
| 27 | + br i1 %cmp1, label %if, label %then, !dbg !6, !prof !8 |
| 28 | +if: |
| 29 | + %add = add i32 %x, 1 |
| 30 | + br label %then |
| 31 | + |
| 32 | +; CHECK-LABEL: then: |
| 33 | +then: |
| 34 | + %phi = phi i32 [ %add, %if ], [ %x, %loop ] |
| 35 | + store i32 %phi, ptr %p |
| 36 | + %cmp2 = icmp ne i32 %phi, 0 |
| 37 | +; CHECK-NEXT: br i1 %cmp2, label %loop, label %end, !dbg [[OTHER_DBG:![0-9]+]], !prof [[OTHER_PROF:![0-9]+]] |
| 38 | + br i1 %cmp2, label %loop, label %end, !dbg !7, !prof !9 |
| 39 | + |
| 40 | +; CHECK-LABEL: end: |
| 41 | +end: |
| 42 | + ret void |
| 43 | +} |
| 44 | + |
| 45 | +; CHECK-DAG: [[ORIG_DBG]] = !DILocation(line: 2, column: 22 |
| 46 | +; CHECK-DAG: [[ORIG_PROF]] = !{!"branch_weights", i32 5, i32 7} |
| 47 | +; CHECK-DAG: [[OTHER_DBG]] = !DILocation(line: 3, column: 22 |
| 48 | +; CHECK-DAG: [[OTHER_PROF]] = !{!"branch_weights", i32 13, i32 11} |
| 49 | + |
| 50 | + |
| 51 | +!llvm.module.flags = !{!2, !3} |
| 52 | + |
| 53 | +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1) |
| 54 | +!1 = !DIFile(filename: "t", directory: "/") |
| 55 | +!2 = !{i32 7, !"Dwarf Version", i32 5} |
| 56 | +!3 = !{i32 2, !"Debug Info Version", i32 3} |
| 57 | +!4 = distinct !DISubprogram(name: "triangle_phi", linkageName: "triangle_phi", scope: !1, file: !1, line: 1, unit: !0) |
| 58 | +!5 = !DILocation(line: 1, column: 22, scope: !4) |
| 59 | +!6 = !DILocation(line: 2, column: 22, scope: !4) |
| 60 | +!7 = !DILocation(line: 3, column: 22, scope: !4) |
| 61 | +!8 = !{!"branch_weights", i32 5, i32 7} |
| 62 | +!9 = !{!"branch_weights", i32 13, i32 11} |
0 commit comments