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

--- Comment #4 from IonuČ› Nicula <nicula.iccc at gmail dot com> ---
Note that my actual usecase with this kind of transformation is slightly more
complex. Instead of having the lookup table filled with zeros (or any single
value), it's filled with arbitrary values that satisfy the subsequent bounds
check. Example:

    constexpr std::array<size_t, 256> TO_DATA_INDEX = {0, 1, 2, 3, 4};

In this case, the *value* of 'second_idx' is not derivable at compile-time, but
the *set of values* is. And since all possible values of 'second_idx' satisfy
the bounds check (or the predicate, more generally), then the bounds check can
be removed altogether.

I'm not familiar with the compiler terminology in Andrew Pinski's message, but
it sounded like their approach is aimed at this general case, not the one with
a single possible value. The former sounds like it would be way more useful,
because lookup tables filled with a single value are probably less common.

I'll also add that in this general case Clang fails to remove the unreachable
branch, too.

Reply via email to