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

--- Comment #3 from Jeremy R. <llvm at rifkin dot dev> ---
(In reply to Jakub Jelinek from comment #1)
> So maybe the switchconv pass could be
> improved not to do just the linear etc. expression handling, but also
> consider code sequences that are the same except for the linear expression
> somewhere in it and turn it back into use of a temporary.

I think this is how LLVM approaches it. It might be nice to be able to fold
switches where it's not a linear sequence too, such as:

void bar(int x) {
    switch(x) {
        case 1: func(x); break;
        case 4: func(x); break;
        case 7: func(x); break;
        case 3: func(x); break;
        case 9: func(x); break;
        default: __builtin_unreachable();
    }
}

LLVM is able to fold this out of a switch though it also struggles due to the
early constant propagation and doesn't fold this perfectly.

Reply via email to