https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103278
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |marxin at gcc dot gnu.org --- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> --- So the main issue is that while CD-DCE tries to undo the factorization by running cleanup CFG, this process has the choice between two forwarder blocks to remove - one pre-existing to disambiguate the two edges from the last test into the PHI and the one we created. But CFG cleanup simply picks the first candidate which, in some cases is not the newly created one. That results in different handling of if-to-switch cluster processing. In particular the ->m_has_forward_bb handling seems important. If we do diff --git a/gcc/gimple-if-to-switch.cc b/gcc/gimple-if-to-switch.cc index 16fabef7ca0..157c5f6f10b 100644 --- a/gcc/gimple-if-to-switch.cc +++ b/gcc/gimple-if-to-switch.cc @@ -219,8 +219,7 @@ if_chain::is_beneficial () { simple_cluster *right = static_cast<simple_cluster *> (clusters[i]); tree type = TREE_TYPE (left->get_low ()); - if (!left->m_has_forward_bb - && !right->m_has_forward_bb + if (left->m_has_forward_bb == right->m_has_forward_bb && left->m_case_bb == right->m_case_bb) { if (wi::eq_p (wi::to_wide (right->get_low ()) - wi::to_wide which seems more natural then even with the original IL we don't get any if-to-switch as we seem to fail JT building because the number of clusters is then just 4 which is lower than case_values_threshold () which is 5. If we supply --param case-values-threshold=4 to the testcase it is optimized (that overrides the target default) with the result switch (aChar_10(D)) <default: <L7> [INV], case 9 ... 10: <L6> [INV], case 12: <L6> [INV], case 13: <L6> [INV], case 32: <L6> [INV], case 48: <L6> [INV]> <bb 3> : <L6>: <bb 4> : # iftmp.0_9 = PHI <1(3), 0(2)> <L7>: return iftmp.0_9; compared to the following before the CD-DCE change which looks clearly worse (but even the above has unmerged case 12 and 13?!) switch (aChar_10(D)) <default: <L10> [INV], case 9 ... 10: <L6> [INV], case 12: <L6> [INV], case 13: <L7> [INV], case 32: <L7> [INV], case 48: <L8> [INV]> <bb 3> : <L6>: goto <bb 6>; [100.00%] <bb 4> : <L7>: goto <bb 6>; [100.00%] <bb 5> : <L8>: <bb 6> : # iftmp.0_9 = PHI <1(4), 0(2), 1(3), 1(5)> <L10>: return iftmp.0_9; so this looks like a testcase issue to me.