• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: llc -march=r600 -mcpu=SI < %s | FileCheck -check-prefix=SI -check-prefix=FUNC %s
2; RUN: llc -march=r600 -mcpu=redwood < %s | FileCheck -check-prefix=EG -check-prefix=FUNC %s
3
4; The code generated by sdiv is long and complex and may frequently change.
5; The goal of this test is to make sure the ISel doesn't fail.
6;
7; This program was previously failing to compile when one of the selectcc
8; opcodes generated by the sdiv lowering was being legalized and optimized to:
9; selectcc Remainder -1, 0, -1, SETGT
10; This was fixed by adding an additional pattern in R600Instructions.td to
11; match this pattern with a CNDGE_INT.
12
13; FUNC-LABEL: @sdiv_i32
14; EG: CF_END
15define void @sdiv_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %in) {
16  %den_ptr = getelementptr i32 addrspace(1)* %in, i32 1
17  %num = load i32 addrspace(1) * %in
18  %den = load i32 addrspace(1) * %den_ptr
19  %result = sdiv i32 %num, %den
20  store i32 %result, i32 addrspace(1)* %out
21  ret void
22}
23
24; FUNC-LABEL: @sdiv_i32_4
25define void @sdiv_i32_4(i32 addrspace(1)* %out, i32 addrspace(1)* %in) {
26  %num = load i32 addrspace(1) * %in
27  %result = sdiv i32 %num, 4
28  store i32 %result, i32 addrspace(1)* %out
29  ret void
30}
31
32; Multiply by a weird constant to make sure setIntDivIsCheap is
33; working.
34
35; FUNC-LABEL: @slow_sdiv_i32_3435
36; SI: BUFFER_LOAD_DWORD [[VAL:v[0-9]+]],
37; SI: V_MOV_B32_e32 [[MAGIC:v[0-9]+]], 0x98a1930b
38; SI: V_MUL_HI_I32 [[TMP:v[0-9]+]], [[VAL]], [[MAGIC]]
39; SI: V_ADD_I32
40; SI: V_LSHRREV_B32
41; SI: V_ASHRREV_I32
42; SI: V_ADD_I32
43; SI: BUFFER_STORE_DWORD
44; SI: S_ENDPGM
45define void @slow_sdiv_i32_3435(i32 addrspace(1)* %out, i32 addrspace(1)* %in) {
46  %num = load i32 addrspace(1) * %in
47  %result = sdiv i32 %num, 3435
48  store i32 %result, i32 addrspace(1)* %out
49  ret void
50}
51
52define void @sdiv_v2i32(<2 x i32> addrspace(1)* %out, <2 x i32> addrspace(1)* %in) {
53  %den_ptr = getelementptr <2 x i32> addrspace(1)* %in, i32 1
54  %num = load <2 x i32> addrspace(1) * %in
55  %den = load <2 x i32> addrspace(1) * %den_ptr
56  %result = sdiv <2 x i32> %num, %den
57  store <2 x i32> %result, <2 x i32> addrspace(1)* %out
58  ret void
59}
60
61define void @sdiv_v2i32_4(<2 x i32> addrspace(1)* %out, <2 x i32> addrspace(1)* %in) {
62  %num = load <2 x i32> addrspace(1) * %in
63  %result = sdiv <2 x i32> %num, <i32 4, i32 4>
64  store <2 x i32> %result, <2 x i32> addrspace(1)* %out
65  ret void
66}
67
68define void @sdiv_v4i32(<4 x i32> addrspace(1)* %out, <4 x i32> addrspace(1)* %in) {
69  %den_ptr = getelementptr <4 x i32> addrspace(1)* %in, i32 1
70  %num = load <4 x i32> addrspace(1) * %in
71  %den = load <4 x i32> addrspace(1) * %den_ptr
72  %result = sdiv <4 x i32> %num, %den
73  store <4 x i32> %result, <4 x i32> addrspace(1)* %out
74  ret void
75}
76
77define void @sdiv_v4i32_4(<4 x i32> addrspace(1)* %out, <4 x i32> addrspace(1)* %in) {
78  %num = load <4 x i32> addrspace(1) * %in
79  %result = sdiv <4 x i32> %num, <i32 4, i32 4, i32 4, i32 4>
80  store <4 x i32> %result, <4 x i32> addrspace(1)* %out
81  ret void
82}
83
84; Tests for 64-bit divide bypass.
85; define void @test_get_quotient(i64 addrspace(1)* %out, i64 %a, i64 %b) nounwind {
86;   %result = sdiv i64 %a, %b
87;   store i64 %result, i64 addrspace(1)* %out, align 8
88;   ret void
89; }
90
91; define void @test_get_remainder(i64 addrspace(1)* %out, i64 %a, i64 %b) nounwind {
92;   %result = srem i64 %a, %b
93;   store i64 %result, i64 addrspace(1)* %out, align 8
94;   ret void
95; }
96
97; define void @test_get_quotient_and_remainder(i64 addrspace(1)* %out, i64 %a, i64 %b) nounwind {
98;   %resultdiv = sdiv i64 %a, %b
99;   %resultrem = srem i64 %a, %b
100;   %result = add i64 %resultdiv, %resultrem
101;   store i64 %result, i64 addrspace(1)* %out, align 8
102;   ret void
103; }
104