blob: f043dc08e49f212c00455f5c7cfd6c60ac564ede [file] [log] [blame]
Chandler Carruth6aa5c262011-10-19 10:12:41 +00001; RUN: opt < %s -analyze -block-freq | FileCheck %s
2
3define i32 @test1(i32 %i, i32* %a) {
4; CHECK: Printing analysis {{.*}} for function 'test1'
5; CHECK: entry = 1024
6entry:
7 br label %body
8
9; Loop backedges are weighted and thus their bodies have a greater frequency.
10; CHECK: body = 31744
11body:
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
22exit:
23 ret i32 %sum
24}
Chandler Carruth99d01c52011-10-19 10:30:30 +000025
26define i32 @test2(i32 %i, i32 %a, i32 %b) {
27; CHECK: Printing analysis {{.*}} for function 'test2'
28; CHECK: entry = 1024
29entry:
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
35then:
36 br label %exit
37
38; CHECK: else = 60
39else:
40 br label %exit
41
42; FIXME: It may be a bug that we don't sum back to 1024.
43; CHECK: exit = 1023
44exit:
45 %result = phi i32 [ %a, %then ], [ %b, %else ]
46 ret i32 %result
47}
48
49!0 = metadata !{metadata !"branch_weights", i32 64, i32 4}