Index: clang/test/CodeGen/CSKY/csky-builtins.c =================================================================== --- /dev/null +++ clang/test/CodeGen/CSKY/csky-builtins.c @@ -0,0 +1,67 @@ +// RUN: %clang_cc1 -triple csky -emit-llvm -o - %s | FileCheck %s + +unsigned char bitrev8(unsigned char data) { + // CHECK: define{{.*}} i8 @bitrev8 + // CHECK: i8 @llvm.bitreverse.i8(i8 + return __builtin_bitreverse8(data); +} + +unsigned short bitrev16(unsigned short data) { + // CHECK: define{{.*}} i16 @bitrev16 + // CHECK: i16 @llvm.bitreverse.i16(i16 + return __builtin_bitreverse16(data); +} + +unsigned long bitrev32(unsigned long data) { + // CHECK: define{{.*}} i32 @bitrev32 + // CHECK: i32 @llvm.bitreverse.i32(i32 + return __builtin_bitreverse32(data); +} + +unsigned long long bitrev64(unsigned long long data) { + // CHECK: define{{.*}} i64 @bitrev64 + // CHECK: i64 @llvm.bitreverse.i64(i64 + return __builtin_bitreverse64(data); +} + +unsigned char rotleft8(unsigned char x, unsigned char y) { + // CHECK: define{{.*}} i8 @rotleft8 + // CHECK: i8 @llvm.fshl.i8(i8 + return __builtin_rotateleft8(x, y); +} + +unsigned short rotleft16(unsigned short x, unsigned short y) { + // CHECK: define{{.*}} i16 @rotleft16 + // CHECK: i16 @llvm.fshl.i16(i16 + return __builtin_rotateleft16(x, y); +} + +unsigned long rotleft32(unsigned long x, unsigned long y) { + // CHECK: define{{.*}} i32 @rotleft32 + // CHECK: i32 @llvm.fshl.i32(i32 + return __builtin_rotateleft32(x, y); +} + +unsigned long long rotleft64(unsigned long long x, unsigned long long y) { + // CHECK: define{{.*}} i64 @rotleft64 + // CHECK: i64 @llvm.fshl.i64(i64 + return __builtin_rotateleft64(x, y); +} + +unsigned short byteswap16(unsigned short x) { + // CHECK: define{{.*}} i16 @byteswap16 + // CHECK: i16 @llvm.bswap.i16(i16 + return __builtin_bswap16(x); +} + +unsigned long byteswap32(unsigned long x) { + // CHECK: define{{.*}} i32 @byteswap32 + // CHECK: i32 @llvm.bswap.i32(i32 + return __builtin_bswap32(x); +} + +unsigned long long byteswap64(unsigned long long x) { + // CHECK: define{{.*}} i64 @byteswap64 + // CHECK: i64 @llvm.bswap.i64(i64 + return __builtin_bswap64(x); +} 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 @@ -21,6 +32,17 @@ ret i32 %revb32 } +define i16 @bswap16(i16 %x) { +; CHECK-LABEL: bswap16: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT: revb16 a0, a0 +; CHECK-NEXT: lsri16 a0, a0, 16 +; CHECK-NEXT: rts16 +entry: + %revb16 = call i16 @llvm.bswap.i16(i16 %x) + ret i16 %revb16 +} + define i32 @bitreverse(i32 %x) { ; CHECK-LABEL: bitreverse: ; CHECK: # %bb.0: # %entry @@ -32,5 +54,7 @@ } declare i32 @llvm.bswap.i32(i32) +declare i16 @llvm.bswap.i16(i16) declare i32 @llvm.ctlz.i32 (i32, i1) +declare i32 @llvm.cttz.i32 (i32, i1) declare i32 @llvm.bitreverse.i32(i32)