1; Test population-count instruction
2;
3; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z196 | FileCheck %s
4
5declare i32 @llvm.ctpop.i32(i32 %a)
6declare i64 @llvm.ctpop.i64(i64 %a)
7
8define i32 @f1(i32 %a) {
9; CHECK-LABEL: f1:
10; CHECK: popcnt  %r0, %r2
11; CHECK: sllk    %r1, %r0, 16
12; CHECK: ar      %r0, %r1
13; CHECK: sllk    %r1, %r0, 8
14; CHECK: ar      %r0, %r1
15; CHECK: srlk    %r2, %r0, 24
16; CHECK: br      %r14
17
18  %popcnt = call i32 @llvm.ctpop.i32(i32 %a)
19  ret i32 %popcnt
20}
21
22define i32 @f2(i32 %a) {
23; CHECK-LABEL: f2:
24; CHECK: llhr    %r0, %r2
25; CHECK: popcnt  %r0, %r0
26; CHECK: risblg  %r1, %r0, 16, 151, 8
27; CHECK: ar      %r0, %r1
28; CHECK: srlk    %r2, %r0, 8
29; CHECK: br      %r14
30  %and = and i32 %a, 65535
31  %popcnt = call i32 @llvm.ctpop.i32(i32 %and)
32  ret i32 %popcnt
33}
34
35define i32 @f3(i32 %a) {
36; CHECK-LABEL: f3:
37; CHECK: llcr    %r0, %r2
38; CHECK: popcnt  %r2, %r0
39; CHECK: br      %r14
40  %and = and i32 %a, 255
41  %popcnt = call i32 @llvm.ctpop.i32(i32 %and)
42  ret i32 %popcnt
43}
44
45define i64 @f4(i64 %a) {
46; CHECK-LABEL: f4:
47; CHECK: popcnt  %r0, %r2
48; CHECK: sllg    %r1, %r0, 32
49; CHECK: agr     %r0, %r1
50; CHECK: sllg    %r1, %r0, 16
51; CHECK: agr     %r0, %r1
52; CHECK: sllg    %r1, %r0, 8
53; CHECK: agr     %r0, %r1
54; CHECK: srlg    %r2, %r0, 56
55; CHECK: br      %r14
56  %popcnt = call i64 @llvm.ctpop.i64(i64 %a)
57  ret i64 %popcnt
58}
59
60define i64 @f5(i64 %a) {
61; CHECK-LABEL: f5:
62; CHECK: llgfr   %r0, %r2
63; CHECK: popcnt  %r0, %r0
64; CHECK: sllg    %r1, %r0, 16
65; CHECK: algfr   %r0, %r1
66; CHECK: sllg    %r1, %r0, 8
67; CHECK: algfr   %r0, %r1
68; CHECK: srlg    %r2, %r0, 24
69  %and = and i64 %a, 4294967295
70  %popcnt = call i64 @llvm.ctpop.i64(i64 %and)
71  ret i64 %popcnt
72}
73
74define i64 @f6(i64 %a) {
75; CHECK-LABEL: f6:
76; CHECK: llghr   %r0, %r2
77; CHECK: popcnt  %r0, %r0
78; CHECK: risbg   %r1, %r0, 48, 183, 8
79; CHECK: agr     %r0, %r1
80; CHECK: srlg    %r2, %r0, 8
81; CHECK: br      %r14
82  %and = and i64 %a, 65535
83  %popcnt = call i64 @llvm.ctpop.i64(i64 %and)
84  ret i64 %popcnt
85}
86
87define i64 @f7(i64 %a) {
88; CHECK-LABEL: f7:
89; CHECK: llgcr   %r0, %r2
90; CHECK: popcnt  %r2, %r0
91; CHECK: br      %r14
92  %and = and i64 %a, 255
93  %popcnt = call i64 @llvm.ctpop.i64(i64 %and)
94  ret i64 %popcnt
95}
96
97