[llvm] 75c3c6a - [CSKY] Optimize 'llvm.cttz.i32' and 'llvm.ctlz.i32'

Ben Shi via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 1 03:15:29 PDT 2023


Author: Ben Shi
Date: 2023-08-01T18:15:20+08:00
New Revision: 75c3c6ac15f520bde7353383117292ac3d0e1cc2

URL: https://github.com/llvm/llvm-project/commit/75c3c6ac15f520bde7353383117292ac3d0e1cc2
DIFF: https://github.com/llvm/llvm-project/commit/75c3c6ac15f520bde7353383117292ac3d0e1cc2.diff

LOG: [CSKY] Optimize 'llvm.cttz.i32' and 'llvm.ctlz.i32'

Reviewed By: zixuan-wu

Differential Revision: https://reviews.llvm.org/D156780

Added: 
    

Modified: 
    llvm/lib/Target/CSKY/CSKYISelLowering.cpp
    llvm/lib/Target/CSKY/CSKYISelLowering.h
    llvm/test/CodeGen/CSKY/intrinsic.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/CSKY/CSKYISelLowering.cpp b/llvm/lib/Target/CSKY/CSKYISelLowering.cpp
index d10d7ccb0bb6a7..ff48174228f172 100644
--- a/llvm/lib/Target/CSKY/CSKYISelLowering.cpp
+++ b/llvm/lib/Target/CSKY/CSKYISelLowering.cpp
@@ -1401,3 +1401,11 @@ bool CSKYTargetLowering::decomposeMulByConstant(LLVMContext &Context, EVT VT,
 
   return false;
 }
+
+bool CSKYTargetLowering::isCheapToSpeculateCttz(Type *Ty) const {
+  return Subtarget.has2E3();
+}
+
+bool CSKYTargetLowering::isCheapToSpeculateCtlz(Type *Ty) const {
+  return Subtarget.hasE2();
+}

diff  --git a/llvm/lib/Target/CSKY/CSKYISelLowering.h b/llvm/lib/Target/CSKY/CSKYISelLowering.h
index c724882c6042fd..d59481af3c5ba9 100644
--- a/llvm/lib/Target/CSKY/CSKYISelLowering.h
+++ b/llvm/lib/Target/CSKY/CSKYISelLowering.h
@@ -176,6 +176,8 @@ class CSKYTargetLowering : public TargetLowering {
 
   bool decomposeMulByConstant(LLVMContext &Context, EVT VT,
                               SDValue C) const override;
+  bool isCheapToSpeculateCttz(Type *Ty) const override;
+  bool isCheapToSpeculateCtlz(Type *Ty) const override;
 };
 
 } // namespace llvm

diff  --git a/llvm/test/CodeGen/CSKY/intrinsic.ll b/llvm/test/CodeGen/CSKY/intrinsic.ll
index a21c81714db5bf..24182f0b50e10f 100644
--- a/llvm/test/CodeGen/CSKY/intrinsic.ll
+++ b/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 @@ entry:
 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


        


More information about the llvm-commits mailing list