[Bug tree-optimization/102738] Failure to optimize (signed) right shift if the range is already known to be [-1, 0]

pinskia at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Oct 14 01:55:08 GMT 2021


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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So this is interesting, I think clang/LLVM does this optimization late in their
pipeline take:
int a1(int f, int g)
{
    if (f == 0 || f == 1)
    return (f-1) >> g;
    return 0;
}
They don't remove the shift at all.  But if you change return 0 to
__builtin_unreachable(), they remove the shift.

Anyways we should be able to do this optimization even in the above case.

And even here where clang/LLVM misses too:
int a1(int f, int g)
{
    if (f == 6 || f == 7)
    return (f-7) >> g;
    __builtin_unreachable();
}


More information about the Gcc-bugs mailing list