Commit 84dbb9f
authored
Cranelift: fix
* Cranelift: fix `uadd_overflow` + load sinking.
In #14271 we got a fuzzbug that had a `uadd_overflow` with (i) a
sinkable load as one argument, (ii) multiple uses of the flag output,
so its flag result would have to be materialized anyway.
This results in the lowering happening twice: once to feed the flags
into the branch, and once to actually materialize the bool
value. That's fine: the whole point of the new mechanism is that the
common case is to use the overflow as a branch input only, not as a
materialized bool, so a double lowering here is harmless (two extra
cycles).
The issue arises because of a bit of logic I had forgotten we added
several years ago in #9510 that declares *all* multi-def instructions
as "value roots" that will only be lowered *once*. This allows loads
to sink into such instructions always (if only used once by that
instruction of course), but in turn requires a promise that we will do
what we say on the tin: we will only *ever* lower any multi-def
instruction once.
I believe that this eliminates any practical way of optimizing
overflow-flag insts, or doing fusion of bool flags into conditional
branches at all, because these inherently require lowering at use
sites (because of the way that we don't regalloc flags).
It is also a somewhat dangerous (IMHO, now with perspective) exception
to our otherwise principled "multiplicity" analysis: we otherwise
assume (i) that any given instruction is only lowered once,
unless (ii) truly used multiple times in the DFG. That is what allows
us to reason about code motion of loads in a princpled way (because we
can't duplicate a load). That principle is pretty simple; declaring
some instructions "roots" and allowing them to "kill" multiplicity
adds this footgun that will strike whenever we forget the exception
and write a lowering rule like the overflow cases.
Fortunately it seems we don't actually get any test failures when
removing that feature (and the test from #9510 is still in-tree?), so
it's not required anymore; so this PR removes the feature. The
attached test will panic without the fix.
Fixes #14271.
(Some more philosophical thought: our pre-pass that computes
multiplicity is itself a choice, but the alternative requires us to
give up single-pass lowering altogether and forces code motion into an
iterative/fixpoint kind of framework. Consider: we have multiple uses
of a given load; when we see the first use, how do we know whether
it's the only use (and we can sink it into here) or there will be
another? The multiplicity analysis is what answers that ahead of time,
and despite its main limitation (it cannot be updated live), it seems
to work well overall if we stick to the framework.)
* Delete now-outdated unit test that was testing the deleted logic.uadd_overflow + load sinking. (#14272)1 parent 3c767c0 commit 84dbb9f
2 files changed
Lines changed: 58 additions & 56 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1422 | 1422 | | |
1423 | 1423 | | |
1424 | 1424 | | |
1425 | | - | |
1426 | | - | |
1427 | | - | |
1428 | | - | |
1429 | | - | |
| 1425 | + | |
1430 | 1426 | | |
1431 | 1427 | | |
1432 | 1428 | | |
| |||
1486 | 1482 | | |
1487 | 1483 | | |
1488 | 1484 | | |
1489 | | - | |
1490 | | - | |
1491 | | - | |
1492 | | - | |
1493 | | - | |
1494 | | - | |
1495 | | - | |
1496 | | - | |
1497 | | - | |
1498 | | - | |
1499 | | - | |
1500 | | - | |
1501 | | - | |
1502 | | - | |
1503 | | - | |
1504 | | - | |
1505 | | - | |
1506 | | - | |
1507 | | - | |
1508 | | - | |
1509 | 1485 | | |
1510 | 1486 | | |
1511 | 1487 | | |
| |||
1710 | 1686 | | |
1711 | 1687 | | |
1712 | 1688 | | |
1713 | | - | |
1714 | | - | |
1715 | | - | |
1716 | | - | |
1717 | | - | |
1718 | | - | |
1719 | | - | |
1720 | | - | |
1721 | | - | |
1722 | | - | |
| 1689 | + | |
1723 | 1690 | | |
1724 | 1691 | | |
1725 | 1692 | | |
| |||
1870 | 1837 | | |
1871 | 1838 | | |
1872 | 1839 | | |
1873 | | - | |
1874 | | - | |
1875 | | - | |
1876 | | - | |
1877 | | - | |
1878 | | - | |
1879 | | - | |
1880 | | - | |
1881 | | - | |
1882 | | - | |
1883 | | - | |
1884 | | - | |
1885 | | - | |
1886 | | - | |
1887 | | - | |
1888 | | - | |
1889 | | - | |
1890 | | - | |
1891 | | - | |
1892 | | - | |
1893 | | - | |
1894 | 1840 | | |
Lines changed: 56 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
322 | 322 | | |
323 | 323 | | |
324 | 324 | | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
0 commit comments