| 1 |
-- Test cases for converting high-level IR to lower-level IR (lowering). |
| 2 |
|
| 3 |
[case testLowerIntEq] |
| 4 |
def f(x: int, y: int) -> int: |
| 5 |
if x == y: |
| 6 |
return 1 |
| 7 |
else: |
| 8 |
return 2 |
| 9 |
[out] |
| 10 |
def f(x, y): |
| 11 |
x, y :: int |
| 12 |
r0 :: native_int |
| 13 |
r1, r2, r3 :: bit |
| 14 |
L0: |
| 15 |
r0 = x & 1 |
| 16 |
r1 = r0 != 0 |
| 17 |
if r1 goto L1 else goto L2 :: bool |
| 18 |
L1: |
| 19 |
r2 = CPyTagged_IsEq_(x, y) |
| 20 |
if r2 goto L3 else goto L4 :: bool |
| 21 |
L2: |
| 22 |
r3 = x == y |
| 23 |
if r3 goto L3 else goto L4 :: bool |
| 24 |
L3: |
| 25 |
return 2 |
| 26 |
L4: |
| 27 |
return 4 |
| 28 |
|
| 29 |
[case testLowerIntNe] |
| 30 |
def f(x: int, y: int) -> int: |
| 31 |
if x != y: |
| 32 |
return 1 |
| 33 |
else: |
| 34 |
return 2 |
| 35 |
[out] |
| 36 |
def f(x, y): |
| 37 |
x, y :: int |
| 38 |
r0 :: native_int |
| 39 |
r1, r2, r3, r4 :: bit |
| 40 |
L0: |
| 41 |
r0 = x & 1 |
| 42 |
r1 = r0 != 0 |
| 43 |
if r1 goto L1 else goto L2 :: bool |
| 44 |
L1: |
| 45 |
r2 = CPyTagged_IsEq_(x, y) |
| 46 |
r3 = r2 ^ 1 |
| 47 |
if r3 goto L3 else goto L4 :: bool |
| 48 |
L2: |
| 49 |
r4 = x != y |
| 50 |
if r4 goto L3 else goto L4 :: bool |
| 51 |
L3: |
| 52 |
return 2 |
| 53 |
L4: |
| 54 |
return 4 |
| 55 |
|
| 56 |
[case testLowerIntEqWithConstant] |
| 57 |
def f(x: int, y: int) -> int: |
| 58 |
if x == 2: |
| 59 |
return 1 |
| 60 |
elif -1 == x: |
| 61 |
return 2 |
| 62 |
return 3 |
| 63 |
[out] |
| 64 |
def f(x, y): |
| 65 |
x, y :: int |
| 66 |
r0, r1 :: bit |
| 67 |
L0: |
| 68 |
r0 = x == 4 |
| 69 |
if r0 goto L1 else goto L2 :: bool |
| 70 |
L1: |
| 71 |
return 2 |
| 72 |
L2: |
| 73 |
r1 = -2 == x |
| 74 |
if r1 goto L3 else goto L4 :: bool |
| 75 |
L3: |
| 76 |
return 4 |
| 77 |
L4: |
| 78 |
return 6 |
| 79 |
|
| 80 |
[case testLowerIntNeWithConstant] |
| 81 |
def f(x: int, y: int) -> int: |
| 82 |
if x != 2: |
| 83 |
return 1 |
| 84 |
elif -1 != x: |
| 85 |
return 2 |
| 86 |
return 3 |
| 87 |
[out] |
| 88 |
def f(x, y): |
| 89 |
x, y :: int |
| 90 |
r0, r1 :: bit |
| 91 |
L0: |
| 92 |
r0 = x != 4 |
| 93 |
if r0 goto L1 else goto L2 :: bool |
| 94 |
L1: |
| 95 |
return 2 |
| 96 |
L2: |
| 97 |
r1 = -2 != x |
| 98 |
if r1 goto L3 else goto L4 :: bool |
| 99 |
L3: |
| 100 |
return 4 |
| 101 |
L4: |
| 102 |
return 6 |
| 103 |
|
| 104 |
[case testLowerIntEqValueContext] |
| 105 |
def f(x: int, y: int) -> bool: |
| 106 |
return x == y |
| 107 |
[out] |
| 108 |
def f(x, y): |
| 109 |
x, y :: int |
| 110 |
r0 :: native_int |
| 111 |
r1, r2 :: bit |
| 112 |
r3 :: bool |
| 113 |
r4 :: bit |
| 114 |
L0: |
| 115 |
r0 = x & 1 |
| 116 |
r1 = r0 != 0 |
| 117 |
if r1 goto L1 else goto L2 :: bool |
| 118 |
L1: |
| 119 |
r2 = CPyTagged_IsEq_(x, y) |
| 120 |
r3 = r2 |
| 121 |
goto L3 |
| 122 |
L2: |
| 123 |
r4 = x == y |
| 124 |
r3 = r4 |
| 125 |
L3: |
| 126 |
return r3 |
| 127 |
|
| 128 |
[case testLowerIntLt] |
| 129 |
def f(x: int, y: int) -> int: |
| 130 |
if x < y: |
| 131 |
return 1 |
| 132 |
else: |
| 133 |
return 2 |
| 134 |
[out] |
| 135 |
def f(x, y): |
| 136 |
x, y :: int |
| 137 |
r0 :: native_int |
| 138 |
r1 :: bit |
| 139 |
r2 :: native_int |
| 140 |
r3, r4, r5 :: bit |
| 141 |
L0: |
| 142 |
r0 = x & 1 |
| 143 |
r1 = r0 != 0 |
| 144 |
if r1 goto L2 else goto L1 :: bool |
| 145 |
L1: |
| 146 |
r2 = y & 1 |
| 147 |
r3 = r2 != 0 |
| 148 |
if r3 goto L2 else goto L3 :: bool |
| 149 |
L2: |
| 150 |
r4 = CPyTagged_IsLt_(x, y) |
| 151 |
if r4 goto L4 else goto L5 :: bool |
| 152 |
L3: |
| 153 |
r5 = x < y :: signed |
| 154 |
if r5 goto L4 else goto L5 :: bool |
| 155 |
L4: |
| 156 |
return 2 |
| 157 |
L5: |
| 158 |
return 4 |
| 159 |
|
| 160 |
[case testLowerIntLe] |
| 161 |
def f(x: int, y: int) -> int: |
| 162 |
if x <= y: |
| 163 |
return 1 |
| 164 |
else: |
| 165 |
return 2 |
| 166 |
[out] |
| 167 |
def f(x, y): |
| 168 |
x, y :: int |
| 169 |
r0 :: native_int |
| 170 |
r1 :: bit |
| 171 |
r2 :: native_int |
| 172 |
r3, r4, r5, r6 :: bit |
| 173 |
L0: |
| 174 |
r0 = x & 1 |
| 175 |
r1 = r0 != 0 |
| 176 |
if r1 goto L2 else goto L1 :: bool |
| 177 |
L1: |
| 178 |
r2 = y & 1 |
| 179 |
r3 = r2 != 0 |
| 180 |
if r3 goto L2 else goto L3 :: bool |
| 181 |
L2: |
| 182 |
r4 = CPyTagged_IsLt_(y, x) |
| 183 |
r5 = r4 ^ 1 |
| 184 |
if r5 goto L4 else goto L5 :: bool |
| 185 |
L3: |
| 186 |
r6 = x <= y :: signed |
| 187 |
if r6 goto L4 else goto L5 :: bool |
| 188 |
L4: |
| 189 |
return 2 |
| 190 |
L5: |
| 191 |
return 4 |
| 192 |
|
| 193 |
[case testLowerIntGt] |
| 194 |
def f(x: int, y: int) -> int: |
| 195 |
if x > y: |
| 196 |
return 1 |
| 197 |
else: |
| 198 |
return 2 |
| 199 |
[out] |
| 200 |
def f(x, y): |
| 201 |
x, y :: int |
| 202 |
r0 :: native_int |
| 203 |
r1 :: bit |
| 204 |
r2 :: native_int |
| 205 |
r3, r4, r5 :: bit |
| 206 |
L0: |
| 207 |
r0 = x & 1 |
| 208 |
r1 = r0 != 0 |
| 209 |
if r1 goto L2 else goto L1 :: bool |
| 210 |
L1: |
| 211 |
r2 = y & 1 |
| 212 |
r3 = r2 != 0 |
| 213 |
if r3 goto L2 else goto L3 :: bool |
| 214 |
L2: |
| 215 |
r4 = CPyTagged_IsLt_(y, x) |
| 216 |
if r4 goto L4 else goto L5 :: bool |
| 217 |
L3: |
| 218 |
r5 = x > y :: signed |
| 219 |
if r5 goto L4 else goto L5 :: bool |
| 220 |
L4: |
| 221 |
return 2 |
| 222 |
L5: |
| 223 |
return 4 |
| 224 |
|
| 225 |
[case testLowerIntGe] |
| 226 |
def f(x: int, y: int) -> int: |
| 227 |
if x >= y: |
| 228 |
return 1 |
| 229 |
else: |
| 230 |
return 2 |
| 231 |
[out] |
| 232 |
def f(x, y): |
| 233 |
x, y :: int |
| 234 |
r0 :: native_int |
| 235 |
r1 :: bit |
| 236 |
r2 :: native_int |
| 237 |
r3, r4, r5, r6 :: bit |
| 238 |
L0: |
| 239 |
r0 = x & 1 |
| 240 |
r1 = r0 != 0 |
| 241 |
if r1 goto L2 else goto L1 :: bool |
| 242 |
L1: |
| 243 |
r2 = y & 1 |
| 244 |
r3 = r2 != 0 |
| 245 |
if r3 goto L2 else goto L3 :: bool |
| 246 |
L2: |
| 247 |
r4 = CPyTagged_IsLt_(x, y) |
| 248 |
r5 = r4 ^ 1 |
| 249 |
if r5 goto L4 else goto L5 :: bool |
| 250 |
L3: |
| 251 |
r6 = x >= y :: signed |
| 252 |
if r6 goto L4 else goto L5 :: bool |
| 253 |
L4: |
| 254 |
return 2 |
| 255 |
L5: |
| 256 |
return 4 |
| 257 |
|
| 258 |
[case testLowerIntLtShort] |
| 259 |
def both() -> int: |
| 260 |
if 3 < 5: |
| 261 |
return 1 |
| 262 |
else: |
| 263 |
return 2 |
| 264 |
|
| 265 |
def rhs_only(x: int) -> int: |
| 266 |
if x < 5: |
| 267 |
return 1 |
| 268 |
else: |
| 269 |
return 2 |
| 270 |
|
| 271 |
def lhs_only(x: int) -> int: |
| 272 |
if 5 < x: |
| 273 |
return 1 |
| 274 |
else: |
| 275 |
return 2 |
| 276 |
[out] |
| 277 |
def both(): |
| 278 |
r0 :: bit |
| 279 |
L0: |
| 280 |
r0 = 6 < 10 :: signed |
| 281 |
if r0 goto L1 else goto L2 :: bool |
| 282 |
L1: |
| 283 |
return 2 |
| 284 |
L2: |
| 285 |
return 4 |
| 286 |
def rhs_only(x): |
| 287 |
x :: int |
| 288 |
r0 :: native_int |
| 289 |
r1 :: bit |
| 290 |
r2 :: native_int |
| 291 |
r3, r4, r5 :: bit |
| 292 |
L0: |
| 293 |
r0 = x & 1 |
| 294 |
r1 = r0 != 0 |
| 295 |
if r1 goto L2 else goto L1 :: bool |
| 296 |
L1: |
| 297 |
r2 = 10 & 1 |
| 298 |
r3 = r2 != 0 |
| 299 |
if r3 goto L2 else goto L3 :: bool |
| 300 |
L2: |
| 301 |
r4 = CPyTagged_IsLt_(x, 10) |
| 302 |
if r4 goto L4 else goto L5 :: bool |
| 303 |
L3: |
| 304 |
r5 = x < 10 :: signed |
| 305 |
if r5 goto L4 else goto L5 :: bool |
| 306 |
L4: |
| 307 |
return 2 |
| 308 |
L5: |
| 309 |
return 4 |
| 310 |
def lhs_only(x): |
| 311 |
x :: int |
| 312 |
r0 :: native_int |
| 313 |
r1 :: bit |
| 314 |
r2 :: native_int |
| 315 |
r3, r4, r5 :: bit |
| 316 |
L0: |
| 317 |
r0 = 10 & 1 |
| 318 |
r1 = r0 != 0 |
| 319 |
if r1 goto L2 else goto L1 :: bool |
| 320 |
L1: |
| 321 |
r2 = x & 1 |
| 322 |
r3 = r2 != 0 |
| 323 |
if r3 goto L2 else goto L3 :: bool |
| 324 |
L2: |
| 325 |
r4 = CPyTagged_IsLt_(10, x) |
| 326 |
if r4 goto L4 else goto L5 :: bool |
| 327 |
L3: |
| 328 |
r5 = 10 < x :: signed |
| 329 |
if r5 goto L4 else goto L5 :: bool |
| 330 |
L4: |
| 331 |
return 2 |
| 332 |
L5: |
| 333 |
return 4 |
| 334 |
|
| 335 |
[case testLowerIntForLoop_withgil_64bit] |
| 336 |
from __future__ import annotations |
| 337 |
|
| 338 |
def f(l: list[int]) -> None: |
| 339 |
for x in l: |
| 340 |
pass |
| 341 |
[out] |
| 342 |
def f(l): |
| 343 |
l :: list |
| 344 |
r0 :: native_int |
| 345 |
r1 :: ptr |
| 346 |
r2 :: native_int |
| 347 |
r3 :: bit |
| 348 |
r4, r5 :: ptr |
| 349 |
r6 :: native_int |
| 350 |
r7 :: ptr |
| 351 |
r8 :: object |
| 352 |
r9, x :: int |
| 353 |
r10 :: native_int |
| 354 |
r11 :: None |
| 355 |
L0: |
| 356 |
r0 = 0 |
| 357 |
L1: |
| 358 |
r1 = get_element_ptr l ob_size :: PyVarObject |
| 359 |
r2 = load_mem r1 :: native_int* |
| 360 |
r3 = r0 < r2 :: signed |
| 361 |
if r3 goto L2 else goto L5 :: bool |
| 362 |
L2: |
| 363 |
r4 = get_element_ptr l ob_item :: PyListObject |
| 364 |
r5 = load_mem r4 :: ptr* |
| 365 |
r6 = r0 * 8 |
| 366 |
r7 = r5 + r6 |
| 367 |
r8 = load_mem r7 :: builtins.object* |
| 368 |
r9 = unbox(int, r8) |
| 369 |
dec_ref r8 |
| 370 |
if is_error(r9) goto L6 (error at f:4) else goto L3 |
| 371 |
L3: |
| 372 |
x = r9 |
| 373 |
dec_ref x :: int |
| 374 |
L4: |
| 375 |
r10 = r0 + 1 |
| 376 |
r0 = r10 |
| 377 |
goto L1 |
| 378 |
L5: |
| 379 |
return 1 |
| 380 |
L6: |
| 381 |
r11 = <error> :: None |
| 382 |
return r11 |