[llvm] [SelectionDAG] Use 31 ^ ctlz(x & -x) for CTTZ_ZERO_POISON when ctpop is not available (PR #220415)

Chris Copeland via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 1 19:50:00 PDT 2026


================
@@ -519,37 +507,33 @@ define i64 @test_cttz_i64(i64 %a) nounwind {
 ; RV32XTHEADBB-NEXT:  # %bb.1: # %cond.false
 ; RV32XTHEADBB-NEXT:    bnez a0, .LBB3_4
 ; RV32XTHEADBB-NEXT:  # %bb.2: # %cond.false
-; RV32XTHEADBB-NEXT:    addi a0, a1, -1
-; RV32XTHEADBB-NEXT:    not a1, a1
+; RV32XTHEADBB-NEXT:    neg a0, a1
 ; RV32XTHEADBB-NEXT:    and a0, a1, a0
 ; RV32XTHEADBB-NEXT:    th.ff1 a0, a0
-; RV32XTHEADBB-NEXT:    li a1, 64
-; RV32XTHEADBB-NEXT:    j .LBB3_5
+; RV32XTHEADBB-NEXT:    xori a0, a0, 31
----------------
chrisnc wrote:

This is one spot where I would have expected the xori and addi to be combined, but the overall sequence is improved regardless.

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


More information about the llvm-commits mailing list