blob: e2604c2cb6ef448c2a9fb6979f31cd6df6958f8d [file] [log] [blame]
Chandler Carruth4162ece2011-10-21 08:01:56 +00001; RUN: llc -march=x86 -enable-block-placement < %s | FileCheck %s
2
3declare void @error(i32 %i, i32 %a, i32 %b)
4
Chandler Carruth4a85cc92011-10-21 08:57:37 +00005define i32 @test_ifchains(i32 %i, i32* %a, i32 %b) {
Chandler Carruth4162ece2011-10-21 08:01:56 +00006; Test a chain of ifs, where the block guarded by the if is error handling code
7; that is not expected to run.
Chandler Carruth4a85cc92011-10-21 08:57:37 +00008; CHECK: test_ifchains:
Chandler Carruth4162ece2011-10-21 08:01:56 +00009; CHECK: %entry
10; CHECK: %else1
11; CHECK: %else2
12; CHECK: %else3
13; CHECK: %else4
14; CHECK: %exit
15; CHECK: %then1
16; CHECK: %then2
17; CHECK: %then3
18; CHECK: %then4
19; CHECK: %then5
20
21entry:
22 %gep1 = getelementptr i32* %a, i32 1
23 %val1 = load i32* %gep1
24 %cond1 = icmp ugt i32 %val1, 1
25 br i1 %cond1, label %then1, label %else1, !prof !0
26
27then1:
28 call void @error(i32 %i, i32 1, i32 %b)
29 br label %else1
30
31else1:
32 %gep2 = getelementptr i32* %a, i32 2
33 %val2 = load i32* %gep2
34 %cond2 = icmp ugt i32 %val2, 2
35 br i1 %cond2, label %then2, label %else2, !prof !0
36
37then2:
38 call void @error(i32 %i, i32 1, i32 %b)
39 br label %else2
40
41else2:
42 %gep3 = getelementptr i32* %a, i32 3
43 %val3 = load i32* %gep3
44 %cond3 = icmp ugt i32 %val3, 3
45 br i1 %cond3, label %then3, label %else3, !prof !0
46
47then3:
48 call void @error(i32 %i, i32 1, i32 %b)
49 br label %else3
50
51else3:
52 %gep4 = getelementptr i32* %a, i32 4
53 %val4 = load i32* %gep4
54 %cond4 = icmp ugt i32 %val4, 4
55 br i1 %cond4, label %then4, label %else4, !prof !0
56
57then4:
58 call void @error(i32 %i, i32 1, i32 %b)
59 br label %else4
60
61else4:
62 %gep5 = getelementptr i32* %a, i32 3
63 %val5 = load i32* %gep5
64 %cond5 = icmp ugt i32 %val5, 3
65 br i1 %cond5, label %then5, label %exit, !prof !0
66
67then5:
68 call void @error(i32 %i, i32 1, i32 %b)
69 br label %exit
70
71exit:
72 ret i32 %b
73}
74
75!0 = metadata !{metadata !"branch_weights", i32 4, i32 64}
Chandler Carruth4a85cc92011-10-21 08:57:37 +000076
77define i32 @test_loop_align(i32 %i, i32* %a) {
78; Check that we provide basic loop body alignment with the block placement
79; pass.
80; CHECK: test_loop_align:
81; CHECK: %entry
Chandler Carruth7555c402011-10-21 16:41:39 +000082; CHECK: .align [[ALIGN:[0-9]+]],
Chandler Carruth4a85cc92011-10-21 08:57:37 +000083; CHECK-NEXT: %body
84; CHECK: %exit
85
86entry:
87 br label %body
88
89body:
90 %iv = phi i32 [ 0, %entry ], [ %next, %body ]
91 %base = phi i32 [ 0, %entry ], [ %sum, %body ]
92 %arrayidx = getelementptr inbounds i32* %a, i32 %iv
93 %0 = load i32* %arrayidx
94 %sum = add nsw i32 %0, %base
95 %next = add i32 %iv, 1
96 %exitcond = icmp eq i32 %next, %i
97 br i1 %exitcond, label %exit, label %body
98
99exit:
100 ret i32 %sum
101}
102
103define i32 @test_nested_loop_align(i32 %i, i32* %a, i32* %b) {
104; Check that we provide nested loop body alignment.
105; CHECK: test_nested_loop_align:
106; CHECK: %entry
Chandler Carruth7555c402011-10-21 16:41:39 +0000107; CHECK: .align [[ALIGN]],
Chandler Carruth4a85cc92011-10-21 08:57:37 +0000108; CHECK-NEXT: %loop.body.1
Chandler Carruth7555c402011-10-21 16:41:39 +0000109; CHECK: .align [[ALIGN]],
Chandler Carruth4a85cc92011-10-21 08:57:37 +0000110; CHECK-NEXT: %inner.loop.body
111; CHECK-NOT: .align
112; CHECK: %loop.body.2
113; CHECK: %exit
114
115entry:
116 br label %loop.body.1
117
118loop.body.1:
119 %iv = phi i32 [ 0, %entry ], [ %next, %loop.body.2 ]
120 %arrayidx = getelementptr inbounds i32* %a, i32 %iv
121 %bidx = load i32* %arrayidx
122 br label %inner.loop.body
123
124inner.loop.body:
125 %inner.iv = phi i32 [ 0, %loop.body.1 ], [ %inner.next, %inner.loop.body ]
126 %base = phi i32 [ 0, %loop.body.1 ], [ %sum, %inner.loop.body ]
127 %scaled_idx = mul i32 %bidx, %iv
128 %inner.arrayidx = getelementptr inbounds i32* %b, i32 %scaled_idx
129 %0 = load i32* %inner.arrayidx
130 %sum = add nsw i32 %0, %base
131 %inner.next = add i32 %iv, 1
132 %inner.exitcond = icmp eq i32 %inner.next, %i
133 br i1 %inner.exitcond, label %loop.body.2, label %inner.loop.body
134
135loop.body.2:
136 %next = add i32 %iv, 1
137 %exitcond = icmp eq i32 %next, %i
138 br i1 %exitcond, label %exit, label %loop.body.1
139
140exit:
141 ret i32 %sum
142}