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)
28 ; RV32I-NEXT: sw s0, 56(sp)
29 ; RV32I-NEXT: sw s1, 52(sp)
30 ; RV32I-NEXT: sw s2, 48(sp)
31 ; RV32I-NEXT: sw s3, 44(sp)
32 ; RV32I-NEXT: sw s4, 40(sp)
33 ; RV32I-NEXT: sw s5, 36(sp)
34 ; RV32I-NEXT: sw s6, 32(sp)
35 ; RV32I-NEXT: sw s7, 28(sp)
36 ; RV32I-NEXT: sw s8, 24(sp)
37 ; RV32I-NEXT: sw s9, 20(sp)
38 ; RV32I-NEXT: sw s10, 16(sp)
39 ; RV32I-NEXT: sw s11, 12(sp)
40 ; RV32I-NEXT: lui s6, %hi(a)
41 ; RV32I-NEXT: lw a0, %lo(a)(s6)
42 ; RV32I-NEXT: beqz a0, .LBB0_11
43 ; RV32I-NEXT: # %bb.1: # %for.body.preheader
44 ; RV32I-NEXT: lui s2, %hi(l)
45 ; RV32I-NEXT: lui s3, %hi(k)
46 ; RV32I-NEXT: lui s4, %hi(j)
47 ; RV32I-NEXT: lui s5, %hi(i)
48 ; RV32I-NEXT: lui s1, %hi(d)
49 ; RV32I-NEXT: lui s0, %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: lw a1, %lo(l)(s2)
56 ; RV32I-NEXT: bnez a1, .LBB0_4
57 ; RV32I-NEXT: j .LBB0_5
58 ; RV32I-NEXT: .LBB0_2: # %for.inc
59 ; RV32I-NEXT: # in Loop: Header=BB0_5 Depth=1
60 ; RV32I-NEXT: lw a0, %lo(a)(s6)
61 ; RV32I-NEXT: addi a0, a0, -1
62 ; RV32I-NEXT: sw a0, %lo(a)(s6)
63 ; RV32I-NEXT: beqz a0, .LBB0_11
64 ; RV32I-NEXT: # %bb.3: # %for.body
65 ; RV32I-NEXT: # in Loop: Header=BB0_5 Depth=1
66 ; RV32I-NEXT: lw a1, %lo(l)(s2)
67 ; RV32I-NEXT: beqz a1, .LBB0_5
68 ; RV32I-NEXT: .LBB0_4: # %if.then
69 ; RV32I-NEXT: lw a1, %lo(b)(s11)
70 ; RV32I-NEXT: lw a2, %lo(c)(s10)
71 ; RV32I-NEXT: lw a3, %lo(d)(s1)
72 ; RV32I-NEXT: lw a4, %lo(e)(s0)
73 ; RV32I-NEXT: addi a5, zero, 32
74 ; RV32I-NEXT: call foo
75 ; RV32I-NEXT: .LBB0_5: # %if.end
76 ; RV32I-NEXT: # =>This Inner Loop Header: Depth=1
77 ; RV32I-NEXT: lw a0, %lo(k)(s3)
78 ; RV32I-NEXT: beqz a0, .LBB0_7
79 ; RV32I-NEXT: # %bb.6: # %if.then3
80 ; RV32I-NEXT: # in Loop: Header=BB0_5 Depth=1
81 ; RV32I-NEXT: lw a0, %lo(b)(s11)
82 ; RV32I-NEXT: lw a1, %lo(c)(s10)
83 ; RV32I-NEXT: lw a2, %lo(d)(s1)
84 ; RV32I-NEXT: lw a3, %lo(e)(s0)
85 ; RV32I-NEXT: lw a4, %lo(f)(s7)
86 ; RV32I-NEXT: addi a5, zero, 64
87 ; RV32I-NEXT: call foo
88 ; RV32I-NEXT: .LBB0_7: # %if.end5
89 ; RV32I-NEXT: # in Loop: Header=BB0_5 Depth=1
90 ; RV32I-NEXT: lw a0, %lo(j)(s4)
91 ; RV32I-NEXT: beqz a0, .LBB0_9
92 ; RV32I-NEXT: # %bb.8: # %if.then7
93 ; RV32I-NEXT: # in Loop: Header=BB0_5 Depth=1
94 ; RV32I-NEXT: lw a0, %lo(c)(s10)
95 ; RV32I-NEXT: lw a1, %lo(d)(s1)
96 ; RV32I-NEXT: lw a2, %lo(e)(s0)
97 ; RV32I-NEXT: lw a3, %lo(f)(s7)
98 ; RV32I-NEXT: lw a4, %lo(g)(s8)
99 ; RV32I-NEXT: addi a5, zero, 32
100 ; RV32I-NEXT: call foo
101 ; RV32I-NEXT: .LBB0_9: # %if.end9
102 ; RV32I-NEXT: # in Loop: Header=BB0_5 Depth=1
103 ; RV32I-NEXT: lw a0, %lo(i)(s5)
104 ; RV32I-NEXT: beqz a0, .LBB0_2
105 ; RV32I-NEXT: # %bb.10: # %if.then11
106 ; RV32I-NEXT: # in Loop: Header=BB0_5 Depth=1
107 ; RV32I-NEXT: lw a0, %lo(d)(s1)
108 ; RV32I-NEXT: lw a1, %lo(e)(s0)
109 ; RV32I-NEXT: lw a2, %lo(f)(s7)
110 ; RV32I-NEXT: lw a3, %lo(g)(s8)
111 ; RV32I-NEXT: lw a4, %lo(h)(s9)
112 ; RV32I-NEXT: addi a5, zero, 32
113 ; RV32I-NEXT: call foo
114 ; RV32I-NEXT: j .LBB0_2
115 ; RV32I-NEXT: .LBB0_11: # %for.end
116 ; RV32I-NEXT: addi a0, zero, 1
117 ; RV32I-NEXT: lw s11, 12(sp)
118 ; RV32I-NEXT: lw s10, 16(sp)
119 ; RV32I-NEXT: lw s9, 20(sp)
120 ; RV32I-NEXT: lw s8, 24(sp)
121 ; RV32I-NEXT: lw s7, 28(sp)
122 ; RV32I-NEXT: lw s6, 32(sp)
123 ; RV32I-NEXT: lw s5, 36(sp)
124 ; RV32I-NEXT: lw s4, 40(sp)
125 ; RV32I-NEXT: lw s3, 44(sp)
126 ; RV32I-NEXT: lw s2, 48(sp)
127 ; RV32I-NEXT: lw s1, 52(sp)
128 ; RV32I-NEXT: lw s0, 56(sp)
129 ; RV32I-NEXT: lw ra, 60(sp)
130 ; RV32I-NEXT: addi sp, sp, 64
133 %.pr = load i32, i32* @a, align 4
134 %tobool14 = icmp eq i32 %.pr, 0
135 br i1 %tobool14, label %for.end, label %for.body
137 for.body: ; preds = %entry, %for.inc
138 %0 = phi i32 [ %dec, %for.inc ], [ %.pr, %entry ]
139 %1 = load i32, i32* @l, align 4
140 %tobool1 = icmp eq i32 %1, 0
141 br i1 %tobool1, label %if.end, label %if.then
143 if.then: ; preds = %for.body
144 %2 = load i32, i32* @b, align 4
145 %3 = load i32, i32* @c, align 4
146 %4 = load i32, i32* @d, align 4
147 %5 = load i32, i32* @e, align 4
148 %call = tail call i32 @foo(i32 %0, i32 %2, i32 %3, i32 %4, i32 %5, i32 32) #3
151 if.end: ; preds = %for.body, %if.then
152 %6 = load i32, i32* @k, align 4
153 %tobool2 = icmp eq i32 %6, 0
154 br i1 %tobool2, label %if.end5, label %if.then3
156 if.then3: ; preds = %if.end
157 %7 = load i32, i32* @b, align 4
158 %8 = load i32, i32* @c, align 4
159 %9 = load i32, i32* @d, align 4
160 %10 = load i32, i32* @e, align 4
161 %11 = load i32, i32* @f, align 4
162 %call4 = tail call i32 @foo(i32 %7, i32 %8, i32 %9, i32 %10, i32 %11, i32 64) #3
165 if.end5: ; preds = %if.end, %if.then3
166 %12 = load i32, i32* @j, align 4
167 %tobool6 = icmp eq i32 %12, 0
168 br i1 %tobool6, label %if.end9, label %if.then7
170 if.then7: ; preds = %if.end5
171 %13 = load i32, i32* @c, align 4
172 %14 = load i32, i32* @d, align 4
173 %15 = load i32, i32* @e, align 4
174 %16 = load i32, i32* @f, align 4
175 %17 = load i32, i32* @g, align 4
176 %call8 = tail call i32 @foo(i32 %13, i32 %14, i32 %15, i32 %16, i32 %17, i32 32) #3
179 if.end9: ; preds = %if.end5, %if.then7
180 %18 = load i32, i32* @i, align 4
181 %tobool10 = icmp eq i32 %18, 0
182 br i1 %tobool10, label %for.inc, label %if.then11
184 if.then11: ; preds = %if.end9
185 %19 = load i32, i32* @d, align 4
186 %20 = load i32, i32* @e, align 4
187 %21 = load i32, i32* @f, align 4
188 %22 = load i32, i32* @g, align 4
189 %23 = load i32, i32* @h, align 4
190 %call12 = tail call i32 @foo(i32 %19, i32 %20, i32 %21, i32 %22, i32 %23, i32 32) #3
193 for.inc: ; preds = %if.end9, %if.then11
194 %24 = load i32, i32* @a, align 4
195 %dec = add nsw i32 %24, -1
196 store i32 %dec, i32* @a, align 4
197 %tobool = icmp eq i32 %dec, 0
198 br i1 %tobool, label %for.end, label %for.body
200 for.end: ; preds = %for.inc, %entry
204 declare i32 @foo(i32, i32, i32, i32, i32, i32)