Skip to content

Commit a56f79a

Browse files
committed
Add more cases in shouldBeInFConstantPool
1 parent a4eca16 commit a56f79a

File tree

2 files changed

+26
-30
lines changed

2 files changed

+26
-30
lines changed

llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -871,8 +871,13 @@ bool RISCVLegalizerInfo::shouldBeInConstantPool(const APInt &APImm,
871871
return !(!SeqLo.empty() && (SeqLo.size() + 2) <= STI.getMaxBuildIntsCost());
872872
}
873873

874-
bool RISCVLegalizerInfo::shouldBeInFConstantPool(const APFloat &APImm) const {
875-
if (APImm.isZero() || APImm.isExactlyValue(1.0))
874+
bool RISCVLegalizerInfo::shouldBeInFConstantPool(const APFloat &APF) const {
875+
[[maybe_unused]] unsigned Size = APF.getSizeInBits(APF.getSemantics());
876+
assert((Size == 32 || Size == 64) && "Only support f32 and f64");
877+
878+
int64_t Imm = APF.bitcastToAPInt().getSExtValue();
879+
RISCVMatInt::InstSeq Seq = RISCVMatInt::generateInstSeq(Imm, STI);
880+
if (Seq.size() <= STI.getMaxBuildIntsCost())
876881
return false;
877882
return true;
878883
}

llvm/test/CodeGen/RISCV/GlobalISel/constantpool.ll

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -112,47 +112,37 @@ define void @constpool_f64(ptr %p) {
112112
define void @constpool_f32_1234_5(ptr %p) {
113113
; RV32-SMALL-LABEL: constpool_f32_1234_5:
114114
; RV32-SMALL: # %bb.0:
115-
; RV32-SMALL-NEXT: lui a1, %hi(.LCPI2_0)
116-
; RV32-SMALL-NEXT: lw a1, %lo(.LCPI2_0)(a1)
115+
; RV32-SMALL-NEXT: lui a1, 280997
117116
; RV32-SMALL-NEXT: sw a1, 0(a0)
118117
; RV32-SMALL-NEXT: ret
119118
;
120119
; RV32-MEDIUM-LABEL: constpool_f32_1234_5:
121120
; RV32-MEDIUM: # %bb.0:
122-
; RV32-MEDIUM-NEXT: .Lpcrel_hi1:
123-
; RV32-MEDIUM-NEXT: auipc a1, %pcrel_hi(.LCPI2_0)
124-
; RV32-MEDIUM-NEXT: lw a1, %pcrel_lo(.Lpcrel_hi1)(a1)
121+
; RV32-MEDIUM-NEXT: lui a1, 280997
125122
; RV32-MEDIUM-NEXT: sw a1, 0(a0)
126123
; RV32-MEDIUM-NEXT: ret
127124
;
128125
; RV32-PIC-LABEL: constpool_f32_1234_5:
129126
; RV32-PIC: # %bb.0:
130-
; RV32-PIC-NEXT: .Lpcrel_hi1:
131-
; RV32-PIC-NEXT: auipc a1, %pcrel_hi(.LCPI2_0)
132-
; RV32-PIC-NEXT: lw a1, %pcrel_lo(.Lpcrel_hi1)(a1)
127+
; RV32-PIC-NEXT: lui a1, 280997
133128
; RV32-PIC-NEXT: sw a1, 0(a0)
134129
; RV32-PIC-NEXT: ret
135130
;
136131
; RV64-SMALL-LABEL: constpool_f32_1234_5:
137132
; RV64-SMALL: # %bb.0:
138-
; RV64-SMALL-NEXT: lui a1, %hi(.LCPI2_0)
139-
; RV64-SMALL-NEXT: lw a1, %lo(.LCPI2_0)(a1)
133+
; RV64-SMALL-NEXT: lui a1, 280997
140134
; RV64-SMALL-NEXT: sw a1, 0(a0)
141135
; RV64-SMALL-NEXT: ret
142136
;
143137
; RV64-MEDIUM-LABEL: constpool_f32_1234_5:
144138
; RV64-MEDIUM: # %bb.0:
145-
; RV64-MEDIUM-NEXT: .Lpcrel_hi0:
146-
; RV64-MEDIUM-NEXT: auipc a1, %pcrel_hi(.LCPI2_0)
147-
; RV64-MEDIUM-NEXT: lw a1, %pcrel_lo(.Lpcrel_hi0)(a1)
139+
; RV64-MEDIUM-NEXT: lui a1, 280997
148140
; RV64-MEDIUM-NEXT: sw a1, 0(a0)
149141
; RV64-MEDIUM-NEXT: ret
150142
;
151143
; RV64-PIC-LABEL: constpool_f32_1234_5:
152144
; RV64-PIC: # %bb.0:
153-
; RV64-PIC-NEXT: .Lpcrel_hi0:
154-
; RV64-PIC-NEXT: auipc a1, %pcrel_hi(.LCPI2_0)
155-
; RV64-PIC-NEXT: lw a1, %pcrel_lo(.Lpcrel_hi0)(a1)
145+
; RV64-PIC-NEXT: lui a1, 280997
156146
; RV64-PIC-NEXT: sw a1, 0(a0)
157147
; RV64-PIC-NEXT: ret
158148
store float 1.234500e+03, ptr %p
@@ -172,9 +162,9 @@ define void @constpool_f64_1234_5(ptr %p) {
172162
;
173163
; RV32-MEDIUM-LABEL: constpool_f64_1234_5:
174164
; RV32-MEDIUM: # %bb.0:
175-
; RV32-MEDIUM-NEXT: .Lpcrel_hi2:
165+
; RV32-MEDIUM-NEXT: .Lpcrel_hi1:
176166
; RV32-MEDIUM-NEXT: auipc a1, %pcrel_hi(.LCPI3_0)
177-
; RV32-MEDIUM-NEXT: addi a1, a1, %pcrel_lo(.Lpcrel_hi2)
167+
; RV32-MEDIUM-NEXT: addi a1, a1, %pcrel_lo(.Lpcrel_hi1)
178168
; RV32-MEDIUM-NEXT: lw a2, 0(a1)
179169
; RV32-MEDIUM-NEXT: lw a1, 4(a1)
180170
; RV32-MEDIUM-NEXT: sw a2, 0(a0)
@@ -183,9 +173,9 @@ define void @constpool_f64_1234_5(ptr %p) {
183173
;
184174
; RV32-PIC-LABEL: constpool_f64_1234_5:
185175
; RV32-PIC: # %bb.0:
186-
; RV32-PIC-NEXT: .Lpcrel_hi2:
176+
; RV32-PIC-NEXT: .Lpcrel_hi1:
187177
; RV32-PIC-NEXT: auipc a1, %pcrel_hi(.LCPI3_0)
188-
; RV32-PIC-NEXT: addi a1, a1, %pcrel_lo(.Lpcrel_hi2)
178+
; RV32-PIC-NEXT: addi a1, a1, %pcrel_lo(.Lpcrel_hi1)
189179
; RV32-PIC-NEXT: lw a2, 0(a1)
190180
; RV32-PIC-NEXT: lw a1, 4(a1)
191181
; RV32-PIC-NEXT: sw a2, 0(a0)
@@ -194,24 +184,25 @@ define void @constpool_f64_1234_5(ptr %p) {
194184
;
195185
; RV64-SMALL-LABEL: constpool_f64_1234_5:
196186
; RV64-SMALL: # %bb.0:
197-
; RV64-SMALL-NEXT: lui a1, %hi(.LCPI3_0)
198-
; RV64-SMALL-NEXT: ld a1, %lo(.LCPI3_0)(a1)
187+
; RV64-SMALL-NEXT: lui a1, 517
188+
; RV64-SMALL-NEXT: addi a1, a1, -1627
189+
; RV64-SMALL-NEXT: slli a1, a1, 41
199190
; RV64-SMALL-NEXT: sd a1, 0(a0)
200191
; RV64-SMALL-NEXT: ret
201192
;
202193
; RV64-MEDIUM-LABEL: constpool_f64_1234_5:
203194
; RV64-MEDIUM: # %bb.0:
204-
; RV64-MEDIUM-NEXT: .Lpcrel_hi1:
205-
; RV64-MEDIUM-NEXT: auipc a1, %pcrel_hi(.LCPI3_0)
206-
; RV64-MEDIUM-NEXT: ld a1, %pcrel_lo(.Lpcrel_hi1)(a1)
195+
; RV64-MEDIUM-NEXT: lui a1, 517
196+
; RV64-MEDIUM-NEXT: addi a1, a1, -1627
197+
; RV64-MEDIUM-NEXT: slli a1, a1, 41
207198
; RV64-MEDIUM-NEXT: sd a1, 0(a0)
208199
; RV64-MEDIUM-NEXT: ret
209200
;
210201
; RV64-PIC-LABEL: constpool_f64_1234_5:
211202
; RV64-PIC: # %bb.0:
212-
; RV64-PIC-NEXT: .Lpcrel_hi1:
213-
; RV64-PIC-NEXT: auipc a1, %pcrel_hi(.LCPI3_0)
214-
; RV64-PIC-NEXT: ld a1, %pcrel_lo(.Lpcrel_hi1)(a1)
203+
; RV64-PIC-NEXT: lui a1, 517
204+
; RV64-PIC-NEXT: addi a1, a1, -1627
205+
; RV64-PIC-NEXT: slli a1, a1, 41
215206
; RV64-PIC-NEXT: sd a1, 0(a0)
216207
; RV64-PIC-NEXT: ret
217208
store double 1.234500e+03, ptr %p

0 commit comments

Comments
 (0)