| 
 | 1 | +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals --version 2  | 
 | 2 | +; Test that hoisting conditional branches copies the debug and profiling info  | 
 | 3 | +; metadata from the branch being hoisted.  | 
 | 4 | +; RUN: opt -S -passes=licm -licm-control-flow-hoisting=1 %s -o - | FileCheck %s --check-prefixes=FOR-DEBUG  | 
 | 5 | +; RUN: opt -S -passes=licm -licm-control-flow-hoisting=1 -dbginfo-prefer-sample-profiling %s -o - | FileCheck %s --check-prefixes=FOR-AFDO  | 
 | 6 | + | 
 | 7 | +define void @triangle_phi(i32 %x, ptr %p) {  | 
 | 8 | +; FOR-DEBUG-LABEL: define void @triangle_phi  | 
 | 9 | +; FOR-DEBUG-SAME: (i32 [[X:%.*]], ptr [[P:%.*]]) {  | 
 | 10 | +; FOR-DEBUG-NEXT:  entry:  | 
 | 11 | +; FOR-DEBUG-NEXT:    [[CMP1:%.*]] = icmp sgt i32 [[X]], 0  | 
 | 12 | +; FOR-DEBUG-NEXT:    br i1 [[CMP1]], label [[IF_LICM:%.*]], label [[THEN_LICM:%.*]], !prof [[PROF2:![0-9]+]]  | 
 | 13 | +; FOR-DEBUG:       if.licm:  | 
 | 14 | +; FOR-DEBUG-NEXT:    [[ADD:%.*]] = add i32 [[X]], 1  | 
 | 15 | +; FOR-DEBUG-NEXT:    br label [[THEN_LICM]]  | 
 | 16 | +; FOR-DEBUG:       then.licm:  | 
 | 17 | +; FOR-DEBUG-NEXT:    [[PHI:%.*]] = phi i32 [ [[ADD]], [[IF_LICM]] ], [ [[X]], [[ENTRY:%.*]] ]  | 
 | 18 | +; FOR-DEBUG-NEXT:    store i32 [[PHI]], ptr [[P]], align 4  | 
 | 19 | +; FOR-DEBUG-NEXT:    [[CMP2:%.*]] = icmp ne i32 [[PHI]], 0  | 
 | 20 | +; FOR-DEBUG-NEXT:    br label [[LOOP:%.*]]  | 
 | 21 | +; FOR-DEBUG:       loop:  | 
 | 22 | +; FOR-DEBUG-NEXT:    br i1 [[CMP1]], label [[IF:%.*]], label [[THEN:%.*]], !dbg [[DBG3:![0-9]+]], !prof [[PROF2]]  | 
 | 23 | +; FOR-DEBUG:       if:  | 
 | 24 | +; FOR-DEBUG-NEXT:    br label [[THEN]]  | 
 | 25 | +; FOR-DEBUG:       then:  | 
 | 26 | +; FOR-DEBUG-NEXT:    br i1 [[CMP2]], label [[LOOP]], label [[END:%.*]], !dbg [[DBG7:![0-9]+]], !prof [[PROF8:![0-9]+]]  | 
 | 27 | +; FOR-DEBUG:       end:  | 
 | 28 | +; FOR-DEBUG-NEXT:    ret void  | 
 | 29 | +;  | 
 | 30 | +; FOR-AFDO-LABEL: define void @triangle_phi  | 
 | 31 | +; FOR-AFDO-SAME: (i32 [[X:%.*]], ptr [[P:%.*]]) {  | 
 | 32 | +; FOR-AFDO-NEXT:  entry:  | 
 | 33 | +; FOR-AFDO-NEXT:    [[CMP1:%.*]] = icmp sgt i32 [[X]], 0  | 
 | 34 | +; FOR-AFDO-NEXT:    br i1 [[CMP1]], label [[IF_LICM:%.*]], label [[THEN_LICM:%.*]], !dbg [[DBG2:![0-9]+]], !prof [[PROF6:![0-9]+]]  | 
 | 35 | +; FOR-AFDO:       if.licm:  | 
 | 36 | +; FOR-AFDO-NEXT:    [[ADD:%.*]] = add i32 [[X]], 1  | 
 | 37 | +; FOR-AFDO-NEXT:    br label [[THEN_LICM]]  | 
 | 38 | +; FOR-AFDO:       then.licm:  | 
 | 39 | +; FOR-AFDO-NEXT:    [[PHI:%.*]] = phi i32 [ [[ADD]], [[IF_LICM]] ], [ [[X]], [[ENTRY:%.*]] ]  | 
 | 40 | +; FOR-AFDO-NEXT:    store i32 [[PHI]], ptr [[P]], align 4  | 
 | 41 | +; FOR-AFDO-NEXT:    [[CMP2:%.*]] = icmp ne i32 [[PHI]], 0  | 
 | 42 | +; FOR-AFDO-NEXT:    br label [[LOOP:%.*]]  | 
 | 43 | +; FOR-AFDO:       loop:  | 
 | 44 | +; FOR-AFDO-NEXT:    br i1 [[CMP1]], label [[IF:%.*]], label [[THEN:%.*]], !dbg [[DBG2]], !prof [[PROF6]]  | 
 | 45 | +; FOR-AFDO:       if:  | 
 | 46 | +; FOR-AFDO-NEXT:    br label [[THEN]]  | 
 | 47 | +; FOR-AFDO:       then:  | 
 | 48 | +; FOR-AFDO-NEXT:    br i1 [[CMP2]], label [[LOOP]], label [[END:%.*]], !dbg [[DBG7:![0-9]+]], !prof [[PROF8:![0-9]+]]  | 
 | 49 | +; FOR-AFDO:       end:  | 
 | 50 | +; FOR-AFDO-NEXT:    ret void  | 
 | 51 | +;  | 
 | 52 | +entry:  | 
 | 53 | +  br label %loop, !dbg !5  | 
 | 54 | +loop:  | 
 | 55 | +  %cmp1 = icmp sgt i32 %x, 0  | 
 | 56 | +  br i1 %cmp1, label %if, label %then, !dbg !6, !prof !8  | 
 | 57 | +if:  | 
 | 58 | +  %add = add i32 %x, 1  | 
 | 59 | +  br label %then  | 
 | 60 | + | 
 | 61 | +then:  | 
 | 62 | +  %phi = phi i32 [ %add, %if ], [ %x, %loop ]  | 
 | 63 | +  store i32 %phi, ptr %p  | 
 | 64 | +  %cmp2 = icmp ne i32 %phi, 0  | 
 | 65 | +  br i1 %cmp2, label %loop, label %end, !dbg !7, !prof !9  | 
 | 66 | + | 
 | 67 | +end:  | 
 | 68 | +  ret void  | 
 | 69 | +}  | 
 | 70 | + | 
 | 71 | +!llvm.module.flags = !{!2, !3}  | 
 | 72 | + | 
 | 73 | +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1)  | 
 | 74 | +!1 = !DIFile(filename: "t", directory: "/")  | 
 | 75 | +!2 = !{i32 7, !"Dwarf Version", i32 5}  | 
 | 76 | +!3 = !{i32 2, !"Debug Info Version", i32 3}  | 
 | 77 | +!4 = distinct !DISubprogram(name: "triangle_phi", linkageName: "triangle_phi", scope: !1, file: !1, line: 1, unit: !0)  | 
 | 78 | +!5 = !DILocation(line: 1, column: 22, scope: !4)  | 
 | 79 | +!6 = !DILocation(line: 2, column: 22, scope: !4)  | 
 | 80 | +!7 = !DILocation(line: 3, column: 22, scope: !4)  | 
 | 81 | +!8 = !{!"branch_weights", i32 5, i32 7}  | 
 | 82 | +!9 = !{!"branch_weights", i32 13, i32 11}  | 
 | 83 | +;.  | 
 | 84 | +; FOR-DEBUG: [[META0:![0-9]+]] = !{i32 7, !"Dwarf Version", i32 5}  | 
 | 85 | +; FOR-DEBUG: [[META1:![0-9]+]] = !{i32 2, !"Debug Info Version", i32 3}  | 
 | 86 | +; FOR-DEBUG: [[PROF2]] = !{!"branch_weights", i32 5, i32 7}  | 
 | 87 | +; FOR-DEBUG: [[DBG3]] = !DILocation(line: 2, column: 22, scope: [[META4:![0-9]+]])  | 
 | 88 | +; FOR-DEBUG: [[META4]] = distinct !DISubprogram(name: "triangle_phi", linkageName: "triangle_phi", scope: [[META5:![0-9]+]], file: [[META5]], line: 1, spFlags: DISPFlagDefinition, unit: [[META6:![0-9]+]])  | 
 | 89 | +; FOR-DEBUG: [[META5]] = !DIFile(filename: "{{.*}}t", directory: {{.*}})  | 
 | 90 | +; FOR-DEBUG: [[META6]] = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: [[META5]], isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug)  | 
 | 91 | +; FOR-DEBUG: [[DBG7]] = !DILocation(line: 3, column: 22, scope: [[META4]])  | 
 | 92 | +; FOR-DEBUG: [[PROF8]] = !{!"branch_weights", i32 13, i32 11}  | 
 | 93 | +;.  | 
 | 94 | +; FOR-AFDO: [[META0:![0-9]+]] = !{i32 7, !"Dwarf Version", i32 5}  | 
 | 95 | +; FOR-AFDO: [[META1:![0-9]+]] = !{i32 2, !"Debug Info Version", i32 3}  | 
 | 96 | +; FOR-AFDO: [[DBG2]] = !DILocation(line: 2, column: 22, scope: [[META3:![0-9]+]])  | 
 | 97 | +; FOR-AFDO: [[META3]] = distinct !DISubprogram(name: "triangle_phi", linkageName: "triangle_phi", scope: [[META4:![0-9]+]], file: [[META4]], line: 1, spFlags: DISPFlagDefinition, unit: [[META5:![0-9]+]])  | 
 | 98 | +; FOR-AFDO: [[META4]] = !DIFile(filename: "{{.*}}t", directory: {{.*}})  | 
 | 99 | +; FOR-AFDO: [[META5]] = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: [[META4]], isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug)  | 
 | 100 | +; FOR-AFDO: [[PROF6]] = !{!"branch_weights", i32 5, i32 7}  | 
 | 101 | +; FOR-AFDO: [[DBG7]] = !DILocation(line: 3, column: 22, scope: [[META3]])  | 
 | 102 | +; FOR-AFDO: [[PROF8]] = !{!"branch_weights", i32 13, i32 11}  | 
 | 103 | +;.  | 
0 commit comments