Chandler Carruth | 4162ece | 2011-10-21 08:01:56 +0000 | [diff] [blame] | 1 | ; RUN: llc -march=x86 -enable-block-placement < %s | FileCheck %s |
| 2 | |
| 3 | declare void @error(i32 %i, i32 %a, i32 %b) |
| 4 | |
Chandler Carruth | 4a85cc9 | 2011-10-21 08:57:37 +0000 | [diff] [blame] | 5 | define i32 @test_ifchains(i32 %i, i32* %a, i32 %b) { |
Chandler Carruth | 4162ece | 2011-10-21 08:01:56 +0000 | [diff] [blame] | 6 | ; Test a chain of ifs, where the block guarded by the if is error handling code |
| 7 | ; that is not expected to run. |
Chandler Carruth | 4a85cc9 | 2011-10-21 08:57:37 +0000 | [diff] [blame] | 8 | ; CHECK: test_ifchains: |
Chandler Carruth | 4162ece | 2011-10-21 08:01:56 +0000 | [diff] [blame] | 9 | ; 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 | |
| 21 | entry: |
| 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 | |
| 27 | then1: |
| 28 | call void @error(i32 %i, i32 1, i32 %b) |
| 29 | br label %else1 |
| 30 | |
| 31 | else1: |
| 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 | |
| 37 | then2: |
| 38 | call void @error(i32 %i, i32 1, i32 %b) |
| 39 | br label %else2 |
| 40 | |
| 41 | else2: |
| 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 | |
| 47 | then3: |
| 48 | call void @error(i32 %i, i32 1, i32 %b) |
| 49 | br label %else3 |
| 50 | |
| 51 | else3: |
| 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 | |
| 57 | then4: |
| 58 | call void @error(i32 %i, i32 1, i32 %b) |
| 59 | br label %else4 |
| 60 | |
| 61 | else4: |
| 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 | |
| 67 | then5: |
| 68 | call void @error(i32 %i, i32 1, i32 %b) |
| 69 | br label %exit |
| 70 | |
| 71 | exit: |
| 72 | ret i32 %b |
| 73 | } |
| 74 | |
| 75 | !0 = metadata !{metadata !"branch_weights", i32 4, i32 64} |
Chandler Carruth | 4a85cc9 | 2011-10-21 08:57:37 +0000 | [diff] [blame] | 76 | |
| 77 | define 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 Carruth | 7555c40 | 2011-10-21 16:41:39 +0000 | [diff] [blame^] | 82 | ; CHECK: .align [[ALIGN:[0-9]+]], |
Chandler Carruth | 4a85cc9 | 2011-10-21 08:57:37 +0000 | [diff] [blame] | 83 | ; CHECK-NEXT: %body |
| 84 | ; CHECK: %exit |
| 85 | |
| 86 | entry: |
| 87 | br label %body |
| 88 | |
| 89 | body: |
| 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 | |
| 99 | exit: |
| 100 | ret i32 %sum |
| 101 | } |
| 102 | |
| 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: |
| 106 | ; CHECK: %entry |
Chandler Carruth | 7555c40 | 2011-10-21 16:41:39 +0000 | [diff] [blame^] | 107 | ; CHECK: .align [[ALIGN]], |
Chandler Carruth | 4a85cc9 | 2011-10-21 08:57:37 +0000 | [diff] [blame] | 108 | ; CHECK-NEXT: %loop.body.1 |
Chandler Carruth | 7555c40 | 2011-10-21 16:41:39 +0000 | [diff] [blame^] | 109 | ; CHECK: .align [[ALIGN]], |
Chandler Carruth | 4a85cc9 | 2011-10-21 08:57:37 +0000 | [diff] [blame] | 110 | ; CHECK-NEXT: %inner.loop.body |
| 111 | ; CHECK-NOT: .align |
| 112 | ; CHECK: %loop.body.2 |
| 113 | ; CHECK: %exit |
| 114 | |
| 115 | entry: |
| 116 | br label %loop.body.1 |
| 117 | |
| 118 | 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 |
| 123 | |
| 124 | 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 |
| 134 | |
| 135 | loop.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 | |
| 140 | exit: |
| 141 | ret i32 %sum |
| 142 | } |