This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/51513] Only partially optimizes away __builtin_unreachable switch default case
- From: "bergner at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 29 Apr 2015 02:25:41 +0000
- Subject: [Bug tree-optimization/51513] Only partially optimizes away __builtin_unreachable switch default case
- Auto-submitted: auto-generated
- References: <bug-51513-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51513
--- Comment #7 from Peter Bergner <bergner at gcc dot gnu.org> ---
(In reply to Emil L from comment #3)
> This optimization would be very interesting for interpreter implementators
> that use a switch statement to dispatch the next instruction, when they can
> guarantee that the default branch is never taken.
I have actually hit the same issue with some code from PHP, so you're not too
far off on your comment. A reduced test case from PHP looks like:
void
foo (unsigned char *ptr, unsigned int cond)
{
switch (cond)
{
case 0:
return;
case 1:
case 2:
case 3:
case 4:
case 6:
*ptr += 1;
return;
case 5:
*ptr += 2;
return;
default:
__builtin_unreachable ();
break;
}
}
In this case, the undeleted branch had a wild label that pointed to nowhere.