[llvm] Optimize count leading ones if promoted type (PR #99591)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 25 04:29:26 PDT 2024


v01dXYZ wrote:

I added some tests for CGP for two different cases:

* X86: DAG legalisation is the one doing the promotion
* RISCV: type legalisation is the one doing the promotion.

There is still a remaining issue with X86 when LZCNT is not available as DAG legalisation is custom for i8. I tried to mark `addOperationPromotedToType(CTLZ, i8, i32)` but the code is still not optimal with a spurious `XOR 31`.

Note also that there is no optimisation for counting trailing ones here, only for counting leading ones, although CGP takes the two cases into account in this PR. Tell me if you think it is relevant to add it. 

https://github.com/llvm/llvm-project/pull/99591


More information about the llvm-commits mailing list