Wouter van Oortmerssen | 8a9cb24 | 2018-08-27 15:45:51 +0000 | [diff] [blame] | 1 | ; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-block-placement -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s |
Dan Gohman | d7a2eea | 2016-03-09 02:01:14 +0000 | [diff] [blame] | 2 | |
| 3 | ; Test irreducible CFG handling. |
| 4 | |
| 5 | target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" |
Sam Clegg | a590800 | 2018-05-10 17:49:11 +0000 | [diff] [blame] | 6 | target triple = "wasm32-unknown-unknown" |
Dan Gohman | d7a2eea | 2016-03-09 02:01:14 +0000 | [diff] [blame] | 7 | |
| 8 | ; A simple loop with two entries. |
| 9 | |
| 10 | ; CHECK-LABEL: test0: |
Dan Gohman | f456290 | 2016-04-26 01:40:56 +0000 | [diff] [blame] | 11 | ; CHECK: f64.load |
Heejin Ahn | 777d01c | 2019-01-03 23:10:11 +0000 | [diff] [blame] | 12 | ; CHECK: i32.const $[[REG:[^,]+]]= |
Dan Gohman | f456290 | 2016-04-26 01:40:56 +0000 | [diff] [blame] | 13 | ; CHECK: br_table $[[REG]], |
Dan Gohman | d7a2eea | 2016-03-09 02:01:14 +0000 | [diff] [blame] | 14 | define void @test0(double* %arg, i32 %arg1, i32 %arg2, i32 %arg3) { |
| 15 | bb: |
| 16 | %tmp = icmp eq i32 %arg2, 0 |
| 17 | br i1 %tmp, label %bb6, label %bb3 |
| 18 | |
| 19 | bb3: |
| 20 | %tmp4 = getelementptr double, double* %arg, i32 %arg3 |
| 21 | %tmp5 = load double, double* %tmp4, align 4 |
| 22 | br label %bb13 |
| 23 | |
| 24 | bb6: |
| 25 | %tmp7 = phi i32 [ %tmp18, %bb13 ], [ 0, %bb ] |
| 26 | %tmp8 = icmp slt i32 %tmp7, %arg1 |
| 27 | br i1 %tmp8, label %bb9, label %bb19 |
| 28 | |
| 29 | bb9: |
| 30 | %tmp10 = getelementptr double, double* %arg, i32 %tmp7 |
| 31 | %tmp11 = load double, double* %tmp10, align 4 |
| 32 | %tmp12 = fmul double %tmp11, 2.300000e+00 |
| 33 | store double %tmp12, double* %tmp10, align 4 |
| 34 | br label %bb13 |
| 35 | |
| 36 | bb13: |
| 37 | %tmp14 = phi double [ %tmp5, %bb3 ], [ %tmp12, %bb9 ] |
| 38 | %tmp15 = phi i32 [ undef, %bb3 ], [ %tmp7, %bb9 ] |
| 39 | %tmp16 = getelementptr double, double* %arg, i32 %tmp15 |
| 40 | %tmp17 = fadd double %tmp14, 1.300000e+00 |
| 41 | store double %tmp17, double* %tmp16, align 4 |
| 42 | %tmp18 = add nsw i32 %tmp15, 1 |
| 43 | br label %bb6 |
| 44 | |
| 45 | bb19: |
| 46 | ret void |
| 47 | } |
| 48 | |
| 49 | ; A simple loop with two entries and an inner natural loop. |
| 50 | |
| 51 | ; CHECK-LABEL: test1: |
Dan Gohman | f456290 | 2016-04-26 01:40:56 +0000 | [diff] [blame] | 52 | ; CHECK: f64.load |
Heejin Ahn | 777d01c | 2019-01-03 23:10:11 +0000 | [diff] [blame] | 53 | ; CHECK: i32.const $[[REG:[^,]+]]= |
Dan Gohman | f456290 | 2016-04-26 01:40:56 +0000 | [diff] [blame] | 54 | ; CHECK: br_table $[[REG]], |
Dan Gohman | d7a2eea | 2016-03-09 02:01:14 +0000 | [diff] [blame] | 55 | define void @test1(double* %arg, i32 %arg1, i32 %arg2, i32 %arg3) { |
| 56 | bb: |
| 57 | %tmp = icmp eq i32 %arg2, 0 |
| 58 | br i1 %tmp, label %bb6, label %bb3 |
| 59 | |
| 60 | bb3: |
| 61 | %tmp4 = getelementptr double, double* %arg, i32 %arg3 |
| 62 | %tmp5 = load double, double* %tmp4, align 4 |
| 63 | br label %bb13 |
| 64 | |
| 65 | bb6: |
| 66 | %tmp7 = phi i32 [ %tmp18, %bb13 ], [ 0, %bb ] |
| 67 | %tmp8 = icmp slt i32 %tmp7, %arg1 |
| 68 | br i1 %tmp8, label %bb9, label %bb19 |
| 69 | |
| 70 | bb9: |
| 71 | %tmp10 = getelementptr double, double* %arg, i32 %tmp7 |
| 72 | %tmp11 = load double, double* %tmp10, align 4 |
| 73 | %tmp12 = fmul double %tmp11, 2.300000e+00 |
| 74 | store double %tmp12, double* %tmp10, align 4 |
| 75 | br label %bb10 |
| 76 | |
| 77 | bb10: |
| 78 | %p = phi i32 [ 0, %bb9 ], [ %pn, %bb10 ] |
| 79 | %pn = add i32 %p, 1 |
| 80 | %c = icmp slt i32 %pn, 256 |
| 81 | br i1 %c, label %bb10, label %bb13 |
| 82 | |
| 83 | bb13: |
| 84 | %tmp14 = phi double [ %tmp5, %bb3 ], [ %tmp12, %bb10 ] |
| 85 | %tmp15 = phi i32 [ undef, %bb3 ], [ %tmp7, %bb10 ] |
| 86 | %tmp16 = getelementptr double, double* %arg, i32 %tmp15 |
| 87 | %tmp17 = fadd double %tmp14, 1.300000e+00 |
| 88 | store double %tmp17, double* %tmp16, align 4 |
| 89 | %tmp18 = add nsw i32 %tmp15, 1 |
| 90 | br label %bb6 |
| 91 | |
| 92 | bb19: |
| 93 | ret void |
| 94 | } |
Heejin Ahn | 777d01c | 2019-01-03 23:10:11 +0000 | [diff] [blame] | 95 | |
| 96 | ; A simple loop 2 blocks that are both entries. |
| 97 | |
| 98 | ; CHECK-LABEL: test2: |
| 99 | ; CHECK: br_if |
| 100 | ; CHECK: i32.const $[[REG:[^,]+]]= |
| 101 | ; CHECK: br_table $[[REG]], |
| 102 | define internal i32 @test2(i32) noinline { |
| 103 | entry: |
| 104 | br label %A0 |
| 105 | |
| 106 | A0: |
| 107 | %a0a = tail call i32 @test2(i32 1) |
| 108 | %a0b = icmp eq i32 %a0a, 0 |
| 109 | br i1 %a0b, label %A1, label %A2 |
| 110 | |
| 111 | A1: |
| 112 | %a1a = tail call i32 @test2(i32 2) |
| 113 | %a1b = icmp eq i32 %a1a, 0 |
| 114 | br i1 %a1b, label %A1, label %A2 |
| 115 | |
| 116 | A2: |
| 117 | %a2a = tail call i32 @test2(i32 3) |
| 118 | %a2b = icmp eq i32 %a2a, 0 |
| 119 | br i1 %a2b, label %A1, label %A2 |
| 120 | } |
| 121 | |
| 122 | ; An interesting loop with inner loop and if-else structure too. |
| 123 | |
| 124 | ; CHECK-LABEL: test3: |
| 125 | ; CHECK: br_if |
| 126 | define void @test3(i32 %ws) { |
| 127 | entry: |
| 128 | %ws.addr = alloca i32, align 4 |
| 129 | store volatile i32 %ws, i32* %ws.addr, align 4 |
| 130 | %0 = load volatile i32, i32* %ws.addr, align 4 |
| 131 | %tobool = icmp ne i32 %0, 0 |
| 132 | br i1 %tobool, label %if.then, label %if.end |
| 133 | |
| 134 | if.then: ; preds = %entry |
| 135 | br label %wynn |
| 136 | |
| 137 | if.end: ; preds = %entry |
| 138 | %1 = load volatile i32, i32* %ws.addr, align 4 |
| 139 | %tobool1 = icmp ne i32 %1, 0 |
| 140 | br i1 %tobool1, label %if.end9, label %if.then2 |
| 141 | |
| 142 | if.then2: ; preds = %if.end |
| 143 | br label %for.cond |
| 144 | |
| 145 | for.cond: ; preds = %wynn, %if.then7, %if.then2 |
| 146 | %2 = load volatile i32, i32* %ws.addr, align 4 |
| 147 | %tobool3 = icmp ne i32 %2, 0 |
| 148 | br i1 %tobool3, label %if.then4, label %if.end5 |
| 149 | |
| 150 | if.then4: ; preds = %for.cond |
| 151 | br label %if.end5 |
| 152 | |
| 153 | if.end5: ; preds = %if.then4, %for.cond |
| 154 | %3 = load volatile i32, i32* %ws.addr, align 4 |
| 155 | %tobool6 = icmp ne i32 %3, 0 |
| 156 | br i1 %tobool6, label %if.then7, label %if.end8 |
| 157 | |
| 158 | if.then7: ; preds = %if.end5 |
| 159 | br label %for.cond |
| 160 | |
| 161 | if.end8: ; preds = %if.end5 |
| 162 | br label %wynn |
| 163 | |
| 164 | wynn: ; preds = %if.end8, %if.then |
| 165 | br label %for.cond |
| 166 | |
| 167 | if.end9: ; preds = %if.end |
| 168 | ret void |
| 169 | } |
| 170 | |
| 171 | ; Multi-level irreducibility, after reducing in the main scope we must then |
| 172 | ; reduce in the inner loop that we just created. |
| 173 | ; CHECK: br_table |
| 174 | ; CHECK: br_table |
| 175 | define void @pi_next() { |
| 176 | entry: |
| 177 | br i1 undef, label %sw.bb5, label %return |
| 178 | |
| 179 | sw.bb5: ; preds = %entry |
| 180 | br i1 undef, label %if.then.i49, label %if.else.i52 |
| 181 | |
| 182 | if.then.i49: ; preds = %sw.bb5 |
| 183 | br label %for.inc197.i |
| 184 | |
| 185 | if.else.i52: ; preds = %sw.bb5 |
| 186 | br label %for.cond57.i |
| 187 | |
| 188 | for.cond57.i: ; preds = %for.inc205.i, %if.else.i52 |
| 189 | store i32 0, i32* undef, align 4 |
| 190 | br label %for.cond65.i |
| 191 | |
| 192 | for.cond65.i: ; preds = %for.inc201.i, %for.cond57.i |
| 193 | br i1 undef, label %for.body70.i, label %for.inc205.i |
| 194 | |
| 195 | for.body70.i: ; preds = %for.cond65.i |
| 196 | br label %for.cond76.i |
| 197 | |
| 198 | for.cond76.i: ; preds = %for.inc197.i, %for.body70.i |
| 199 | %0 = phi i32 [ %inc199.i, %for.inc197.i ], [ 0, %for.body70.i ] |
| 200 | %cmp81.i = icmp slt i32 %0, 0 |
| 201 | br i1 %cmp81.i, label %for.body82.i, label %for.inc201.i |
| 202 | |
| 203 | for.body82.i: ; preds = %for.cond76.i |
| 204 | br label %for.inc197.i |
| 205 | |
| 206 | for.inc197.i: ; preds = %for.body82.i, %if.then.i49 |
| 207 | %inc199.i = add nsw i32 undef, 1 |
| 208 | br label %for.cond76.i |
| 209 | |
| 210 | for.inc201.i: ; preds = %for.cond76.i |
| 211 | br label %for.cond65.i |
| 212 | |
| 213 | for.inc205.i: ; preds = %for.cond65.i |
| 214 | br label %for.cond57.i |
| 215 | |
| 216 | return: ; preds = %entry |
| 217 | ret void |
| 218 | } |
| 219 | |