1; RUN: llc -march=amdgcn -mcpu=SI < %s | FileCheck -check-prefix=SI -check-prefix=FUNC %s
2; RUN: llc -march=amdgcn -mcpu=tonga < %s | FileCheck -check-prefix=SI -check-prefix=FUNC %s
3; RUN: llc -march=r600 -mcpu=redwood < %s
4
5define void @srem_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %in) {
6  %den_ptr = getelementptr i32, i32 addrspace(1)* %in, i32 1
7  %num = load i32, i32 addrspace(1) * %in
8  %den = load i32, i32 addrspace(1) * %den_ptr
9  %result = srem i32 %num, %den
10  store i32 %result, i32 addrspace(1)* %out
11  ret void
12}
13
14define void @srem_i32_4(i32 addrspace(1)* %out, i32 addrspace(1)* %in) {
15  %num = load i32, i32 addrspace(1) * %in
16  %result = srem i32 %num, 4
17  store i32 %result, i32 addrspace(1)* %out
18  ret void
19}
20
21; FUNC-LABEL: {{^}}srem_i32_7:
22; SI: v_mov_b32_e32 [[MAGIC:v[0-9]+]], 0x92492493
23; SI: v_mul_hi_i32 {{v[0-9]+}}, [[MAGIC]],
24; SI: v_mul_lo_i32
25; SI: v_sub_i32
26; SI: s_endpgm
27define void @srem_i32_7(i32 addrspace(1)* %out, i32 addrspace(1)* %in) {
28  %num = load i32, i32 addrspace(1) * %in
29  %result = srem i32 %num, 7
30  store i32 %result, i32 addrspace(1)* %out
31  ret void
32}
33
34define void @srem_v2i32(<2 x i32> addrspace(1)* %out, <2 x i32> addrspace(1)* %in) {
35  %den_ptr = getelementptr <2 x i32>, <2 x i32> addrspace(1)* %in, i32 1
36  %num = load <2 x i32>, <2 x i32> addrspace(1) * %in
37  %den = load <2 x i32>, <2 x i32> addrspace(1) * %den_ptr
38  %result = srem <2 x i32> %num, %den
39  store <2 x i32> %result, <2 x i32> addrspace(1)* %out
40  ret void
41}
42
43define void @srem_v2i32_4(<2 x i32> addrspace(1)* %out, <2 x i32> addrspace(1)* %in) {
44  %num = load <2 x i32>, <2 x i32> addrspace(1) * %in
45  %result = srem <2 x i32> %num, <i32 4, i32 4>
46  store <2 x i32> %result, <2 x i32> addrspace(1)* %out
47  ret void
48}
49
50define void @srem_v4i32(<4 x i32> addrspace(1)* %out, <4 x i32> addrspace(1)* %in) {
51  %den_ptr = getelementptr <4 x i32>, <4 x i32> addrspace(1)* %in, i32 1
52  %num = load <4 x i32>, <4 x i32> addrspace(1) * %in
53  %den = load <4 x i32>, <4 x i32> addrspace(1) * %den_ptr
54  %result = srem <4 x i32> %num, %den
55  store <4 x i32> %result, <4 x i32> addrspace(1)* %out
56  ret void
57}
58
59define void @srem_v4i32_4(<4 x i32> addrspace(1)* %out, <4 x i32> addrspace(1)* %in) {
60  %num = load <4 x i32>, <4 x i32> addrspace(1) * %in
61  %result = srem <4 x i32> %num, <i32 4, i32 4, i32 4, i32 4>
62  store <4 x i32> %result, <4 x i32> addrspace(1)* %out
63  ret void
64}
65
66define void @srem_i64(i64 addrspace(1)* %out, i64 addrspace(1)* %in) {
67  %den_ptr = getelementptr i64, i64 addrspace(1)* %in, i64 1
68  %num = load i64, i64 addrspace(1) * %in
69  %den = load i64, i64 addrspace(1) * %den_ptr
70  %result = srem i64 %num, %den
71  store i64 %result, i64 addrspace(1)* %out
72  ret void
73}
74
75define void @srem_i64_4(i64 addrspace(1)* %out, i64 addrspace(1)* %in) {
76  %num = load i64, i64 addrspace(1) * %in
77  %result = srem i64 %num, 4
78  store i64 %result, i64 addrspace(1)* %out
79  ret void
80}
81
82define void @srem_v2i64(<2 x i64> addrspace(1)* %out, <2 x i64> addrspace(1)* %in) {
83  %den_ptr = getelementptr <2 x i64>, <2 x i64> addrspace(1)* %in, i64 1
84  %num = load <2 x i64>, <2 x i64> addrspace(1) * %in
85  %den = load <2 x i64>, <2 x i64> addrspace(1) * %den_ptr
86  %result = srem <2 x i64> %num, %den
87  store <2 x i64> %result, <2 x i64> addrspace(1)* %out
88  ret void
89}
90
91define void @srem_v2i64_4(<2 x i64> addrspace(1)* %out, <2 x i64> addrspace(1)* %in) {
92  %num = load <2 x i64>, <2 x i64> addrspace(1) * %in
93  %result = srem <2 x i64> %num, <i64 4, i64 4>
94  store <2 x i64> %result, <2 x i64> addrspace(1)* %out
95  ret void
96}
97
98define void @srem_v4i64(<4 x i64> addrspace(1)* %out, <4 x i64> addrspace(1)* %in) {
99  %den_ptr = getelementptr <4 x i64>, <4 x i64> addrspace(1)* %in, i64 1
100  %num = load <4 x i64>, <4 x i64> addrspace(1) * %in
101  %den = load <4 x i64>, <4 x i64> addrspace(1) * %den_ptr
102  %result = srem <4 x i64> %num, %den
103  store <4 x i64> %result, <4 x i64> addrspace(1)* %out
104  ret void
105}
106
107define void @srem_v4i64_4(<4 x i64> addrspace(1)* %out, <4 x i64> addrspace(1)* %in) {
108  %num = load <4 x i64>, <4 x i64> addrspace(1) * %in
109  %result = srem <4 x i64> %num, <i64 4, i64 4, i64 4, i64 4>
110  store <4 x i64> %result, <4 x i64> addrspace(1)* %out
111  ret void
112}
113