From 5615aca2199279b9358fc4d59dc8ecc143912dc9 Mon Sep 17 00:00:00 2001 From: Venkatraman Govindaraju Date: Sun, 3 Nov 2013 05:59:07 +0000 Subject: [PATCH] [SparcV9] Add ctpop instruction for i64. Also, expand ctlz, cttz and bswap. llvm-svn: 193941 --- llvm/lib/Target/Sparc/SparcISelLowering.cpp | 7 +++++++ llvm/lib/Target/Sparc/SparcInstr64Bit.td | 2 ++ llvm/test/CodeGen/SPARC/64bit.ll | 23 +++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/llvm/lib/Target/Sparc/SparcISelLowering.cpp b/llvm/lib/Target/Sparc/SparcISelLowering.cpp index d0156fa340d9..e09802b9ff97 100644 --- a/llvm/lib/Target/Sparc/SparcISelLowering.cpp +++ b/llvm/lib/Target/Sparc/SparcISelLowering.cpp @@ -1397,6 +1397,13 @@ SparcTargetLowering::SparcTargetLowering(TargetMachine &TM) setOperationAction(ISD::SETCC, MVT::i64, Expand); setOperationAction(ISD::BR_CC, MVT::i64, Custom); setOperationAction(ISD::SELECT_CC, MVT::i64, Custom); + + setOperationAction(ISD::CTPOP, MVT::i64, Legal); + setOperationAction(ISD::CTTZ , MVT::i64, Expand); + setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::i64, Expand); + setOperationAction(ISD::CTLZ , MVT::i64, Expand); + setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i64, Expand); + setOperationAction(ISD::BSWAP, MVT::i64, Expand); } // FIXME: There are instructions available for ATOMIC_FENCE diff --git a/llvm/lib/Target/Sparc/SparcInstr64Bit.td b/llvm/lib/Target/Sparc/SparcInstr64Bit.td index d44c18dd4226..cf8747d0900a 100644 --- a/llvm/lib/Target/Sparc/SparcInstr64Bit.td +++ b/llvm/lib/Target/Sparc/SparcInstr64Bit.td @@ -169,6 +169,8 @@ def : Pat<(sub i64:$a, (i64 simm13:$b)), (SUBri $a, (as_i32imm $b))>; def : Pat<(SPcmpicc i64:$a, (i64 simm13:$b)), (CMPri $a, (as_i32imm $b))>; +def : Pat<(ctpop i64:$src), (POPCrr $src)>; + } // Predicates = [Is64Bit] diff --git a/llvm/test/CodeGen/SPARC/64bit.ll b/llvm/test/CodeGen/SPARC/64bit.ll index f778f9dcf9a7..f5ed047592e9 100644 --- a/llvm/test/CodeGen/SPARC/64bit.ll +++ b/llvm/test/CodeGen/SPARC/64bit.ll @@ -285,3 +285,26 @@ entry: store i64 0, i64* %0, align 8 ret i64 0 } + +; CHECK-LABEL: bit_ops +; CHECK: popc + +; OPT-LABEL: bit_ops +; OPT: popc + +define i64 @bit_ops(i64 %arg) { +entry: + %0 = tail call i64 @llvm.ctpop.i64(i64 %arg) + %1 = tail call i64 @llvm.ctlz.i64(i64 %arg, i1 true) + %2 = tail call i64 @llvm.cttz.i64(i64 %arg, i1 true) + %3 = tail call i64 @llvm.bswap.i64(i64 %arg) + %4 = add i64 %0, %1 + %5 = add i64 %2, %3 + %6 = add i64 %4, %5 + ret i64 %6 +} + +declare i64 @llvm.ctpop.i64(i64) nounwind readnone +declare i64 @llvm.ctlz.i64(i64, i1) nounwind readnone +declare i64 @llvm.cttz.i64(i64, i1) nounwind readnone +declare i64 @llvm.bswap.i64(i64) nounwind readnone