1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -mattr=+f -target-abi=ilp32f -code-model=small -verify-machineinstrs < %s \
3 ; RUN: | FileCheck %s -check-prefix=RV32I-SMALL
4 ; RUN: llc -mtriple=riscv32 -mattr=+f -target-abi=ilp32f -code-model=medium -verify-machineinstrs < %s \
5 ; RUN: | FileCheck %s -check-prefix=RV32I-MEDIUM
7 ; Check lowering of globals
10 define i32 @lower_global(i32 %a) nounwind {
11 ; RV32I-SMALL-LABEL: lower_global:
12 ; RV32I-SMALL: # %bb.0:
13 ; RV32I-SMALL-NEXT: lui a0, %hi(G)
14 ; RV32I-SMALL-NEXT: lw a0, %lo(G)(a0)
15 ; RV32I-SMALL-NEXT: ret
17 ; RV32I-MEDIUM-LABEL: lower_global:
18 ; RV32I-MEDIUM: # %bb.0:
19 ; RV32I-MEDIUM-NEXT: .Lpcrel_hi0:
20 ; RV32I-MEDIUM-NEXT: auipc a0, %pcrel_hi(G)
21 ; RV32I-MEDIUM-NEXT: lw a0, %pcrel_lo(.Lpcrel_hi0)(a0)
22 ; RV32I-MEDIUM-NEXT: ret
23 %1 = load volatile i32, ptr @G
27 ; Check lowering of blockaddresses
29 @addr = global ptr null
31 define void @lower_blockaddress() nounwind {
32 ; RV32I-SMALL-LABEL: lower_blockaddress:
33 ; RV32I-SMALL: # %bb.0:
34 ; RV32I-SMALL-NEXT: lui a0, %hi(addr)
35 ; RV32I-SMALL-NEXT: li a1, 1
36 ; RV32I-SMALL-NEXT: sw a1, %lo(addr)(a0)
37 ; RV32I-SMALL-NEXT: ret
39 ; RV32I-MEDIUM-LABEL: lower_blockaddress:
40 ; RV32I-MEDIUM: # %bb.0:
41 ; RV32I-MEDIUM-NEXT: .Lpcrel_hi1:
42 ; RV32I-MEDIUM-NEXT: auipc a0, %pcrel_hi(addr)
43 ; RV32I-MEDIUM-NEXT: li a1, 1
44 ; RV32I-MEDIUM-NEXT: sw a1, %pcrel_lo(.Lpcrel_hi1)(a0)
45 ; RV32I-MEDIUM-NEXT: ret
46 store volatile ptr blockaddress(@lower_blockaddress, %block), ptr @addr
53 ; Check lowering of blockaddress that forces a displacement to be added
55 define signext i32 @lower_blockaddress_displ(i32 signext %w) nounwind {
56 ; RV32I-SMALL-LABEL: lower_blockaddress_displ:
57 ; RV32I-SMALL: # %bb.0: # %entry
58 ; RV32I-SMALL-NEXT: addi sp, sp, -16
59 ; RV32I-SMALL-NEXT: lui a1, %hi(.Ltmp0)
60 ; RV32I-SMALL-NEXT: addi a1, a1, %lo(.Ltmp0)
61 ; RV32I-SMALL-NEXT: li a2, 101
62 ; RV32I-SMALL-NEXT: sw a1, 8(sp)
63 ; RV32I-SMALL-NEXT: blt a0, a2, .LBB2_3
64 ; RV32I-SMALL-NEXT: # %bb.1: # %if.then
65 ; RV32I-SMALL-NEXT: lw a0, 8(sp)
66 ; RV32I-SMALL-NEXT: jr a0
67 ; RV32I-SMALL-NEXT: .Ltmp0: # Block address taken
68 ; RV32I-SMALL-NEXT: .LBB2_2: # %return
69 ; RV32I-SMALL-NEXT: li a0, 4
70 ; RV32I-SMALL-NEXT: addi sp, sp, 16
71 ; RV32I-SMALL-NEXT: ret
72 ; RV32I-SMALL-NEXT: .LBB2_3: # %return.clone
73 ; RV32I-SMALL-NEXT: li a0, 3
74 ; RV32I-SMALL-NEXT: addi sp, sp, 16
75 ; RV32I-SMALL-NEXT: ret
77 ; RV32I-MEDIUM-LABEL: lower_blockaddress_displ:
78 ; RV32I-MEDIUM: # %bb.0: # %entry
79 ; RV32I-MEDIUM-NEXT: addi sp, sp, -16
80 ; RV32I-MEDIUM-NEXT: .Lpcrel_hi2:
81 ; RV32I-MEDIUM-NEXT: auipc a1, %pcrel_hi(.Ltmp0)
82 ; RV32I-MEDIUM-NEXT: addi a1, a1, %pcrel_lo(.Lpcrel_hi2)
83 ; RV32I-MEDIUM-NEXT: li a2, 101
84 ; RV32I-MEDIUM-NEXT: sw a1, 8(sp)
85 ; RV32I-MEDIUM-NEXT: blt a0, a2, .LBB2_3
86 ; RV32I-MEDIUM-NEXT: # %bb.1: # %if.then
87 ; RV32I-MEDIUM-NEXT: lw a0, 8(sp)
88 ; RV32I-MEDIUM-NEXT: jr a0
89 ; RV32I-MEDIUM-NEXT: .Ltmp0: # Block address taken
90 ; RV32I-MEDIUM-NEXT: .LBB2_2: # %return
91 ; RV32I-MEDIUM-NEXT: li a0, 4
92 ; RV32I-MEDIUM-NEXT: addi sp, sp, 16
93 ; RV32I-MEDIUM-NEXT: ret
94 ; RV32I-MEDIUM-NEXT: .LBB2_3: # %return.clone
95 ; RV32I-MEDIUM-NEXT: li a0, 3
96 ; RV32I-MEDIUM-NEXT: addi sp, sp, 16
97 ; RV32I-MEDIUM-NEXT: ret
99 %x = alloca ptr, align 8
100 store ptr blockaddress(@lower_blockaddress_displ, %test_block), ptr %x, align 8
101 %cmp = icmp sgt i32 %w, 100
102 br i1 %cmp, label %if.then, label %if.end
105 %addr = load ptr, ptr %x, align 8
106 br label %indirectgoto
115 %retval = phi i32 [ 3, %if.end ], [ 4, %test_block ]
119 indirectbr ptr %addr, [ label %test_block ]
122 ; Check lowering of constantpools
124 define float @lower_constantpool(float %a) nounwind {
125 ; RV32I-SMALL-LABEL: lower_constantpool:
126 ; RV32I-SMALL: # %bb.0:
127 ; RV32I-SMALL-NEXT: lui a0, %hi(.LCPI3_0)
128 ; RV32I-SMALL-NEXT: flw fa5, %lo(.LCPI3_0)(a0)
129 ; RV32I-SMALL-NEXT: fadd.s fa0, fa0, fa5
130 ; RV32I-SMALL-NEXT: ret
132 ; RV32I-MEDIUM-LABEL: lower_constantpool:
133 ; RV32I-MEDIUM: # %bb.0:
134 ; RV32I-MEDIUM-NEXT: .Lpcrel_hi3:
135 ; RV32I-MEDIUM-NEXT: auipc a0, %pcrel_hi(.LCPI3_0)
136 ; RV32I-MEDIUM-NEXT: flw fa5, %pcrel_lo(.Lpcrel_hi3)(a0)
137 ; RV32I-MEDIUM-NEXT: fadd.s fa0, fa0, fa5
138 ; RV32I-MEDIUM-NEXT: ret
139 %1 = fadd float %a, 1.000244140625
143 ; Check lowering of extern_weaks
144 @W = extern_weak global i32
146 define i32 @lower_extern_weak(i32 %a) nounwind {
147 ; RV32I-SMALL-LABEL: lower_extern_weak:
148 ; RV32I-SMALL: # %bb.0:
149 ; RV32I-SMALL-NEXT: lui a0, %hi(W)
150 ; RV32I-SMALL-NEXT: lw a0, %lo(W)(a0)
151 ; RV32I-SMALL-NEXT: ret
153 ; RV32I-MEDIUM-LABEL: lower_extern_weak:
154 ; RV32I-MEDIUM: # %bb.0:
155 ; RV32I-MEDIUM-NEXT: .Lpcrel_hi4:
156 ; RV32I-MEDIUM-NEXT: auipc a0, %got_pcrel_hi(W)
157 ; RV32I-MEDIUM-NEXT: lw a0, %pcrel_lo(.Lpcrel_hi4)(a0)
158 ; RV32I-MEDIUM-NEXT: lw a0, 0(a0)
159 ; RV32I-MEDIUM-NEXT: ret
160 %1 = load volatile i32, ptr @W