6687da29
by Andreas Klebinger at 2026-11-03T15:46:32+01:00
x86 ncg: Track the current block in NatM to keep the CFG in sync
The x86 NCG uses a CFG for code layout. When instruction selection
makes new blocks (word2Float#, cmpxchg loops, 64-bit shifts on i386),
it must add them to the CFG. Some sites did not. The CFG went out of
sync, the layout was bad, and the register allocator panicked when it
added fixup blocks (#27694, #27915).
NatM now keeps the current block in its state. Combinators update the
CFG and the current block together. See Note [Updating the CFG during
CodeGen] in GHC.CmmToAsm.Monad.
Other changes:
* -dasm-lint checks that the jumps in the code and the edges in the
CFG agree in both directions. This found a second desync: the CFG
did not follow the jumps that allocMoreStack retargets. The new
addPreentryBlock fixes it.
* A store emits the code of its address before the code of its value,
because the CFG records new blocks in generation order. Stores and
atomic operations take their address from the new
getNonClobberedAmode, so the value code cannot clobber it.
* backendMaintainsCfg is now True for i386: it gets the CFG based
layout, dead code elimination and the -dasm-lint check.
Fixes #27694, #27915
Co-authored-by: Sylvain Henry <sylvain@haskus.fr>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>