[llvm] [test][LoongArch] Pre-commit test for optimize CTPOP. NFC (PR #106940)

via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 1 23:18:17 PDT 2024


https://github.com/wangleiat created https://github.com/llvm/llvm-project/pull/106940

None

>From 2baee03dd1a0a9fb7ae3d8f24cc25c55fd37e500 Mon Sep 17 00:00:00 2001
From: wanglei <wanglei at loongson.cn>
Date: Mon, 2 Sep 2024 14:18:06 +0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 llvm/test/CodeGen/LoongArch/ctpop-with-lsx.ll | 206 ++++++++++++++++++
 1 file changed, 206 insertions(+)
 create mode 100644 llvm/test/CodeGen/LoongArch/ctpop-with-lsx.ll

diff --git a/llvm/test/CodeGen/LoongArch/ctpop-with-lsx.ll b/llvm/test/CodeGen/LoongArch/ctpop-with-lsx.ll
new file mode 100644
index 00000000000000..a5cffb29eec614
--- /dev/null
+++ b/llvm/test/CodeGen/LoongArch/ctpop-with-lsx.ll
@@ -0,0 +1,206 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc --mtriple=loongarch32 -mattr=+lsx < %s | FileCheck %s --check-prefix=LA32
+; RUN: llc --mtriple=loongarch64 -mattr=+lsx < %s | FileCheck %s --check-prefix=LA64
+
+declare i8 @llvm.ctpop.i8(i8)
+declare i16 @llvm.ctpop.i16(i16)
+declare i32 @llvm.ctpop.i32(i32)
+declare i64 @llvm.ctpop.i64(i64)
+
+define i8 @test_ctpop_i8(i8 %a) nounwind {
+; LA32-LABEL: test_ctpop_i8:
+; LA32:       # %bb.0:
+; LA32-NEXT:    srli.w $a1, $a0, 1
+; LA32-NEXT:    andi $a1, $a1, 85
+; LA32-NEXT:    sub.w $a0, $a0, $a1
+; LA32-NEXT:    andi $a1, $a0, 51
+; LA32-NEXT:    srli.w $a0, $a0, 2
+; LA32-NEXT:    andi $a0, $a0, 51
+; LA32-NEXT:    add.w $a0, $a1, $a0
+; LA32-NEXT:    srli.w $a1, $a0, 4
+; LA32-NEXT:    add.w $a0, $a0, $a1
+; LA32-NEXT:    andi $a0, $a0, 15
+; LA32-NEXT:    ret
+;
+; LA64-LABEL: test_ctpop_i8:
+; LA64:       # %bb.0:
+; LA64-NEXT:    srli.d $a1, $a0, 1
+; LA64-NEXT:    andi $a1, $a1, 85
+; LA64-NEXT:    sub.d $a0, $a0, $a1
+; LA64-NEXT:    andi $a1, $a0, 51
+; LA64-NEXT:    srli.d $a0, $a0, 2
+; LA64-NEXT:    andi $a0, $a0, 51
+; LA64-NEXT:    add.d $a0, $a1, $a0
+; LA64-NEXT:    srli.d $a1, $a0, 4
+; LA64-NEXT:    add.d $a0, $a0, $a1
+; LA64-NEXT:    andi $a0, $a0, 15
+; LA64-NEXT:    ret
+  %1 = call i8 @llvm.ctpop.i8(i8 %a)
+  ret i8 %1
+}
+
+define i16 @test_ctpop_i16(i16 %a) nounwind {
+; LA32-LABEL: test_ctpop_i16:
+; LA32:       # %bb.0:
+; LA32-NEXT:    srli.w $a1, $a0, 1
+; LA32-NEXT:    lu12i.w $a2, 5
+; LA32-NEXT:    ori $a2, $a2, 1365
+; LA32-NEXT:    and $a1, $a1, $a2
+; LA32-NEXT:    sub.w $a0, $a0, $a1
+; LA32-NEXT:    lu12i.w $a1, 3
+; LA32-NEXT:    ori $a1, $a1, 819
+; LA32-NEXT:    and $a2, $a0, $a1
+; LA32-NEXT:    srli.w $a0, $a0, 2
+; LA32-NEXT:    and $a0, $a0, $a1
+; LA32-NEXT:    add.w $a0, $a2, $a0
+; LA32-NEXT:    srli.w $a1, $a0, 4
+; LA32-NEXT:    add.w $a0, $a0, $a1
+; LA32-NEXT:    bstrpick.w $a1, $a0, 11, 8
+; LA32-NEXT:    andi $a0, $a0, 15
+; LA32-NEXT:    add.w $a0, $a0, $a1
+; LA32-NEXT:    ret
+;
+; LA64-LABEL: test_ctpop_i16:
+; LA64:       # %bb.0:
+; LA64-NEXT:    srli.d $a1, $a0, 1
+; LA64-NEXT:    lu12i.w $a2, 5
+; LA64-NEXT:    ori $a2, $a2, 1365
+; LA64-NEXT:    and $a1, $a1, $a2
+; LA64-NEXT:    sub.d $a0, $a0, $a1
+; LA64-NEXT:    lu12i.w $a1, 3
+; LA64-NEXT:    ori $a1, $a1, 819
+; LA64-NEXT:    and $a2, $a0, $a1
+; LA64-NEXT:    srli.d $a0, $a0, 2
+; LA64-NEXT:    and $a0, $a0, $a1
+; LA64-NEXT:    add.d $a0, $a2, $a0
+; LA64-NEXT:    srli.d $a1, $a0, 4
+; LA64-NEXT:    add.d $a0, $a0, $a1
+; LA64-NEXT:    bstrpick.d $a1, $a0, 11, 8
+; LA64-NEXT:    andi $a0, $a0, 15
+; LA64-NEXT:    add.d $a0, $a0, $a1
+; LA64-NEXT:    ret
+  %1 = call i16 @llvm.ctpop.i16(i16 %a)
+  ret i16 %1
+}
+
+define i32 @test_ctpop_i32(i32 %a) nounwind {
+; LA32-LABEL: test_ctpop_i32:
+; LA32:       # %bb.0:
+; LA32-NEXT:    srli.w $a1, $a0, 1
+; LA32-NEXT:    lu12i.w $a2, 349525
+; LA32-NEXT:    ori $a2, $a2, 1365
+; LA32-NEXT:    and $a1, $a1, $a2
+; LA32-NEXT:    sub.w $a0, $a0, $a1
+; LA32-NEXT:    lu12i.w $a1, 209715
+; LA32-NEXT:    ori $a1, $a1, 819
+; LA32-NEXT:    and $a2, $a0, $a1
+; LA32-NEXT:    srli.w $a0, $a0, 2
+; LA32-NEXT:    and $a0, $a0, $a1
+; LA32-NEXT:    add.w $a0, $a2, $a0
+; LA32-NEXT:    srli.w $a1, $a0, 4
+; LA32-NEXT:    add.w $a0, $a0, $a1
+; LA32-NEXT:    lu12i.w $a1, 61680
+; LA32-NEXT:    ori $a1, $a1, 3855
+; LA32-NEXT:    and $a0, $a0, $a1
+; LA32-NEXT:    lu12i.w $a1, 4112
+; LA32-NEXT:    ori $a1, $a1, 257
+; LA32-NEXT:    mul.w $a0, $a0, $a1
+; LA32-NEXT:    srli.w $a0, $a0, 24
+; LA32-NEXT:    ret
+;
+; LA64-LABEL: test_ctpop_i32:
+; LA64:       # %bb.0:
+; LA64-NEXT:    srli.d $a1, $a0, 1
+; LA64-NEXT:    lu12i.w $a2, 349525
+; LA64-NEXT:    ori $a2, $a2, 1365
+; LA64-NEXT:    and $a1, $a1, $a2
+; LA64-NEXT:    sub.d $a0, $a0, $a1
+; LA64-NEXT:    lu12i.w $a1, 209715
+; LA64-NEXT:    ori $a1, $a1, 819
+; LA64-NEXT:    and $a2, $a0, $a1
+; LA64-NEXT:    srli.d $a0, $a0, 2
+; LA64-NEXT:    and $a0, $a0, $a1
+; LA64-NEXT:    add.d $a0, $a2, $a0
+; LA64-NEXT:    srli.d $a1, $a0, 4
+; LA64-NEXT:    add.d $a0, $a0, $a1
+; LA64-NEXT:    lu12i.w $a1, 61680
+; LA64-NEXT:    ori $a1, $a1, 3855
+; LA64-NEXT:    and $a0, $a0, $a1
+; LA64-NEXT:    lu12i.w $a1, 4112
+; LA64-NEXT:    ori $a1, $a1, 257
+; LA64-NEXT:    mul.d $a0, $a0, $a1
+; LA64-NEXT:    bstrpick.d $a0, $a0, 31, 24
+; LA64-NEXT:    ret
+  %1 = call i32 @llvm.ctpop.i32(i32 %a)
+  ret i32 %1
+}
+
+define i64 @test_ctpop_i64(i64 %a) nounwind {
+; LA32-LABEL: test_ctpop_i64:
+; LA32:       # %bb.0:
+; LA32-NEXT:    srli.w $a2, $a1, 1
+; LA32-NEXT:    lu12i.w $a3, 349525
+; LA32-NEXT:    ori $a3, $a3, 1365
+; LA32-NEXT:    and $a2, $a2, $a3
+; LA32-NEXT:    sub.w $a1, $a1, $a2
+; LA32-NEXT:    lu12i.w $a2, 209715
+; LA32-NEXT:    ori $a2, $a2, 819
+; LA32-NEXT:    and $a4, $a1, $a2
+; LA32-NEXT:    srli.w $a1, $a1, 2
+; LA32-NEXT:    and $a1, $a1, $a2
+; LA32-NEXT:    add.w $a1, $a4, $a1
+; LA32-NEXT:    srli.w $a4, $a1, 4
+; LA32-NEXT:    add.w $a1, $a1, $a4
+; LA32-NEXT:    lu12i.w $a4, 61680
+; LA32-NEXT:    ori $a4, $a4, 3855
+; LA32-NEXT:    and $a1, $a1, $a4
+; LA32-NEXT:    lu12i.w $a5, 4112
+; LA32-NEXT:    ori $a5, $a5, 257
+; LA32-NEXT:    mul.w $a1, $a1, $a5
+; LA32-NEXT:    srli.w $a1, $a1, 24
+; LA32-NEXT:    srli.w $a6, $a0, 1
+; LA32-NEXT:    and $a3, $a6, $a3
+; LA32-NEXT:    sub.w $a0, $a0, $a3
+; LA32-NEXT:    and $a3, $a0, $a2
+; LA32-NEXT:    srli.w $a0, $a0, 2
+; LA32-NEXT:    and $a0, $a0, $a2
+; LA32-NEXT:    add.w $a0, $a3, $a0
+; LA32-NEXT:    srli.w $a2, $a0, 4
+; LA32-NEXT:    add.w $a0, $a0, $a2
+; LA32-NEXT:    and $a0, $a0, $a4
+; LA32-NEXT:    mul.w $a0, $a0, $a5
+; LA32-NEXT:    srli.w $a0, $a0, 24
+; LA32-NEXT:    add.w $a0, $a0, $a1
+; LA32-NEXT:    move $a1, $zero
+; LA32-NEXT:    ret
+;
+; LA64-LABEL: test_ctpop_i64:
+; LA64:       # %bb.0:
+; LA64-NEXT:    srli.d $a1, $a0, 1
+; LA64-NEXT:    lu12i.w $a2, 349525
+; LA64-NEXT:    ori $a2, $a2, 1365
+; LA64-NEXT:    bstrins.d $a2, $a2, 62, 32
+; LA64-NEXT:    and $a1, $a1, $a2
+; LA64-NEXT:    sub.d $a0, $a0, $a1
+; LA64-NEXT:    lu12i.w $a1, 209715
+; LA64-NEXT:    ori $a1, $a1, 819
+; LA64-NEXT:    bstrins.d $a1, $a1, 61, 32
+; LA64-NEXT:    and $a2, $a0, $a1
+; LA64-NEXT:    srli.d $a0, $a0, 2
+; LA64-NEXT:    and $a0, $a0, $a1
+; LA64-NEXT:    add.d $a0, $a2, $a0
+; LA64-NEXT:    srli.d $a1, $a0, 4
+; LA64-NEXT:    add.d $a0, $a0, $a1
+; LA64-NEXT:    lu12i.w $a1, 61680
+; LA64-NEXT:    ori $a1, $a1, 3855
+; LA64-NEXT:    bstrins.d $a1, $a1, 59, 32
+; LA64-NEXT:    and $a0, $a0, $a1
+; LA64-NEXT:    lu12i.w $a1, 4112
+; LA64-NEXT:    ori $a1, $a1, 257
+; LA64-NEXT:    bstrins.d $a1, $a1, 56, 32
+; LA64-NEXT:    mul.d $a0, $a0, $a1
+; LA64-NEXT:    srli.d $a0, $a0, 56
+; LA64-NEXT:    ret
+  %1 = call i64 @llvm.ctpop.i64(i64 %a)
+  ret i64 %1
+}



More information about the llvm-commits mailing list