1# RUN: llc -verify-machineinstrs -mcpu=pwr9 -mtriple powerpc64le-unknown-linux-gnu \ 2# RUN: -run-pass=codegenprepare -o - %s | FileCheck %s 3# RUN: llc -verify-machineinstrs -mcpu=pwr8 -mtriple powerpc64le-unknown-linux-gnu \ 4# RUN: -run-pass=codegenprepare -o - %s | FileCheck %s 5--- | 6 define i32 @weighted_select1(i32 %a, i32 %b) { 7 %cmp = icmp ne i32 %a, 0 8 %sel = select i1 %cmp, i32 %a, i32 %b, !prof !14 9 ret i32 %sel 10 11 ; If branch_weights > 99% or branch_weights < 1%, the select will be 12 ; converted to branch, here !14 = 99/100, !14 = 99%, so it will do nothing. 13 ; CHECK-LABEL: weighted_select1 14 ; CHECK: %cmp = icmp ne i32 %a, 0 15 ; CHECK-NEXT: %sel = select i1 %cmp, i32 %a, i32 %b, !prof !14 16 ; CHECK-NEXT: ret i32 %sel 17 } 18 19 define i32 @weighted_select2(i32 %a, i32 %b) { 20 %cmp = icmp ne i32 %a, 0 21 %sel = select i1 %cmp, i32 %a, i32 %b, !prof !15 22 ret i32 %sel 23 24 ; If branch_weights > 99% or branch_weights < 1%, the select will be converted 25 ; to branch, here !15 = 100/101, !15 > 99%, so it will convert select to 26 ; branch. 27 ; CHECK-LABEL: weighted_select2 28 ; CHECK: %sel.frozen = freeze i32 %a 29 ; CHECK: %cmp = icmp ne i32 %sel.frozen, 0 30 ; CHECK-NEXT: br i1 %cmp, label %select.end, label %select.false, !prof !15 31 ; CHECK: select.false: 32 ; CHECK-NEXT: br label %select.end 33 ; CHECK: select.end: 34 ; CHECK-NEXT: %sel = phi i32 [ %a, %0 ], [ %b, %select.false ] 35 ; CHECK-NEXT: ret i32 %sel 36 } 37 38 define i32 @weighted_select3(i32 %a, i32 %b) { 39 %cmp = icmp ne i32 %a, 0 40 %sel = select i1 %cmp, i32 %a, i32 %b, !prof !16 41 ret i32 %sel 42 43 ; If branch_weights > 99% or branch_weights < 1%, the select will be converted 44 ; to branch, here !16 = 1/101, !16 < 1%, so it will convert select to branch. 45 ; CHECK-LABEL: weighted_select3 46 ; CHECK: %sel.frozen = freeze i32 %a 47 ; CHECK: %cmp = icmp ne i32 %sel.frozen, 0 48 ; CHECK-NEXT: br i1 %cmp, label %select.end, label %select.false, !prof !16 49 ; CHECK: select.false: 50 ; CHECK-NEXT: br label %select.end 51 ; CHECK: select.end: 52 ; CHECK-NEXT: %sel = phi i32 [ %a, %0 ], [ %b, %select.false ] 53 ; CHECK-NEXT: ret i32 %sel 54 } 55 56 define i32 @unweighted_select(i32 %a, i32 %b) { 57 %cmp = icmp ne i32 %a, 0 58 %sel = select i1 %cmp, i32 %a, i32 %b, !prof !17 59 ret i32 %sel 60 61 ; There is no weight_branch information, so it will do nothing. 62 ; CHECK-LABEL: unweighted_select 63 ; CHECK: %cmp = icmp ne i32 %a, 0 64 ; CHECK-NEXT: %sel = select i1 %cmp, i32 %a, i32 %b, !prof !17 65 ; CHECK-NEXT: ret i32 %sel 66 } 67 68 ; Function Attrs: optsize 69 define i32 @weighted_select_optsize(i32 %a, i32 %b) #0 { 70 %cmp = icmp ne i32 %a, 0 71 %sel = select i1 %cmp, i32 %a, i32 %b, !prof !15 72 ret i32 %sel 73 74 ; This function has used the optsize flag, so it will do nothing. 75 ; CHECK-LABEL: weighted_select_optsize 76 ; CHECK: %cmp = icmp ne i32 %a, 0 77 ; CHECK-NEXT: %sel = select i1 %cmp, i32 %a, i32 %b, !prof !15 78 ; CHECK-NEXT: ret i32 %sel 79 } 80 81 define i32 @weighted_select_pgso(i32 %a, i32 %b) !prof !18 { 82 %cmp = icmp ne i32 %a, 0 83 %sel = select i1 %cmp, i32 %a, i32 %b, !prof !15 84 ret i32 %sel 85 86 ; The function_entry_count of this function is 0, so it will do nothing. 87 ; CHECK-LABEL: weighted_select_pgso 88 ; CHECK: %cmp = icmp ne i32 %a, 0 89 ; CHECK-NEXT: %sel = select i1 %cmp, i32 %a, i32 %b, !prof !15 90 ; CHECK-NEXT: ret i32 %sel 91 } 92 93 attributes #0 = { optsize } 94 95 !llvm.module.flags = !{!0} 96 97 !0 = !{i32 1, !"ProfileSummary", !1} 98 !1 = !{!2, !3, !4, !5, !6, !7, !8, !9} 99 !2 = !{!"ProfileFormat", !"InstrProf"} 100 !3 = !{!"TotalCount", i64 10000} 101 !4 = !{!"MaxCount", i64 10} 102 !5 = !{!"MaxInternalCount", i64 1} 103 !6 = !{!"MaxFunctionCount", i64 1000} 104 !7 = !{!"NumCounts", i64 3} 105 !8 = !{!"NumFunctions", i64 3} 106 !9 = !{!"DetailedSummary", !10} 107 !10 = !{!11, !12, !13} 108 !11 = !{i32 10000, i64 100, i32 1} 109 !12 = !{i32 999000, i64 100, i32 1} 110 !13 = !{i32 999999, i64 1, i32 2} 111 !14 = !{!"branch_weights", i32 1, i32 99} 112 !15 = !{!"branch_weights", i32 1, i32 100} 113 !16 = !{!"branch_weights", i32 100, i32 1} 114 !17 = !{!"branch_weights", i32 0, i32 0} 115 !18 = !{!"function_entry_count", i64 0} 116 117... 118