1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -O1 -mtriple=riscv32 -verify-machineinstrs < %s \
3 ; RUN: | FileCheck %s -check-prefix=RV32I
5 @a = common global i32 0, align 4
6 @l = common global i32 0, align 4
7 @b = common global i32 0, align 4
8 @c = common global i32 0, align 4
9 @d = common global i32 0, align 4
10 @e = common global i32 0, align 4
11 @k = common global i32 0, align 4
12 @f = common global i32 0, align 4
13 @j = common global i32 0, align 4
14 @g = common global i32 0, align 4
15 @i = common global i32 0, align 4
16 @h = common global i32 0, align 4
18 ; This test case benefits from codegen recognising that some values are
19 ; trivially rematerialisable, meaning they are recreated rather than saved to
20 ; the stack and restored. It creates high register pressure to force this
23 define i32 @test() nounwind {
25 ; RV32I: # %bb.0: # %entry
26 ; RV32I-NEXT: addi sp, sp, -64
27 ; RV32I-NEXT: sw ra, 60(sp) # 4-byte Folded Spill
28 ; RV32I-NEXT: sw s0, 56(sp) # 4-byte Folded Spill
29 ; RV32I-NEXT: sw s1, 52(sp) # 4-byte Folded Spill
30 ; RV32I-NEXT: sw s2, 48(sp) # 4-byte Folded Spill
31 ; RV32I-NEXT: sw s3, 44(sp) # 4-byte Folded Spill
32 ; RV32I-NEXT: sw s4, 40(sp) # 4-byte Folded Spill
33 ; RV32I-NEXT: sw s5, 36(sp) # 4-byte Folded Spill
34 ; RV32I-NEXT: sw s6, 32(sp) # 4-byte Folded Spill
35 ; RV32I-NEXT: sw s7, 28(sp) # 4-byte Folded Spill
36 ; RV32I-NEXT: sw s8, 24(sp) # 4-byte Folded Spill
37 ; RV32I-NEXT: sw s9, 20(sp) # 4-byte Folded Spill
38 ; RV32I-NEXT: sw s10, 16(sp) # 4-byte Folded Spill
39 ; RV32I-NEXT: sw s11, 12(sp) # 4-byte Folded Spill
40 ; RV32I-NEXT: lui s0, %hi(a)
41 ; RV32I-NEXT: lw a0, %lo(a)(s0)
42 ; RV32I-NEXT: beqz a0, .LBB0_11
43 ; RV32I-NEXT: # %bb.1: # %for.body.preheader
44 ; RV32I-NEXT: lui s1, %hi(l)
45 ; RV32I-NEXT: lui s2, %hi(k)
46 ; RV32I-NEXT: lui s3, %hi(j)
47 ; RV32I-NEXT: lui s4, %hi(i)
48 ; RV32I-NEXT: lui s5, %hi(d)
49 ; RV32I-NEXT: lui s6, %hi(e)
50 ; RV32I-NEXT: lui s7, %hi(f)
51 ; RV32I-NEXT: lui s8, %hi(g)
52 ; RV32I-NEXT: lui s9, %hi(h)
53 ; RV32I-NEXT: lui s10, %hi(c)
54 ; RV32I-NEXT: lui s11, %hi(b)
55 ; RV32I-NEXT: j .LBB0_3
56 ; RV32I-NEXT: .LBB0_2: # %for.inc
57 ; RV32I-NEXT: # in Loop: Header=BB0_3 Depth=1
58 ; RV32I-NEXT: lw a0, %lo(a)(s0)
59 ; RV32I-NEXT: addi a0, a0, -1
60 ; RV32I-NEXT: sw a0, %lo(a)(s0)
61 ; RV32I-NEXT: beqz a0, .LBB0_11
62 ; RV32I-NEXT: .LBB0_3: # %for.body
63 ; RV32I-NEXT: # =>This Inner Loop Header: Depth=1
64 ; RV32I-NEXT: lw a1, %lo(l)(s1)
65 ; RV32I-NEXT: beqz a1, .LBB0_5
66 ; RV32I-NEXT: # %bb.4: # %if.then
67 ; RV32I-NEXT: # in Loop: Header=BB0_3 Depth=1
68 ; RV32I-NEXT: lw a1, %lo(b)(s11)
69 ; RV32I-NEXT: lw a2, %lo(c)(s10)
70 ; RV32I-NEXT: lw a3, %lo(d)(s5)
71 ; RV32I-NEXT: lw a4, %lo(e)(s6)
72 ; RV32I-NEXT: li a5, 32
73 ; RV32I-NEXT: call foo
74 ; RV32I-NEXT: .LBB0_5: # %if.end
75 ; RV32I-NEXT: # in Loop: Header=BB0_3 Depth=1
76 ; RV32I-NEXT: lw a0, %lo(k)(s2)
77 ; RV32I-NEXT: beqz a0, .LBB0_7
78 ; RV32I-NEXT: # %bb.6: # %if.then3
79 ; RV32I-NEXT: # in Loop: Header=BB0_3 Depth=1
80 ; RV32I-NEXT: lw a0, %lo(b)(s11)
81 ; RV32I-NEXT: lw a1, %lo(c)(s10)
82 ; RV32I-NEXT: lw a2, %lo(d)(s5)
83 ; RV32I-NEXT: lw a3, %lo(e)(s6)
84 ; RV32I-NEXT: lw a4, %lo(f)(s7)
85 ; RV32I-NEXT: li a5, 64
86 ; RV32I-NEXT: call foo
87 ; RV32I-NEXT: .LBB0_7: # %if.end5
88 ; RV32I-NEXT: # in Loop: Header=BB0_3 Depth=1
89 ; RV32I-NEXT: lw a0, %lo(j)(s3)
90 ; RV32I-NEXT: beqz a0, .LBB0_9
91 ; RV32I-NEXT: # %bb.8: # %if.then7
92 ; RV32I-NEXT: # in Loop: Header=BB0_3 Depth=1
93 ; RV32I-NEXT: lw a0, %lo(c)(s10)
94 ; RV32I-NEXT: lw a1, %lo(d)(s5)
95 ; RV32I-NEXT: lw a2, %lo(e)(s6)
96 ; RV32I-NEXT: lw a3, %lo(f)(s7)
97 ; RV32I-NEXT: lw a4, %lo(g)(s8)
98 ; RV32I-NEXT: li a5, 32
99 ; RV32I-NEXT: call foo
100 ; RV32I-NEXT: .LBB0_9: # %if.end9
101 ; RV32I-NEXT: # in Loop: Header=BB0_3 Depth=1
102 ; RV32I-NEXT: lw a0, %lo(i)(s4)
103 ; RV32I-NEXT: beqz a0, .LBB0_2
104 ; RV32I-NEXT: # %bb.10: # %if.then11
105 ; RV32I-NEXT: # in Loop: Header=BB0_3 Depth=1
106 ; RV32I-NEXT: lw a0, %lo(d)(s5)
107 ; RV32I-NEXT: lw a1, %lo(e)(s6)
108 ; RV32I-NEXT: lw a2, %lo(f)(s7)
109 ; RV32I-NEXT: lw a3, %lo(g)(s8)
110 ; RV32I-NEXT: lw a4, %lo(h)(s9)
111 ; RV32I-NEXT: li a5, 32
112 ; RV32I-NEXT: call foo
113 ; RV32I-NEXT: j .LBB0_2
114 ; RV32I-NEXT: .LBB0_11: # %for.end
115 ; RV32I-NEXT: li a0, 1
116 ; RV32I-NEXT: lw ra, 60(sp) # 4-byte Folded Reload
117 ; RV32I-NEXT: lw s0, 56(sp) # 4-byte Folded Reload
118 ; RV32I-NEXT: lw s1, 52(sp) # 4-byte Folded Reload
119 ; RV32I-NEXT: lw s2, 48(sp) # 4-byte Folded Reload
120 ; RV32I-NEXT: lw s3, 44(sp) # 4-byte Folded Reload
121 ; RV32I-NEXT: lw s4, 40(sp) # 4-byte Folded Reload
122 ; RV32I-NEXT: lw s5, 36(sp) # 4-byte Folded Reload
123 ; RV32I-NEXT: lw s6, 32(sp) # 4-byte Folded Reload
124 ; RV32I-NEXT: lw s7, 28(sp) # 4-byte Folded Reload
125 ; RV32I-NEXT: lw s8, 24(sp) # 4-byte Folded Reload
126 ; RV32I-NEXT: lw s9, 20(sp) # 4-byte Folded Reload
127 ; RV32I-NEXT: lw s10, 16(sp) # 4-byte Folded Reload
128 ; RV32I-NEXT: lw s11, 12(sp) # 4-byte Folded Reload
129 ; RV32I-NEXT: addi sp, sp, 64
132 %.pr = load i32, ptr @a, align 4
133 %tobool14 = icmp eq i32 %.pr, 0
134 br i1 %tobool14, label %for.end, label %for.body
136 for.body: ; preds = %entry, %for.inc
137 %0 = phi i32 [ %dec, %for.inc ], [ %.pr, %entry ]
138 %1 = load i32, ptr @l, align 4
139 %tobool1 = icmp eq i32 %1, 0
140 br i1 %tobool1, label %if.end, label %if.then
142 if.then: ; preds = %for.body
143 %2 = load i32, ptr @b, align 4
144 %3 = load i32, ptr @c, align 4
145 %4 = load i32, ptr @d, align 4
146 %5 = load i32, ptr @e, align 4
147 %call = tail call i32 @foo(i32 %0, i32 %2, i32 %3, i32 %4, i32 %5, i32 32)
150 if.end: ; preds = %for.body, %if.then
151 %6 = load i32, ptr @k, align 4
152 %tobool2 = icmp eq i32 %6, 0
153 br i1 %tobool2, label %if.end5, label %if.then3
155 if.then3: ; preds = %if.end
156 %7 = load i32, ptr @b, align 4
157 %8 = load i32, ptr @c, align 4
158 %9 = load i32, ptr @d, align 4
159 %10 = load i32, ptr @e, align 4
160 %11 = load i32, ptr @f, align 4
161 %call4 = tail call i32 @foo(i32 %7, i32 %8, i32 %9, i32 %10, i32 %11, i32 64)
164 if.end5: ; preds = %if.end, %if.then3
165 %12 = load i32, ptr @j, align 4
166 %tobool6 = icmp eq i32 %12, 0
167 br i1 %tobool6, label %if.end9, label %if.then7
169 if.then7: ; preds = %if.end5
170 %13 = load i32, ptr @c, align 4
171 %14 = load i32, ptr @d, align 4
172 %15 = load i32, ptr @e, align 4
173 %16 = load i32, ptr @f, align 4
174 %17 = load i32, ptr @g, align 4
175 %call8 = tail call i32 @foo(i32 %13, i32 %14, i32 %15, i32 %16, i32 %17, i32 32)
178 if.end9: ; preds = %if.end5, %if.then7
179 %18 = load i32, ptr @i, align 4
180 %tobool10 = icmp eq i32 %18, 0
181 br i1 %tobool10, label %for.inc, label %if.then11
183 if.then11: ; preds = %if.end9
184 %19 = load i32, ptr @d, align 4
185 %20 = load i32, ptr @e, align 4
186 %21 = load i32, ptr @f, align 4
187 %22 = load i32, ptr @g, align 4
188 %23 = load i32, ptr @h, align 4
189 %call12 = tail call i32 @foo(i32 %19, i32 %20, i32 %21, i32 %22, i32 %23, i32 32)
192 for.inc: ; preds = %if.end9, %if.then11
193 %24 = load i32, ptr @a, align 4
194 %dec = add nsw i32 %24, -1
195 store i32 %dec, ptr @a, align 4
196 %tobool = icmp eq i32 %dec, 0
197 br i1 %tobool, label %for.end, label %for.body
199 for.end: ; preds = %for.inc, %entry
203 declare i32 @foo(i32, i32, i32, i32, i32, i32)