This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/51513] Only partially optimizes away __builtin_unreachable switch default case


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]