1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -relocation-model=pic -verify-machineinstrs < %s \
3 ; RUN: | FileCheck -check-prefixes=RV32I %s
4 ; RUN: llc -mtriple=riscv64 -relocation-model=pic -verify-machineinstrs < %s \
5 ; RUN: | FileCheck -check-prefixes=RV64I %s
7 ; Verifies that MachineLICM can hoist address generation pseudos out of loops.
9 @l = protected global i32 0, align 4
11 define void @test_lla(i32 signext %n) {
12 ; RV32I-LABEL: test_lla:
13 ; RV32I: # %bb.0: # %entry
14 ; RV32I-NEXT: li a1, 0
15 ; RV32I-NEXT: .Lpcrel_hi0:
16 ; RV32I-NEXT: auipc a2, %pcrel_hi(l)
17 ; RV32I-NEXT: .LBB0_1: # %loop
18 ; RV32I-NEXT: # =>This Inner Loop Header: Depth=1
19 ; RV32I-NEXT: lw zero, %pcrel_lo(.Lpcrel_hi0)(a2)
20 ; RV32I-NEXT: addi a1, a1, 1
21 ; RV32I-NEXT: blt a1, a0, .LBB0_1
22 ; RV32I-NEXT: # %bb.2: # %ret
25 ; RV64I-LABEL: test_lla:
26 ; RV64I: # %bb.0: # %entry
27 ; RV64I-NEXT: li a1, 0
28 ; RV64I-NEXT: .Lpcrel_hi0:
29 ; RV64I-NEXT: auipc a2, %pcrel_hi(l)
30 ; RV64I-NEXT: .LBB0_1: # %loop
31 ; RV64I-NEXT: # =>This Inner Loop Header: Depth=1
32 ; RV64I-NEXT: lw zero, %pcrel_lo(.Lpcrel_hi0)(a2)
33 ; RV64I-NEXT: addiw a1, a1, 1
34 ; RV64I-NEXT: blt a1, a0, .LBB0_1
35 ; RV64I-NEXT: # %bb.2: # %ret
41 %i = phi i32 [ %inc, %loop ], [ 0, %entry ]
42 %0 = load volatile i32, ptr @l, align 4
43 %inc = add nuw nsw i32 %i, 1
44 %cmp = icmp slt i32 %inc, %n
45 br i1 %cmp, label %loop, label %ret
51 @g = global i32 0, align 4
53 define void @test_la(i32 signext %n) {
54 ; RV32I-LABEL: test_la:
55 ; RV32I: # %bb.0: # %entry
56 ; RV32I-NEXT: .Lpcrel_hi1:
57 ; RV32I-NEXT: auipc a1, %got_pcrel_hi(g)
58 ; RV32I-NEXT: lw a1, %pcrel_lo(.Lpcrel_hi1)(a1)
59 ; RV32I-NEXT: li a2, 0
60 ; RV32I-NEXT: .LBB1_1: # %loop
61 ; RV32I-NEXT: # =>This Inner Loop Header: Depth=1
62 ; RV32I-NEXT: lw zero, 0(a1)
63 ; RV32I-NEXT: addi a2, a2, 1
64 ; RV32I-NEXT: blt a2, a0, .LBB1_1
65 ; RV32I-NEXT: # %bb.2: # %ret
68 ; RV64I-LABEL: test_la:
69 ; RV64I: # %bb.0: # %entry
70 ; RV64I-NEXT: .Lpcrel_hi1:
71 ; RV64I-NEXT: auipc a1, %got_pcrel_hi(g)
72 ; RV64I-NEXT: ld a1, %pcrel_lo(.Lpcrel_hi1)(a1)
73 ; RV64I-NEXT: li a2, 0
74 ; RV64I-NEXT: .LBB1_1: # %loop
75 ; RV64I-NEXT: # =>This Inner Loop Header: Depth=1
76 ; RV64I-NEXT: lw zero, 0(a1)
77 ; RV64I-NEXT: addiw a2, a2, 1
78 ; RV64I-NEXT: blt a2, a0, .LBB1_1
79 ; RV64I-NEXT: # %bb.2: # %ret
85 %i = phi i32 [ %inc, %loop ], [ 0, %entry ]
86 %0 = load volatile i32, ptr @g, align 4
87 %inc = add nuw nsw i32 %i, 1
88 %cmp = icmp slt i32 %inc, %n
89 br i1 %cmp, label %loop, label %ret
95 @ie = external thread_local(initialexec) global i32
97 define void @test_la_tls_ie(i32 signext %n) {
98 ; RV32I-LABEL: test_la_tls_ie:
99 ; RV32I: # %bb.0: # %entry
100 ; RV32I-NEXT: .Lpcrel_hi2:
101 ; RV32I-NEXT: auipc a1, %tls_ie_pcrel_hi(ie)
102 ; RV32I-NEXT: lw a2, %pcrel_lo(.Lpcrel_hi2)(a1)
103 ; RV32I-NEXT: li a1, 0
104 ; RV32I-NEXT: add a2, a2, tp
105 ; RV32I-NEXT: .LBB2_1: # %loop
106 ; RV32I-NEXT: # =>This Inner Loop Header: Depth=1
107 ; RV32I-NEXT: lw zero, 0(a2)
108 ; RV32I-NEXT: addi a1, a1, 1
109 ; RV32I-NEXT: blt a1, a0, .LBB2_1
110 ; RV32I-NEXT: # %bb.2: # %ret
113 ; RV64I-LABEL: test_la_tls_ie:
114 ; RV64I: # %bb.0: # %entry
115 ; RV64I-NEXT: .Lpcrel_hi2:
116 ; RV64I-NEXT: auipc a1, %tls_ie_pcrel_hi(ie)
117 ; RV64I-NEXT: ld a2, %pcrel_lo(.Lpcrel_hi2)(a1)
118 ; RV64I-NEXT: li a1, 0
119 ; RV64I-NEXT: add a2, a2, tp
120 ; RV64I-NEXT: .LBB2_1: # %loop
121 ; RV64I-NEXT: # =>This Inner Loop Header: Depth=1
122 ; RV64I-NEXT: lw zero, 0(a2)
123 ; RV64I-NEXT: addiw a1, a1, 1
124 ; RV64I-NEXT: blt a1, a0, .LBB2_1
125 ; RV64I-NEXT: # %bb.2: # %ret
131 %i = phi i32 [ %inc, %loop ], [ 0, %entry ]
132 %0 = load volatile i32, ptr @ie, align 4
133 %inc = add nuw nsw i32 %i, 1
134 %cmp = icmp slt i32 %inc, %n
135 br i1 %cmp, label %loop, label %ret
141 @gd = external thread_local global i32
143 define void @test_la_tls_gd(i32 signext %n) nounwind {
144 ; RV32I-LABEL: test_la_tls_gd:
145 ; RV32I: # %bb.0: # %entry
146 ; RV32I-NEXT: addi sp, sp, -16
147 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
148 ; RV32I-NEXT: sw s0, 8(sp) # 4-byte Folded Spill
149 ; RV32I-NEXT: sw s1, 4(sp) # 4-byte Folded Spill
150 ; RV32I-NEXT: sw s2, 0(sp) # 4-byte Folded Spill
151 ; RV32I-NEXT: mv s0, a0
152 ; RV32I-NEXT: li s2, 0
153 ; RV32I-NEXT: .Lpcrel_hi3:
154 ; RV32I-NEXT: auipc a0, %tls_gd_pcrel_hi(gd)
155 ; RV32I-NEXT: addi s1, a0, %pcrel_lo(.Lpcrel_hi3)
156 ; RV32I-NEXT: .LBB3_1: # %loop
157 ; RV32I-NEXT: # =>This Inner Loop Header: Depth=1
158 ; RV32I-NEXT: mv a0, s1
159 ; RV32I-NEXT: call __tls_get_addr
160 ; RV32I-NEXT: lw zero, 0(a0)
161 ; RV32I-NEXT: addi s2, s2, 1
162 ; RV32I-NEXT: blt s2, s0, .LBB3_1
163 ; RV32I-NEXT: # %bb.2: # %ret
164 ; RV32I-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
165 ; RV32I-NEXT: lw s0, 8(sp) # 4-byte Folded Reload
166 ; RV32I-NEXT: lw s1, 4(sp) # 4-byte Folded Reload
167 ; RV32I-NEXT: lw s2, 0(sp) # 4-byte Folded Reload
168 ; RV32I-NEXT: addi sp, sp, 16
171 ; RV64I-LABEL: test_la_tls_gd:
172 ; RV64I: # %bb.0: # %entry
173 ; RV64I-NEXT: addi sp, sp, -32
174 ; RV64I-NEXT: sd ra, 24(sp) # 8-byte Folded Spill
175 ; RV64I-NEXT: sd s0, 16(sp) # 8-byte Folded Spill
176 ; RV64I-NEXT: sd s1, 8(sp) # 8-byte Folded Spill
177 ; RV64I-NEXT: sd s2, 0(sp) # 8-byte Folded Spill
178 ; RV64I-NEXT: mv s0, a0
179 ; RV64I-NEXT: li s2, 0
180 ; RV64I-NEXT: .Lpcrel_hi3:
181 ; RV64I-NEXT: auipc a0, %tls_gd_pcrel_hi(gd)
182 ; RV64I-NEXT: addi s1, a0, %pcrel_lo(.Lpcrel_hi3)
183 ; RV64I-NEXT: .LBB3_1: # %loop
184 ; RV64I-NEXT: # =>This Inner Loop Header: Depth=1
185 ; RV64I-NEXT: mv a0, s1
186 ; RV64I-NEXT: call __tls_get_addr
187 ; RV64I-NEXT: lw zero, 0(a0)
188 ; RV64I-NEXT: addiw s2, s2, 1
189 ; RV64I-NEXT: blt s2, s0, .LBB3_1
190 ; RV64I-NEXT: # %bb.2: # %ret
191 ; RV64I-NEXT: ld ra, 24(sp) # 8-byte Folded Reload
192 ; RV64I-NEXT: ld s0, 16(sp) # 8-byte Folded Reload
193 ; RV64I-NEXT: ld s1, 8(sp) # 8-byte Folded Reload
194 ; RV64I-NEXT: ld s2, 0(sp) # 8-byte Folded Reload
195 ; RV64I-NEXT: addi sp, sp, 32
201 %i = phi i32 [ %inc, %loop ], [ 0, %entry ]
202 %0 = load volatile i32, ptr @gd, align 4
203 %inc = add nuw nsw i32 %i, 1
204 %cmp = icmp slt i32 %inc, %n
205 br i1 %cmp, label %loop, label %ret