https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112687

--- Comment #2 from Filip Kastl <fkastl at suse dot cz> ---
Created attachment 57222
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57222&action=edit
WIP patch to fix the missed optimization, version 0

I'm working on a patch. The problem (as Richard stated in pr112645) is that the
testcase gets optimized into

switch (v & 3) {
    default:
        return 0;
    case 1:
        return 1;
    case 2:
        return 2;
    case 3:
        return 3;
    }

so the information that there are only 4 possible values of the expression 'v &
3' is lost.

I add capability for switch conversion to recover from this. With my patch,
before processing the switch, switch conversion finds out if the default case
only corresponds to one possible value of the index expression. If so, it
creates a case for this value and marks default as unreachable.

With the patch applied, functions opt() and unopt() compile into the same
sequence of assembly instructions. I've attached the patch. Do you think this
is a good approach? I'll also appreciate any suggestions/comments for the
patch.

Reply via email to