Skip to content

Commit 8f283ca

Browse files
committed
[AArch64][GlobalISel] Add selection support for fpr bank source variants of G_SITOFP and G_UITOFP.
In order to import patterns for these, we need to define new ops that can map to the AArch64ISD::[SU]ITOF nodes. We then transform fpr->fpr variants of the generic opcodes to these custom opcodes in preisel-lowering. We have to do it here and not the PostLegalizer combiner because this has to run after regbankselect. Differential Revision: https://reviews.llvm.org/D94702
1 parent 1fabe6e commit 8f283ca

File tree

3 files changed

+76
-2
lines changed

3 files changed

+76
-2
lines changed

llvm/lib/Target/AArch64/AArch64InstrGISel.td

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@ def G_VLSHR : AArch64GenericInstruction {
146146
let InOperandList = (ins type0:$src1, untyped_imm_0:$imm);
147147
}
148148

149+
// Represents an integer to FP conversion on the FPR bank.
150+
def G_SITOF : AArch64GenericInstruction {
151+
let OutOperandList = (outs type0:$dst);
152+
let InOperandList = (ins type0:$src);
153+
}
154+
def G_UITOF : AArch64GenericInstruction {
155+
let OutOperandList = (outs type0:$dst);
156+
let InOperandList = (ins type0:$src);
157+
}
158+
149159
def : GINodeEquiv<G_REV16, AArch64rev16>;
150160
def : GINodeEquiv<G_REV32, AArch64rev32>;
151161
def : GINodeEquiv<G_REV64, AArch64rev64>;
@@ -163,6 +173,8 @@ def : GINodeEquiv<G_TRN2, AArch64trn2>;
163173
def : GINodeEquiv<G_EXT, AArch64ext>;
164174
def : GINodeEquiv<G_VASHR, AArch64vashr>;
165175
def : GINodeEquiv<G_VLSHR, AArch64vlshr>;
176+
def : GINodeEquiv<G_SITOF, AArch64sitof>;
177+
def : GINodeEquiv<G_UITOF, AArch64uitof>;
166178

167179
def : GINodeEquiv<G_EXTRACT_VECTOR_ELT, vector_extract>;
168180

llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,6 +1941,24 @@ bool AArch64InstructionSelector::preISelLower(MachineInstr &I) {
19411941
I.getOperand(1).setReg(NewSrc.getReg(0));
19421942
return true;
19431943
}
1944+
case TargetOpcode::G_UITOFP:
1945+
case TargetOpcode::G_SITOFP: {
1946+
// If both source and destination regbanks are FPR, then convert the opcode
1947+
// to G_SITOF so that the importer can select it to an fpr variant.
1948+
// Otherwise, it ends up matching an fpr/gpr variant and adding a cross-bank
1949+
// copy.
1950+
Register SrcReg = I.getOperand(1).getReg();
1951+
if (MRI.getType(SrcReg).isVector())
1952+
return false;
1953+
if (RBI.getRegBank(SrcReg, MRI, TRI)->getID() == AArch64::FPRRegBankID) {
1954+
if (I.getOpcode() == TargetOpcode::G_SITOFP)
1955+
I.setDesc(TII.get(AArch64::G_SITOF));
1956+
else
1957+
I.setDesc(TII.get(AArch64::G_UITOF));
1958+
return true;
1959+
}
1960+
return false;
1961+
}
19441962
default:
19451963
return false;
19461964
}

llvm/test/CodeGen/AArch64/GlobalISel/select-fp-casts.mir

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ body: |
218218
...
219219

220220
---
221-
name: sitofp_s32_s32_fpr
221+
name: sitofp_s32_s32_fpr_gpr
222222
legalized: true
223223
regBankSelected: true
224224

@@ -230,7 +230,7 @@ body: |
230230
bb.0:
231231
liveins: $w0
232232
233-
; CHECK-LABEL: name: sitofp_s32_s32_fpr
233+
; CHECK-LABEL: name: sitofp_s32_s32_fpr_gpr
234234
; CHECK: [[COPY:%[0-9]+]]:gpr32 = COPY $w0
235235
; CHECK: [[SCVTFUWSri:%[0-9]+]]:fpr32 = SCVTFUWSri [[COPY]]
236236
; CHECK: $s0 = COPY [[SCVTFUWSri]]
@@ -239,6 +239,50 @@ body: |
239239
$s0 = COPY %1(s32)
240240
...
241241

242+
---
243+
name: sitofp_s32_s32_fpr_fpr
244+
legalized: true
245+
regBankSelected: true
246+
247+
registers:
248+
- { id: 0, class: fpr }
249+
- { id: 1, class: fpr }
250+
251+
body: |
252+
bb.0:
253+
liveins: $s0
254+
255+
; CHECK-LABEL: name: sitofp_s32_s32_fpr_fpr
256+
; CHECK: [[COPY:%[0-9]+]]:fpr32 = COPY $s0
257+
; CHECK: [[SCVTFv1i32:%[0-9]+]]:fpr32 = SCVTFv1i32 [[COPY]]
258+
; CHECK: $s0 = COPY [[SCVTFv1i32]]
259+
%0(s32) = COPY $s0
260+
%1(s32) = G_SITOFP %0
261+
$s0 = COPY %1(s32)
262+
...
263+
264+
---
265+
name: uitofp_s32_s32_fpr_fpr
266+
legalized: true
267+
regBankSelected: true
268+
269+
registers:
270+
- { id: 0, class: fpr }
271+
- { id: 1, class: fpr }
272+
273+
body: |
274+
bb.0:
275+
liveins: $s0
276+
277+
; CHECK-LABEL: name: uitofp_s32_s32_fpr_fpr
278+
; CHECK: [[COPY:%[0-9]+]]:fpr32 = COPY $s0
279+
; CHECK: [[UCVTFv1i32:%[0-9]+]]:fpr32 = UCVTFv1i32 [[COPY]]
280+
; CHECK: $s0 = COPY [[UCVTFv1i32]]
281+
%0(s32) = COPY $s0
282+
%1(s32) = G_UITOFP %0
283+
$s0 = COPY %1(s32)
284+
...
285+
242286
---
243287
name: sitofp_s32_s64_fpr
244288
legalized: true

0 commit comments

Comments
 (0)