Skip to content

Commit 852eb20

Browse files
authored
[RISCV][GISel] Make register bank selection for unary and binary arithmetic ops more generic. (#87593)
This is inspired by AArch64's getSameKindOfOperandsMapping, but based on what RISC-V currently needs. This removes the special vector case for G_ADD/SUB and unifies integer and FP operations into the same handler. G_SEXTLOAD/ZEXTLOAD have been separated from integer since they should only be scalar integer and never vector.
1 parent 96a99a5 commit 852eb20

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

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

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -290,16 +290,7 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
290290

291291
switch (Opc) {
292292
case TargetOpcode::G_ADD:
293-
case TargetOpcode::G_SUB: {
294-
if (MRI.getType(MI.getOperand(0).getReg()).isVector()) {
295-
LLT Ty = MRI.getType(MI.getOperand(0).getReg());
296-
return getInstructionMapping(
297-
DefaultMappingID, /*Cost=*/1,
298-
getVRBValueMapping(Ty.getSizeInBits().getKnownMinValue()),
299-
NumOperands);
300-
}
301-
}
302-
LLVM_FALLTHROUGH;
293+
case TargetOpcode::G_SUB:
303294
case TargetOpcode::G_SHL:
304295
case TargetOpcode::G_ASHR:
305296
case TargetOpcode::G_LSHR:
@@ -320,10 +311,6 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
320311
case TargetOpcode::G_PTR_ADD:
321312
case TargetOpcode::G_PTRTOINT:
322313
case TargetOpcode::G_INTTOPTR:
323-
case TargetOpcode::G_SEXTLOAD:
324-
case TargetOpcode::G_ZEXTLOAD:
325-
return getInstructionMapping(DefaultMappingID, /*Cost=*/1, GPRValueMapping,
326-
NumOperands);
327314
case TargetOpcode::G_FADD:
328315
case TargetOpcode::G_FSUB:
329316
case TargetOpcode::G_FMUL:
@@ -334,10 +321,34 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
334321
case TargetOpcode::G_FMAXNUM:
335322
case TargetOpcode::G_FMINNUM: {
336323
LLT Ty = MRI.getType(MI.getOperand(0).getReg());
337-
return getInstructionMapping(DefaultMappingID, /*Cost=*/1,
338-
getFPValueMapping(Ty.getSizeInBits()),
339-
NumOperands);
324+
TypeSize Size = Ty.getSizeInBits();
325+
326+
const ValueMapping *Mapping;
327+
if (Ty.isVector())
328+
Mapping = getVRBValueMapping(Size.getKnownMinValue());
329+
else if (isPreISelGenericFloatingPointOpcode(Opc))
330+
Mapping = getFPValueMapping(Size.getFixedValue());
331+
else
332+
Mapping = GPRValueMapping;
333+
334+
#ifndef NDEBUG
335+
// Make sure all the operands are using similar size and type.
336+
for (unsigned Idx = 1; Idx != NumOperands; ++Idx) {
337+
LLT OpTy = MRI.getType(MI.getOperand(Idx).getReg());
338+
assert(Ty.isVector() == OpTy.isVector() &&
339+
"Operand has incompatible type");
340+
// Don't check size for GPR.
341+
if (OpTy.isVector() || isPreISelGenericFloatingPointOpcode(Opc))
342+
assert(Size == OpTy.getSizeInBits() && "Operand has incompatible size");
343+
}
344+
#endif // End NDEBUG
345+
346+
return getInstructionMapping(DefaultMappingID, 1, Mapping, NumOperands);
340347
}
348+
case TargetOpcode::G_SEXTLOAD:
349+
case TargetOpcode::G_ZEXTLOAD:
350+
return getInstructionMapping(DefaultMappingID, /*Cost=*/1, GPRValueMapping,
351+
NumOperands);
341352
case TargetOpcode::G_IMPLICIT_DEF: {
342353
Register Dst = MI.getOperand(0).getReg();
343354
LLT DstTy = MRI.getType(Dst);

0 commit comments

Comments
 (0)