1; RUN: llc < %s | FileCheck %s
2target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
3target triple = "thumbv7-unknown-linux-gnueabihf"
4
5%Target = type { %Target*, %List* }
6%List = type { i32, i32* }
7
8; The entry block should be the first block of the function.
9; CHECK-LABEL: foo
10; CHECK:       %entry
11; CHECK:       %for.body
12; CHECK:       %for.inc
13; CHECK:       %if.then
14; CHECK:       %for.cond.i
15; CHECK:       %for.body.i
16; CHECK:       %return
17
18define i1 @foo(%Target** %ha, i32 %he) !prof !39 {
19entry:
20  %TargetPtr = load %Target*, %Target** %ha, align 4
21  %cmp1 = icmp eq %Target* %TargetPtr, null
22  br i1 %cmp1, label %return, label %for.body, !prof !50
23
24for.body:
25  %TargetPhi = phi %Target* [ %NextPtr, %for.inc ], [ %TargetPtr, %entry ]
26  %ListAddr = getelementptr inbounds %Target, %Target* %TargetPhi, i32 0, i32 1
27  %ListPtr = load %List*, %List** %ListAddr, align 4
28  %cmp2 = icmp eq %List* %ListPtr, null
29  br i1 %cmp2, label %for.inc, label %if.then, !prof !59
30
31if.then:
32  %lenAddr = getelementptr inbounds %List, %List* %ListPtr, i32 0, i32 0
33  %len = load i32, i32* %lenAddr, align 4
34  %ptr = getelementptr inbounds %List, %List* %ListPtr, i32 0, i32 1
35  %ptr2 = load i32*, i32** %ptr, align 4
36  br label %for.cond.i
37
38for.cond.i:
39  %i = phi i32 [ %len, %if.then ], [ %index, %for.body.i ]
40  %index = add nsw i32 %i, -1
41  %cmp3 = icmp sgt i32 %i, 0
42  br i1 %cmp3, label %for.body.i, label %for.inc, !prof !75
43
44for.body.i:
45  %ptr3 = getelementptr inbounds i32, i32* %ptr2, i32 %index
46  %data = load i32, i32* %ptr3, align 4
47  %cmp4 = icmp eq i32 %data, %he
48  br i1 %cmp4, label %return, label %for.cond.i, !prof !79
49
50for.inc:
51  %NextAddr = getelementptr inbounds %Target, %Target* %TargetPhi, i32 0, i32 0
52  %NextPtr = load %Target*, %Target** %NextAddr, align 4
53  %cmp5 = icmp eq %Target* %NextPtr, null
54  br i1 %cmp5, label %return, label %for.body, !prof !50
55
56return:
57  %retval = phi i1 [ false, %entry ], [ true, %for.body.i ], [ false, %for.inc ]
58  ret i1 %retval
59}
60
61!39 = !{!"function_entry_count", i64 226}
62!50 = !{!"branch_weights", i32 451, i32 1}
63!59 = !{!"branch_weights", i32 1502, i32 1}
64!75 = !{!"branch_weights", i32 301, i32 1}
65!79 = !{!"branch_weights", i32 1, i32 301}
66