[Bug target/29776] result of ffs/clz/ctz/popcount/parity are already sign-extended

amonakov at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Dec 31 11:26:00 GMT 2019


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

Alexander Monakov <amonakov at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |amonakov at gcc dot gnu.org

--- Comment #23 from Alexander Monakov <amonakov at gcc dot gnu.org> ---
In libcpp, search_line_fast implementations suffer from this, and what is
worse, attempts to workaround it by explicitly requesting zero extension don't
work:

char *foo(char *p, int x)
{
  return p + (unsigned)__builtin_ctz(x);
}

The above code is deliberately asking for zero extension, and yet various
optimizations in GCC transform it back to costlier form with sign extension.

(FWIW, LLVM gets this right)


More information about the Gcc-bugs mailing list