This is the mail archive of the gcc-patches@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]

Re: [PATCH] PR mid-end/17657: Truncate case ranges to index's type


Roger Sayle <roger@eyesopen.com> writes:

> Similar such optimization opportunies occur with things like:
>
>   switch (x & 5)
>   {
>   case 0:  foo(0);  break;
>   case 1:  foo(1);  break;
>   case 2:  foo(2);  break;  /* Unreachable */
>   default: break;
>   }
>
> or
>
>   switch (x | 1)
>   {
>   case 0: foo(0);  break;  /* Unreachable */
>   case 1: foo(1);  break;
>   case 2: foo(2);  break;  /* Unreachable */
>   default: break;
>   }
>
>
> I'd argue that the ability of the middle-end to eliminate the unreachable
> cases above is a valid optimization, and shouldn't result in a diagnostic.
> Not that the middle-end should ever generate warnings, but the code above
> is valid.

For what it's worth, I agree that the code above is valid, should not
produce a diagnostic, and that GCC should strip the unreachable cases.
(I can see deliberately writing such constructs in ifdef-free code,
counting on the compiler to strip the unreachable cases.)

stmt.c doesn't seem like the ideal place for this - unreachable code
stripping should happen as early as possible - but it'll do.

zw


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