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