[PATCH] D156780: [CSKY] Optimize 'llvm.cttz.i32' and 'llvm.ctlz.i32'
Ben Shi via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 1 02:05:30 PDT 2023
benshi001 created this revision.
benshi001 added a reviewer: zixuan-wu.
Herald added a subscriber: hiraditya.
Herald added a project: All.
benshi001 requested review of this revision.
Herald added subscribers: llvm-commits, jacquesguan.
Herald added a project: LLVM.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D156780
Files:
llvm/lib/Target/CSKY/CSKYISelLowering.cpp
llvm/lib/Target/CSKY/CSKYISelLowering.h
llvm/test/CodeGen/CSKY/intrinsic.ll
Index: llvm/test/CodeGen/CSKY/intrinsic.ll
===================================================================
--- llvm/test/CodeGen/CSKY/intrinsic.ll
+++ llvm/test/CodeGen/CSKY/intrinsic.ll
@@ -4,13 +4,8 @@
define i32 @ctlz_0(i32 %x) {
; CHECK-LABEL: ctlz_0:
; CHECK: # %bb.0: # %entry
-; CHECK-NEXT: bez32 a0, .LBB0_2
-; CHECK-NEXT: # %bb.1: # %cond.false
; CHECK-NEXT: ff1.32 a0, a0
; CHECK-NEXT: rts16
-; CHECK-NEXT: .LBB0_2:
-; CHECK-NEXT: movi16 a0, 32
-; CHECK-NEXT: rts16
entry:
%nlz = call i32 @llvm.ctlz.i32(i32 %x, i1 0)
ret i32 %nlz
@@ -29,14 +24,9 @@
define i32 @cttz_0(i32 %x) {
; CHECK-LABEL: cttz_0:
; CHECK: # %bb.0: # %entry
-; CHECK-NEXT: bez32 a0, .LBB2_2
-; CHECK-NEXT: # %bb.1: # %cond.false
; CHECK-NEXT: brev32 a0, a0
; CHECK-NEXT: ff1.32 a0, a0
; CHECK-NEXT: rts16
-; CHECK-NEXT: .LBB2_2:
-; CHECK-NEXT: movi16 a0, 32
-; CHECK-NEXT: rts16
entry:
%ntz = call i32 @llvm.cttz.i32(i32 %x, i1 0)
ret i32 %ntz
Index: llvm/lib/Target/CSKY/CSKYISelLowering.h
===================================================================
--- llvm/lib/Target/CSKY/CSKYISelLowering.h
+++ llvm/lib/Target/CSKY/CSKYISelLowering.h
@@ -176,6 +176,8 @@
bool decomposeMulByConstant(LLVMContext &Context, EVT VT,
SDValue C) const override;
+ bool isCheapToSpeculateCttz(Type *Ty) const override;
+ bool isCheapToSpeculateCtlz(Type *Ty) const override;
};
} // namespace llvm
Index: llvm/lib/Target/CSKY/CSKYISelLowering.cpp
===================================================================
--- llvm/lib/Target/CSKY/CSKYISelLowering.cpp
+++ llvm/lib/Target/CSKY/CSKYISelLowering.cpp
@@ -1401,3 +1401,11 @@
return false;
}
+
+bool CSKYTargetLowering::isCheapToSpeculateCttz(Type *Ty) const {
+ return Ty->isIntegerTy(Subtarget.XLen) && Subtarget.has2E3();
+}
+
+bool CSKYTargetLowering::isCheapToSpeculateCtlz(Type *Ty) const {
+ return Ty->isIntegerTy(Subtarget.XLen) && Subtarget.hasE2();
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156780.545966.patch
Type: text/x-patch
Size: 2015 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230801/eb54c18b/attachment.bin>
More information about the llvm-commits
mailing list