[PATCH] D154588: [CSKY] Optimize implementation of intrinsic 'llvm.cttz.i32'
Ben Shi via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 28 07:31:46 PDT 2023
benshi001 updated this revision to Diff 545158.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D154588/new/
https://reviews.llvm.org/D154588
Files:
llvm/lib/Target/CSKY/CSKYISelLowering.cpp
llvm/lib/Target/CSKY/CSKYInstrInfo.td
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
@@ -11,6 +11,17 @@
ret i32 %nlz
}
+define i32 @cttz(i32 %x) {
+; CHECK-LABEL: cttz:
+; CHECK: # %bb.0: # %entry
+; CHECK-NEXT: brev32 a0, a0
+; CHECK-NEXT: ff1.32 a0, a0
+; CHECK-NEXT: rts16
+entry:
+ %ntz = call i32 @llvm.cttz.i32(i32 %x, i1 1)
+ ret i32 %ntz
+}
+
define i32 @bswap(i32 %x) {
; CHECK-LABEL: bswap:
; CHECK: # %bb.0: # %entry
@@ -33,4 +44,5 @@
declare i32 @llvm.bswap.i32(i32)
declare i32 @llvm.ctlz.i32 (i32, i1)
+declare i32 @llvm.cttz.i32 (i32, i1)
declare i32 @llvm.bitreverse.i32(i32)
Index: llvm/lib/Target/CSKY/CSKYInstrInfo.td
===================================================================
--- llvm/lib/Target/CSKY/CSKYInstrInfo.td
+++ llvm/lib/Target/CSKY/CSKYInstrInfo.td
@@ -1429,6 +1429,7 @@
let Predicates = [iHas2E3] in {
def : Pat<(bitreverse GPR:$rx), (BREV32 GPR:$rx)>;
def : Pat<(bswap GPR:$rx), (REVB32 GPR:$rx)>;
+ def : Pat<(i32 (cttz GPR:$rx)), (FF1 (BREV32 GPR:$rx))>;
}
def : Pat<(i32 (ctlz GPR:$rx)), (FF1 GPR:$rx)>;
}
Index: llvm/lib/Target/CSKY/CSKYISelLowering.cpp
===================================================================
--- llvm/lib/Target/CSKY/CSKYISelLowering.cpp
+++ llvm/lib/Target/CSKY/CSKYISelLowering.cpp
@@ -59,7 +59,6 @@
setOperationAction(ISD::UREM, MVT::i32, Expand);
setOperationAction(ISD::UDIVREM, MVT::i32, Expand);
setOperationAction(ISD::SDIVREM, MVT::i32, Expand);
- setOperationAction(ISD::CTTZ, MVT::i32, Expand);
setOperationAction(ISD::CTPOP, MVT::i32, Expand);
setOperationAction(ISD::ROTR, MVT::i32, Expand);
setOperationAction(ISD::SHL_PARTS, MVT::i32, Expand);
@@ -103,6 +102,7 @@
if (!Subtarget.has2E3()) {
setOperationAction(ISD::ABS, MVT::i32, Expand);
setOperationAction(ISD::BITREVERSE, MVT::i32, Expand);
+ setOperationAction(ISD::CTTZ, MVT::i32, Expand);
setOperationAction(ISD::SDIV, MVT::i32, Expand);
setOperationAction(ISD::UDIV, MVT::i32, Expand);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154588.545158.patch
Type: text/x-patch
Size: 2150 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230728/73f8ac67/attachment.bin>
More information about the cfe-commits
mailing list