• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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:
3;
4;                            entry
5;                           /     \
6;               diamond_head       branch_from
7;                 /      \           |
8;    diamond_false        diamond_true
9;                 \      /
10;                   done
11;
12; When the diamond_true branch had more than 100 instructions.
13;
14;
15
16; CHECK-LABEL: {{^}}branch_into_diamond:
17; === entry block:
18; CHECK: ALU_PUSH_BEFORE
19; === Branch instruction (IF):
20; CHECK: JUMP
21  ; === branch_from block
22  ; CHECK: ALU
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()
27  ; CHECK: ALU
28; === Branch instruction (ELSE):
29; CHECK: ELSE
30  ; === diamond_head block:
31  ; CHECK: ALU_PUSH_BEFORE
32  ; === Branch instruction (IF):
33  ; CHECK: JUMP
34    ; === diamond_true block (There can be more than one ALU clause):
35    ; ALU
36  ; === Branch instruction (ELSE):
37  ; CHECK: ELSE
38    ; === diamond_false block plus implicit ENDIF
39    ; CHECK: ALU_POP_AFTER
40; === Branch instruction (ENDIF):
41; CHECK: POP
42; === done block:
43; CHECK: ALU
44; CHECK: MEM_RAT_CACHELESS
45; CHECK: CF_END
46
47
48define void @branch_into_diamond(i32 addrspace(1)* %out, i32 %a, i32 %b, i32 %c) {
49entry:
50%0 = icmp ne i32 %a, 0
51  br i1 %0, label %diamond_head, label %branch_from
52
53diamond_head:
54  %1 = icmp ne i32 %a, 1
55  br i1 %1, label %diamond_true, label %diamond_false
56
57branch_from:
58  %2 = add i32 %a, 1
59  br label %diamond_true
60
61diamond_false:
62  %3 = add i32 %a, 2
63  br label %done
64
65diamond_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
77  br label %done
78
79done:
80  %5 = phi i32 [%3, %diamond_false], [%div7, %diamond_true]
81  store i32 %5, i32 addrspace(1)* %out
82  ret void
83}
84