https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124895
--- Comment #2 from Soumya AR <soumyaa at gcc dot gnu.org> --- The main issue here is that this pass runs after pass_free_cfg in an effort to run it as late as possible. But pass_free_cfg nulls the per-insn BLOCK_FOR_INSN pointer. RTL-SSA and DF rely on those to maintain bookkeeping when insns are modified, so the pass shouldn't be using them in this region. The correct fix would be to move this pass above pass_free_cfg. But that would require wider testing. Maybe we can push that to trunk and backport to GCC16.2 after the testing on trunk? Detailed analysis below: ----- For this particular test, -fpath-coverage and -fprofile-generate together produce a redundant AND instruction. At some point we have a PHI node whose result feeds an AND with 0x78. The PHI's inputs are 0x18 and 0x60, so when nonzero_bits ORs the masks of the PHI inputs we get exactly 0x78, making the AND redundant. This redundant operation would have ideally been folded by CCP in the middle-end, except -fno-tree-ccp makes it survive to late RTL. This later gets simplified to a set x0 x0 and marked as a noop. In the dtor, crtl->ssa->perform_pending_updates() walks the queue and calls ::delete_insn(rtl) for each queued noop. This calls df_insn_delete(insn), which tries to find the insn's BB via BLOCK_FOR_INSN(insn). But bb = BLOCK_FOR_INSN(insn) = NULL here since this runs after pass_free_cfg. With bb == NULL, df_insn_delete skips df_set_bb_dirty(bb) (it has a NULL-bb guard) but still runs df_insn_info_delete(uid) unconditionally. This bb's cached def bitmap is now stale, but the bb is not in df_lr->out_of_date_transfer_functions (set by df_set_bb_dirty), so DF still considers it clean. df_lr_verify_transfer_functions audits every BB not on the dirty list. It recomputes a new bitmap from the current insns and compares with its cached bitmap, skipping the dirty function bits. But since our modified BB was never set to dirty, bitmap_equal_p fails and causes the ICE. ----- There is another latent bug which this ICE exposes: for non-noop narrowings, the same BLOCK_FOR_INSN == NULL makes df_insn_rescan bail. For the passes that run afterwards this is OK because the regnums in the stale refs still match the new PATTERN's regnums, but if any future pass queried something else (e.g. the mode) it would get the pre-narrowing answer. ----- We can also fix this ICE for 16.1, if necessary, by just skipping narrowings that could result in a noop. This would be a lot less invasive and can be used as a band-aid until the real fix is tested.
