public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "amacleod at redhat dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/107443] New: Switch conversion removing code Date: Thu, 27 Oct 2022 18:52:09 +0000 [thread overview] Message-ID: <bug-107443-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107443 Bug ID: 107443 Summary: Switch conversion removing code Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: amacleod at redhat dot com Target Milestone: --- Compile the following with -O2 -fdump-tree-all -fdisable-tree-evrp void dead (unsigned n); void foo (unsigned n); void func (unsigned n) { if (n == 0) __builtin_unreachable(); if (n == 1) __builtin_unreachable(); if (n == 2) __builtin_unreachable(); if (n == 3) __builtin_unreachable(); if (n == 4) __builtin_unreachable(); if (n == 5) __builtin_unreachable(); if (n == 6) __builtin_unreachable(); if (n == 7) __builtin_unreachable(); foo (n); if (n < 8) dead (n); } iftoswitch converts the series of if's into a switch: <bb 2> : switch (n_2(D)) <default: <L26> [INV], case 0: <L18> [INV], case 1: <L19> [INV], case 2: <L20> [INV], case 3: <L21> [INV], case 4: <L22> [INV], case 5: <L23> [INV], case 6: <L24> [INV], case 7: <L25> [INV]> <bb 3> : <L18>: __builtin_unreachable (); <bb 4> : <L19>: __builtin_unreachable (); <bb 5> : <L20>: __builtin_unreachable (); <bb 6> : <L21>: __builtin_unreachable (); <bb 7> : <L22>: __builtin_unreachable (); <bb 8> : <L23>: __builtin_unreachable (); <bb 9> : <L24>: __builtin_unreachable (); <bb 10> : <L25>: __builtin_unreachable (); <bb 11> : <L26>: foo (n_2(D)); if (n_2(D) <= 7) goto <bb 12>; [INV] else goto <bb 13>; [INV] <bb 12> : dead (n_2(D)); switch conversion then runs, eliminates all the blocks, then bails on the conversion, leaving the IL without any of the __builtin_unreachable calls: Beginning to process the following SWITCH statement ((null):0) : ------- switch (n_2(D)) <default: <L26> [INV], case 0: <L18> [INV], case 1: <L19> [INV], case 2: <L20> [INV], case 3: <L21> [INV], case 4: <L22> [INV], case 5: <L23> [INV], case 6: <L24> [INV], case 7: <L25> [INV]> Removing basic block 3 Removing basic block 4 Removing basic block 5 Removing basic block 6 Removing basic block 7 Removing basic block 8 Removing basic block 9 Removing basic block 10 Bailing out - switch is a degenerate case -------------------------------- Merging blocks 2 and 11 void func (unsigned int n) { <bb 2> : foo (n_2(D)); if (n_2(D) <= 7) goto <bb 3>; [INV] else goto <bb 4>; [INV] <bb 3> : dead (n_2(D)); <bb 4> : return; } And now the optimizers cannot remove the call to dead() because we lose all the range information inferred from the __builtin_unreachable calls.
next reply other threads:[~2022-10-27 18:52 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-10-27 18:52 amacleod at redhat dot com [this message] 2022-10-27 23:34 ` [Bug middle-end/107443] [10/11/12/13 Regression] Removing switch with __builtin_unreachable causes missed optimizations pinskia at gcc dot gnu.org 2022-10-28 11:57 ` rguenth at gcc dot gnu.org 2023-03-24 8:42 ` rguenth at gcc dot gnu.org 2023-07-07 10:44 ` [Bug middle-end/107443] [11/12/13/14 " rguenth at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-107443-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).