[PATCH] D63004: [TargetLowering] Simplify (ctpop x) == 1

Dávid Bolvanský via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 7 10:43:24 PDT 2019


xbolva00 added a comment.

In D63004#1534334 <https://reviews.llvm.org/D63004#1534334>, @lebedev.ri wrote:

> In D63004#1534270 <https://reviews.llvm.org/D63004#1534270>, @xbolva00 wrote:
>
> > Or should we prefer  (x-1) < (x & -x) ? This seems like a much faster choice.
>
>
> I'm guessing lack of CTPOP also likely implies lack of BMI1? (`(x & x-1)` is a single `blsr` instruction)
>  While that second variant looks like it has simpler ir, the ask looks more complex in general, more arithmetic:
>  https://godbolt.org/z/iwIIKK


And yes, if I turn off vectorization in my example, x && (x & x-1) == 0 is fastest.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63004/new/

https://reviews.llvm.org/D63004





More information about the llvm-commits mailing list