[Bug middle-end/78103] Failure to optimize with __builtin_clzl

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Jul 26 10:57:27 GMT 2021


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

--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 51204
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51204&action=edit
gcc12-pr78103.patch

Untested partial fix.
The patch does 2 things, one is (shown on the first testcase) optimize sign or
zero extension of __builtin_clz{,l,ll} from 32-bits to 64-bit - no need to emit
sign extension instruction.  The other change is to match 32-bit subtraction of
a constant and __builtin_clz, can be optimized into bsr and addition.
All this only with -mno-lzcnt, with -mlzcnt a very different insn is emitted
that handles it fine.


More information about the Gcc-bugs mailing list