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
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.
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.
13 ; FUNC-LABEL: @sdiv_i32
15 define 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
24 ; FUNC-LABEL: @sdiv_i32_4
25 define 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
32 ; Multiply by a weird constant to make sure setIntDivIsCheap is
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]]
43 ; SI: BUFFER_STORE_DWORD
45 define 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
52 ; Tests for 64-bit divide bypass.
53 ; define void @test_get_quotient(i64 addrspace(1)* %out, i64 %a, i64 %b) nounwind {
54 ; %result = sdiv i64 %a, %b
55 ; store i64 %result, i64 addrspace(1)* %out, align 8
59 ; define void @test_get_remainder(i64 addrspace(1)* %out, i64 %a, i64 %b) nounwind {
60 ; %result = srem i64 %a, %b
61 ; store i64 %result, i64 addrspace(1)* %out, align 8
65 ; define void @test_get_quotient_and_remainder(i64 addrspace(1)* %out, i64 %a, i64 %b) nounwind {
66 ; %resultdiv = sdiv i64 %a, %b
67 ; %resultrem = srem i64 %a, %b
68 ; %result = add i64 %resultdiv, %resultrem
69 ; store i64 %result, i64 addrspace(1)* %out, align 8