Skip to content

Commit 675ecf6

Browse files
authored
[RISCV] Use default promotion for i32 CTLZ_ZERO_UNDEF on RV64 with XTHeadBb. (#157955)
If we don't need to worry about the input being zero, we can shift the input right by 32 and use TH_FF1.
1 parent 55bef46 commit 675ecf6

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,12 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
421421
(Subtarget.hasVendorXCVbitmanip() && !Subtarget.is64Bit())) {
422422
// We need the custom lowering to make sure that the resulting sequence
423423
// for the 32bit case is efficient on 64bit targets.
424-
if (Subtarget.is64Bit())
425-
setOperationAction({ISD::CTLZ, ISD::CTLZ_ZERO_UNDEF}, MVT::i32, Custom);
424+
if (Subtarget.is64Bit()) {
425+
setOperationAction(ISD::CTLZ, MVT::i32, Custom);
426+
// Use default promotion for XTHeadBb.
427+
if (Subtarget.hasStdExtZbb())
428+
setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i32, Custom);
429+
}
426430
} else {
427431
setOperationAction(ISD::CTLZ, XLenVT, Expand);
428432
}

llvm/test/CodeGen/RISCV/ctlz-cttz-ctpop.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,9 +2004,8 @@ define i32 @test_ctlz_i32_zero_undef(i32 %a) nounwind {
20042004
;
20052005
; RV64XTHEADBB-LABEL: test_ctlz_i32_zero_undef:
20062006
; RV64XTHEADBB: # %bb.0:
2007-
; RV64XTHEADBB-NEXT: not a0, a0
20082007
; RV64XTHEADBB-NEXT: slli a0, a0, 32
2009-
; RV64XTHEADBB-NEXT: th.ff0 a0, a0
2008+
; RV64XTHEADBB-NEXT: th.ff1 a0, a0
20102009
; RV64XTHEADBB-NEXT: ret
20112010
%tmp = call i32 @llvm.ctlz.i32(i32 %a, i1 true)
20122011
ret i32 %tmp

llvm/test/CodeGen/RISCV/rv64xtheadbb.ll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,9 @@ define signext i32 @findLastSet_i32(i32 signext %a) nounwind {
240240
;
241241
; RV64XTHEADBB-NOB-LABEL: findLastSet_i32:
242242
; RV64XTHEADBB-NOB: # %bb.0:
243-
; RV64XTHEADBB-NOB-NEXT: not a1, a0
243+
; RV64XTHEADBB-NOB-NEXT: slli a1, a0, 32
244244
; RV64XTHEADBB-NOB-NEXT: snez a0, a0
245-
; RV64XTHEADBB-NOB-NEXT: slli a1, a1, 32
246-
; RV64XTHEADBB-NOB-NEXT: th.ff0 a1, a1
245+
; RV64XTHEADBB-NOB-NEXT: th.ff1 a1, a1
247246
; RV64XTHEADBB-NOB-NEXT: xori a1, a1, 31
248247
; RV64XTHEADBB-NOB-NEXT: addi a0, a0, -1
249248
; RV64XTHEADBB-NOB-NEXT: or a0, a0, a1

0 commit comments

Comments
 (0)