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); } 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/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)