2011-10-19 18:12:41 +08:00
|
|
|
; RUN: opt < %s -analyze -block-freq | FileCheck %s
|
|
|
|
|
|
|
|
define i32 @test1(i32 %i, i32* %a) {
|
|
|
|
; CHECK: Printing analysis {{.*}} for function 'test1'
|
2013-06-26 05:57:38 +08:00
|
|
|
; CHECK: entry = 1.0
|
2011-10-19 18:12:41 +08:00
|
|
|
entry:
|
|
|
|
br label %body
|
|
|
|
|
|
|
|
; Loop backedges are weighted and thus their bodies have a greater frequency.
|
2013-06-26 05:57:38 +08:00
|
|
|
; CHECK: body = 32.0
|
2011-10-19 18:12:41 +08:00
|
|
|
body:
|
|
|
|
%iv = phi i32 [ 0, %entry ], [ %next, %body ]
|
|
|
|
%base = phi i32 [ 0, %entry ], [ %sum, %body ]
|
|
|
|
%arrayidx = getelementptr inbounds i32* %a, i32 %iv
|
|
|
|
%0 = load i32* %arrayidx
|
|
|
|
%sum = add nsw i32 %0, %base
|
|
|
|
%next = add i32 %iv, 1
|
|
|
|
%exitcond = icmp eq i32 %next, %i
|
|
|
|
br i1 %exitcond, label %exit, label %body
|
|
|
|
|
2013-06-26 05:57:38 +08:00
|
|
|
; CHECK: exit = 1.0
|
2011-10-19 18:12:41 +08:00
|
|
|
exit:
|
|
|
|
ret i32 %sum
|
|
|
|
}
|
2011-10-19 18:30:30 +08:00
|
|
|
|
|
|
|
define i32 @test2(i32 %i, i32 %a, i32 %b) {
|
|
|
|
; CHECK: Printing analysis {{.*}} for function 'test2'
|
2013-06-26 05:57:38 +08:00
|
|
|
; CHECK: entry = 1.0
|
2011-10-19 18:30:30 +08:00
|
|
|
entry:
|
|
|
|
%cond = icmp ult i32 %i, 42
|
|
|
|
br i1 %cond, label %then, label %else, !prof !0
|
|
|
|
|
|
|
|
; The 'then' branch is predicted more likely via branch weight metadata.
|
2013-06-26 05:57:38 +08:00
|
|
|
; CHECK: then = 0.94116
|
2011-10-19 18:30:30 +08:00
|
|
|
then:
|
|
|
|
br label %exit
|
|
|
|
|
2013-06-26 05:57:38 +08:00
|
|
|
; CHECK: else = 0.05877
|
2011-10-19 18:30:30 +08:00
|
|
|
else:
|
|
|
|
br label %exit
|
|
|
|
|
2013-06-26 05:57:38 +08:00
|
|
|
; FIXME: It may be a bug that we don't sum back to 1.0.
|
|
|
|
; CHECK: exit = 0.99993
|
2011-10-19 18:30:30 +08:00
|
|
|
exit:
|
|
|
|
%result = phi i32 [ %a, %then ], [ %b, %else ]
|
|
|
|
ret i32 %result
|
|
|
|
}
|
|
|
|
|
|
|
|
!0 = metadata !{metadata !"branch_weights", i32 64, i32 4}
|
2011-10-19 18:32:19 +08:00
|
|
|
|
|
|
|
define i32 @test3(i32 %i, i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) {
|
|
|
|
; CHECK: Printing analysis {{.*}} for function 'test3'
|
2013-06-26 05:57:38 +08:00
|
|
|
; CHECK: entry = 1.0
|
2011-10-19 18:32:19 +08:00
|
|
|
entry:
|
|
|
|
switch i32 %i, label %case_a [ i32 1, label %case_b
|
|
|
|
i32 2, label %case_c
|
|
|
|
i32 3, label %case_d
|
|
|
|
i32 4, label %case_e ], !prof !1
|
|
|
|
|
2013-06-26 05:57:38 +08:00
|
|
|
; CHECK: case_a = 0.04998
|
2011-10-19 18:32:19 +08:00
|
|
|
case_a:
|
|
|
|
br label %exit
|
|
|
|
|
2013-06-26 05:57:38 +08:00
|
|
|
; CHECK: case_b = 0.04998
|
2011-10-19 18:32:19 +08:00
|
|
|
case_b:
|
|
|
|
br label %exit
|
|
|
|
|
|
|
|
; The 'case_c' branch is predicted more likely via branch weight metadata.
|
2013-06-26 05:57:38 +08:00
|
|
|
; CHECK: case_c = 0.79998
|
2011-10-19 18:32:19 +08:00
|
|
|
case_c:
|
|
|
|
br label %exit
|
|
|
|
|
2013-06-26 05:57:38 +08:00
|
|
|
; CHECK: case_d = 0.04998
|
2011-10-19 18:32:19 +08:00
|
|
|
case_d:
|
|
|
|
br label %exit
|
|
|
|
|
2013-06-26 05:57:38 +08:00
|
|
|
; CHECK: case_e = 0.04998
|
2011-10-19 18:32:19 +08:00
|
|
|
case_e:
|
|
|
|
br label %exit
|
|
|
|
|
2013-06-26 05:57:38 +08:00
|
|
|
; FIXME: It may be a bug that we don't sum back to 1.0.
|
|
|
|
; CHECK: exit = 0.99993
|
2011-10-19 18:32:19 +08:00
|
|
|
exit:
|
|
|
|
%result = phi i32 [ %a, %case_a ],
|
|
|
|
[ %b, %case_b ],
|
|
|
|
[ %c, %case_c ],
|
|
|
|
[ %d, %case_d ],
|
|
|
|
[ %e, %case_e ]
|
|
|
|
ret i32 %result
|
|
|
|
}
|
|
|
|
|
|
|
|
!1 = metadata !{metadata !"branch_weights", i32 4, i32 4, i32 64, i32 4, i32 4}
|