1 ; RUN: llc -march=x86 -enable-block-placement < %s | FileCheck %s
3 declare void @error(i32 %i, i32 %a, i32 %b)
5 define i32 @test_ifchains(i32 %i, i32* %a, i32 %b) {
6 ; Test a chain of ifs, where the block guarded by the if is error handling code
7 ; that is not expected to run.
8 ; CHECK: test_ifchains:
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
28 call void @error(i32 %i, i32 1, i32 %b)
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
38 call void @error(i32 %i, i32 1, i32 %b)
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
48 call void @error(i32 %i, i32 1, i32 %b)
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
58 call void @error(i32 %i, i32 1, i32 %b)
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
68 call void @error(i32 %i, i32 1, i32 %b)
75 !0 = metadata !{metadata !"branch_weights", i32 4, i32 64}
77 define i32 @test_loop_align(i32 %i, i32* %a) {
78 ; Check that we provide basic loop body alignment with the block placement
80 ; CHECK: test_loop_align:
82 ; CHECK: .align [[ALIGN:[0-9]+]],
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
103 define 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:
107 ; CHECK: .align [[ALIGN]],
108 ; CHECK-NEXT: %loop.body.1
109 ; CHECK: .align [[ALIGN]],
110 ; CHECK-NEXT: %inner.loop.body
112 ; CHECK: %loop.body.2
116 br label %loop.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
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
136 %next = add i32 %iv, 1
137 %exitcond = icmp eq i32 %next, %i
138 br i1 %exitcond, label %exit, label %loop.body.1