xref: /aosp_15_r20/external/llvm/test/CodeGen/AArch64/arm64-popcnt.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -march=arm64 -aarch64-neon-syntax=apple | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -march=aarch64 -mattr -neon -aarch64-neon-syntax=apple | FileCheck -check-prefix=CHECK-NONEON %s
3*9880d681SAndroid Build Coastguard Worker
4*9880d681SAndroid Build Coastguard Workerdefine i32 @cnt32_advsimd(i32 %x) nounwind readnone {
5*9880d681SAndroid Build Coastguard Worker  %cnt = tail call i32 @llvm.ctpop.i32(i32 %x)
6*9880d681SAndroid Build Coastguard Worker  ret i32 %cnt
7*9880d681SAndroid Build Coastguard Worker; CHECK: mov w[[IN64:[0-9]+]], w0
8*9880d681SAndroid Build Coastguard Worker; CHECK: fmov	d0, x[[IN64]]
9*9880d681SAndroid Build Coastguard Worker; CHECK: cnt.8b	v0, v0
10*9880d681SAndroid Build Coastguard Worker; CHECK: uaddlv.8b	h0, v0
11*9880d681SAndroid Build Coastguard Worker; CHECK: fmov w0, s0
12*9880d681SAndroid Build Coastguard Worker; CHECK: ret
13*9880d681SAndroid Build Coastguard Worker; CHECK-NONEON-LABEL: cnt32_advsimd
14*9880d681SAndroid Build Coastguard Worker; CHECK-NONEON-NOT: 8b
15*9880d681SAndroid Build Coastguard Worker; CHECK-NONEON: and w{{[0-9]+}}, w{{[0-9]+}}, #0x55555555
16*9880d681SAndroid Build Coastguard Worker; CHECK-NONEON: and w{{[0-9]+}}, w{{[0-9]+}}, #0x33333333
17*9880d681SAndroid Build Coastguard Worker; CHECK-NONEON: and w{{[0-9]+}}, w{{[0-9]+}}, #0xf0f0f0f
18*9880d681SAndroid Build Coastguard Worker; CHECK-NONEON: mul
19*9880d681SAndroid Build Coastguard Worker}
20*9880d681SAndroid Build Coastguard Worker
21*9880d681SAndroid Build Coastguard Workerdefine i32 @cnt32_advsimd_2(<2 x i32> %x) {
22*9880d681SAndroid Build Coastguard Worker  %1 = extractelement <2 x i32> %x, i64 0
23*9880d681SAndroid Build Coastguard Worker  %2 = tail call i32 @llvm.ctpop.i32(i32 %1)
24*9880d681SAndroid Build Coastguard Worker  ret i32 %2
25*9880d681SAndroid Build Coastguard Worker; CHECK: fmov	w0, s0
26*9880d681SAndroid Build Coastguard Worker; CHECK: fmov	d0, x0
27*9880d681SAndroid Build Coastguard Worker; CHECK: cnt.8b	v0, v0
28*9880d681SAndroid Build Coastguard Worker; CHECK: uaddlv.8b	h0, v0
29*9880d681SAndroid Build Coastguard Worker; CHECK: fmov w0, s0
30*9880d681SAndroid Build Coastguard Worker; CHECK: ret
31*9880d681SAndroid Build Coastguard Worker; CHECK-NONEON-LABEL: cnt32_advsimd_2
32*9880d681SAndroid Build Coastguard Worker; CHECK-NONEON-NOT: 8b
33*9880d681SAndroid Build Coastguard Worker; CHECK-NONEON: and w{{[0-9]+}}, w{{[0-9]+}}, #0x55555555
34*9880d681SAndroid Build Coastguard Worker; CHECK-NONEON: and w{{[0-9]+}}, w{{[0-9]+}}, #0x33333333
35*9880d681SAndroid Build Coastguard Worker; CHECK-NONEON: and w{{[0-9]+}}, w{{[0-9]+}}, #0xf0f0f0f
36*9880d681SAndroid Build Coastguard Worker; CHECK-NONEON: mul
37*9880d681SAndroid Build Coastguard Worker}
38*9880d681SAndroid Build Coastguard Worker
39*9880d681SAndroid Build Coastguard Workerdefine i64 @cnt64_advsimd(i64 %x) nounwind readnone {
40*9880d681SAndroid Build Coastguard Worker  %cnt = tail call i64 @llvm.ctpop.i64(i64 %x)
41*9880d681SAndroid Build Coastguard Worker  ret i64 %cnt
42*9880d681SAndroid Build Coastguard Worker; CHECK: fmov	d0, x0
43*9880d681SAndroid Build Coastguard Worker; CHECK: cnt.8b	v0, v0
44*9880d681SAndroid Build Coastguard Worker; CHECK: uaddlv.8b	h0, v0
45*9880d681SAndroid Build Coastguard Worker; CHECK: fmov	w0, s0
46*9880d681SAndroid Build Coastguard Worker; CHECK: ret
47*9880d681SAndroid Build Coastguard Worker; CHECK-NONEON-LABEL: cnt64_advsimd
48*9880d681SAndroid Build Coastguard Worker; CHECK-NONEON-NOT: 8b
49*9880d681SAndroid Build Coastguard Worker; CHECK-NONEON: and x{{[0-9]+}}, x{{[0-9]+}}, #0x5555555555555555
50*9880d681SAndroid Build Coastguard Worker; CHECK-NONEON: and x{{[0-9]+}}, x{{[0-9]+}}, #0x3333333333333333
51*9880d681SAndroid Build Coastguard Worker; CHECK-NONEON: and x{{[0-9]+}}, x{{[0-9]+}}, #0xf0f0f0f0f0f0f0f
52*9880d681SAndroid Build Coastguard Worker; CHECK-NONEON: mul
53*9880d681SAndroid Build Coastguard Worker}
54*9880d681SAndroid Build Coastguard Worker
55*9880d681SAndroid Build Coastguard Worker; Do not use AdvSIMD when -mno-implicit-float is specified.
56*9880d681SAndroid Build Coastguard Worker; rdar://9473858
57*9880d681SAndroid Build Coastguard Worker
58*9880d681SAndroid Build Coastguard Workerdefine i32 @cnt32(i32 %x) nounwind readnone noimplicitfloat {
59*9880d681SAndroid Build Coastguard Worker  %cnt = tail call i32 @llvm.ctpop.i32(i32 %x)
60*9880d681SAndroid Build Coastguard Worker  ret i32 %cnt
61*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: cnt32:
62*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: 16b
63*9880d681SAndroid Build Coastguard Worker; CHECK: ret
64*9880d681SAndroid Build Coastguard Worker}
65*9880d681SAndroid Build Coastguard Worker
66*9880d681SAndroid Build Coastguard Workerdefine i64 @cnt64(i64 %x) nounwind readnone noimplicitfloat {
67*9880d681SAndroid Build Coastguard Worker  %cnt = tail call i64 @llvm.ctpop.i64(i64 %x)
68*9880d681SAndroid Build Coastguard Worker  ret i64 %cnt
69*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: cnt64:
70*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: 16b
71*9880d681SAndroid Build Coastguard Worker; CHECK: ret
72*9880d681SAndroid Build Coastguard Worker}
73*9880d681SAndroid Build Coastguard Worker
74*9880d681SAndroid Build Coastguard Workerdeclare i32 @llvm.ctpop.i32(i32) nounwind readnone
75*9880d681SAndroid Build Coastguard Workerdeclare i64 @llvm.ctpop.i64(i64) nounwind readnone
76