1 ; RUN: opt < %s -analyze -block-freq | FileCheck %s 2 3 define i32 @test1(i32 %i, i32* %a) { 4 ; CHECK: Printing analysis {{.*}} for function 'test1' 5 ; CHECK: entry = 1024 6 entry: 7 br label %body 8 9 ; Loop backedges are weighted and thus their bodies have a greater frequency. 10 ; CHECK: body = 31744 11 body: 12 %iv = phi i32 [ 0, %entry ], [ %next, %body ] 13 %base = phi i32 [ 0, %entry ], [ %sum, %body ] 14 %arrayidx = getelementptr inbounds i32* %a, i32 %iv 15 %0 = load i32* %arrayidx 16 %sum = add nsw i32 %0, %base 17 %next = add i32 %iv, 1 18 %exitcond = icmp eq i32 %next, %i 19 br i1 %exitcond, label %exit, label %body 20 21 ; CHECK: exit = 1024 22 exit: 23 ret i32 %sum 24 } 25 26 define i32 @test2(i32 %i, i32 %a, i32 %b) { 27 ; CHECK: Printing analysis {{.*}} for function 'test2' 28 ; CHECK: entry = 1024 29 entry: 30 %cond = icmp ult i32 %i, 42 31 br i1 %cond, label %then, label %else, !prof !0 32 33 ; The 'then' branch is predicted more likely via branch weight metadata. 34 ; CHECK: then = 963 35 then: 36 br label %exit 37 38 ; CHECK: else = 60 39 else: 40 br label %exit 41 42 ; FIXME: It may be a bug that we don't sum back to 1024. 43 ; CHECK: exit = 1023 44 exit: 45 %result = phi i32 [ %a, %then ], [ %b, %else ] 46 ret i32 %result 47 } 48 49 !0 = metadata !{metadata !"branch_weights", i32 64, i32 4} 50 51 define i32 @test3(i32 %i, i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) { 52 ; CHECK: Printing analysis {{.*}} for function 'test3' 53 ; CHECK: entry = 1024 54 entry: 55 switch i32 %i, label %case_a [ i32 1, label %case_b 56 i32 2, label %case_c 57 i32 3, label %case_d 58 i32 4, label %case_e ], !prof !1 59 60 ; CHECK: case_a = 51 61 case_a: 62 br label %exit 63 64 ; CHECK: case_b = 51 65 case_b: 66 br label %exit 67 68 ; The 'case_c' branch is predicted more likely via branch weight metadata. 69 ; CHECK: case_c = 819 70 case_c: 71 br label %exit 72 73 ; CHECK: case_d = 51 74 case_d: 75 br label %exit 76 77 ; CHECK: case_e = 51 78 case_e: 79 br label %exit 80 81 ; FIXME: It may be a bug that we don't sum back to 1024. 82 ; CHECK: exit = 1023 83 exit: 84 %result = phi i32 [ %a, %case_a ], 85 [ %b, %case_b ], 86 [ %c, %case_c ], 87 [ %d, %case_d ], 88 [ %e, %case_e ] 89 ret i32 %result 90 } 91 92 !1 = metadata !{metadata !"branch_weights", i32 4, i32 4, i32 64, i32 4, i32 4} 93