Matt Arsenault | cf9a9a1 | 2014-06-15 19:48:16 +0000 | [diff] [blame^] | 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 |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 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 | |
Matt Arsenault | cf9a9a1 | 2014-06-15 19:48:16 +0000 | [diff] [blame^] | 13 | ; FUNC-LABEL: @sdiv_i32 |
| 14 | ; EG: CF_END |
| 15 | define void @sdiv_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %in) { |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 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 | } |
Matt Arsenault | cf9a9a1 | 2014-06-15 19:48:16 +0000 | [diff] [blame^] | 23 | |
| 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 |
| 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 |
| 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 |
| 49 | ret void |
| 50 | } |
| 51 | |
| 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 |
| 56 | ; ret void |
| 57 | ; } |
| 58 | |
| 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 |
| 62 | ; ret void |
| 63 | ; } |
| 64 | |
| 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 |
| 70 | ; ret void |
| 71 | ; } |