1 ; RUN: llc < %s -march=r600 -mcpu=redwood -r600-ir-structurize=0 | FileCheck %s
2 ; Test case for a crash in the AMDILCFGStructurizer from a CFG like this:
6 ; diamond_head branch_from
8 ; diamond_false diamond_true
12 ; When the diamond_true branch had more than 100 instructions.
16 ; CHECK-LABEL: {{^}}branch_into_diamond:
18 ; CHECK: ALU_PUSH_BEFORE
19 ; === Branch instruction (IF):
21 ; === branch_from block
23 ; === Duplicated diamond_true block (There can be more than one ALU clause):
24 ; === XXX: We should be able to optimize this so the basic block is not
25 ; === duplicated. See comments in
26 ; === AMDGPUCFGStructurizer::improveSimpleJumpintoIf()
28 ; === Branch instruction (ELSE):
30 ; === diamond_head block:
31 ; CHECK: ALU_PUSH_BEFORE
32 ; === Branch instruction (IF):
34 ; === diamond_true block (There can be more than one ALU clause):
36 ; === Branch instruction (ELSE):
38 ; === diamond_false block plus implicit ENDIF
39 ; CHECK: ALU_POP_AFTER
40 ; === Branch instruction (ENDIF):
44 ; CHECK: MEM_RAT_CACHELESS
48 define amdgpu_kernel void @branch_into_diamond(ptr addrspace(1) %out, i32 %a, i32 %b, i32 %c) {
50 %0 = icmp ne i32 %a, 0
51 br i1 %0, label %diamond_head, label %branch_from
54 %1 = icmp ne i32 %a, 1
55 br i1 %1, label %diamond_true, label %diamond_false
59 br label %diamond_true
66 %4 = phi i32 [%2, %branch_from], [%a, %diamond_head]
67 ; This block needs to be > 100 ISA instructions to hit the bug,
68 ; so we'll use udiv instructions.
69 %div0 = udiv i32 %a, %b
70 %div1 = udiv i32 %div0, %4
71 %div2 = udiv i32 %div1, 11
72 %div3 = udiv i32 %div2, %a
73 %div4 = udiv i32 %div3, %b
74 %div5 = udiv i32 %div4, %c
75 %div6 = udiv i32 %div5, %div0
76 %div7 = udiv i32 %div6, %div1
80 %5 = phi i32 [%3, %diamond_false], [%div7, %diamond_true]
81 store i32 %5, ptr addrspace(1) %out