https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51840
--- Comment #6 from Kai Tietz <ktietz at gcc dot gnu.org> --- So this is a source of endless bugs ... and all are related to merging of basic-blocks. By the following patch the sample can be built successful on x64 targets. There seems to be another issue for x86 targets triggered in some cases. For 32-bit the factoring out of partial addresses to register leads to new basic-blocks placed before blocks actually jumped by table. Major issue happens in mergephi pass. For all of those problems is common that we happily operate on forced user-labels. Index: tree-cfgcleanup.c =================================================================== --- tree-cfgcleanup.c (Revision 212070) +++ tree-cfgcleanup.c (Arbeitskopie) @@ -285,12 +285,19 @@ tree_forwarder_block_p (basic_block bb, bool phi_w for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi); gsi_prev (&gsi)) { gimple stmt = gsi_stmt (gsi); + tree lbl; switch (gimple_code (stmt)) { case GIMPLE_LABEL: - if (DECL_NONLOCAL (gimple_label_label (stmt))) + lbl = gimple_label_label (stmt); + if (DECL_NONLOCAL (lbl)) return false; + /* If PHI_WANTED is true, we can't operate on user-labels. + See PR 51840. */ + if (phi_wanted + && !DECL_ARTIFICIAL (lbl) && FORCED_LABEL (lbl)) + return false; if (optimize == 0 && gimple_location (stmt) != locus) return false; break;