[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:10:46 PDT 2023


benshi001 updated this revision to Diff 545968.

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

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.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();
+}
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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156780.545968.patch
Type: text/x-patch
Size: 2016 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230801/4e128f71/attachment-0001.bin>


More information about the llvm-commits mailing list