On Thu, Nov 19, 2026 at 9:22 AM Richard Biener wrote: > If a thread through a latch is profitable (single or multiple latch) > but we don't > thread that case we should fix up the heuristics in the threader, not make > it run into the above bug again by re-introducing multiple latches.
Thanks, agreed. I withdraw the patch. My description attributed the slowdown to ethread, and that was wrong. Trunk with the PR128102 series still shows the difference (17787675 instructions, against 16340772 with the patch), but threading is not the cause: the late threaders end with the same CFG either way. Nor is inlining: the whole difference is inside exec86.constprop.0. It comes from lim2 on the prefix loop. With trunk's guessed profile each prefix case is hotter than the preheader (136518602 vs 118111604), so useseg, segoverride and reptype get store motion and segregs[0] and segregs[2] are hoisted; the extra register pressure costs five spills per emulated instruction. With the patch the cases come out colder than the preheader by 8 (153391688 vs 153391696), and LIM leaves them alone. So the gain was an accident of the profile estimate, which predicts each prefix case at 14%. Without profile feedback that guess is reasonable, so I am not changing it. The spilled values are loads whose memory still holds them at every use, but update_equiv_regs records a load equivalence only for a pseudo local to one block, and LRA drops an equivalence whose address uses a pseudo if the equivalenced pseudo is referenced in more than one block. I would rather fix it there than in the profile or LIM: record an equivalence for a load used in several blocks if the load is available at every use (a forward problem in IRA, killed by aliasing stores, calls and defs of the address registers), and keep it in LRA only if the address pseudos are live at every reference. With that and your CCP change kept, the emulator runs 16328659 instructions, against 16340772 with your change reverted and without it. It is about 600 lines without tests and will be posted separately, as a series. Vladimir, does that direction look acceptable for IRA/LRA? Richard Biener wrote: > Oh, and a better way would be to detect threadings through a latch _edge_ > (which is trivially identifiable by ->dest being a loop header). Andrea, in case you were trying this too: I tried it, treating an edge from inside the loop to its header as a latch crossing, in push_bb and in cancel_invalid_paths. On trunk it changes nothing, because after CCP no loop reaches ethread with several latches: none in gcc.c-torture and sqlite3.c at -O2 for arm. They only appear with -fno-tree-ccp, and on the PR testcase even then ethread does the same.
