Re: [middle-end PATCH] Improve bitreverse expansion on x86_64 and cris.

Uros Bizjak <[email protected]>
Newsgroups gmane.comp.gcc.patches
Message-ID <CAFULd4Z05MrExP-LvhCO=xv9uRebFpASW01qynvv35=C_bK06Q@mail.gmail.com>
On Sat, Aug 8, 2026 at 5:24 PM Roger Sayle <[email protected]> wrote:
>
>
> My recent patch to improve bitreverse support on cris, posted at
> https://gcc.gnu.org/pipermail/gcc-patches/2026-August/726384.html
> revealed an optimization opportunity.  If you look closely GCC's
> expansion of bitreverse (in optabs.cc) generates a left shift
> followed by an IOR in several places.  In these instances, its
> possible to use "any_or_plus", and in fact using PLUS would allow
> cris to use its addi instruction, and the x86 to use its lea
> instruction.  I believe PLUS is always as efficient as IOR for
> SImode/wordmode, even on processors that have to use add with carry,
> i.e. addc[qh]i3.  For other (longer) modes (such as vector modes),
> it's better to use IOR, and for shorter modes I'm not sure there's
> any advantage to using PLUS.  If I'm wrong for some targets, we
> can make aop_optab a real optab.

Please note PR108477 [1] where fwprop conversion from '+' to '|' can
interfere with your proposed optimization and the discussion about a
patch that would generate LEA some more, started from [2].

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108477
[2] https://gcc.gnu.org/pipermail/gcc-patches/2024-January/642164.html

Uros.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.