[llvm] 852eb20 - [RISCV][GISel] Make register bank selection for unary and binary arithmetic ops more generic. (#87593)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 4 16:17:22 PDT 2024
Author: Craig Topper
Date: 2024-04-04T16:17:19-07:00
New Revision: 852eb20b4f091a535ef758407d8555798b0ad809
URL: https://github.com/llvm/llvm-project/commit/852eb20b4f091a535ef758407d8555798b0ad809
DIFF: https://github.com/llvm/llvm-project/commit/852eb20b4f091a535ef758407d8555798b0ad809.diff
LOG: [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.
Added:
Modified:
llvm/lib/Target/RISCV/GISel/RISCVRegisterBankInfo.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/GISel/RISCVRegisterBankInfo.cpp b/llvm/lib/Target/RISCV/GISel/RISCVRegisterBankInfo.cpp
index 8534024b6002b6..86e44343b50865 100644
--- a/llvm/lib/Target/RISCV/GISel/RISCVRegisterBankInfo.cpp
+++ b/llvm/lib/Target/RISCV/GISel/RISCVRegisterBankInfo.cpp
@@ -290,16 +290,7 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
switch (Opc) {
case TargetOpcode::G_ADD:
- case TargetOpcode::G_SUB: {
- if (MRI.getType(MI.getOperand(0).getReg()).isVector()) {
- LLT Ty = MRI.getType(MI.getOperand(0).getReg());
- return getInstructionMapping(
- DefaultMappingID, /*Cost=*/1,
- getVRBValueMapping(Ty.getSizeInBits().getKnownMinValue()),
- NumOperands);
- }
- }
- LLVM_FALLTHROUGH;
+ case TargetOpcode::G_SUB:
case TargetOpcode::G_SHL:
case TargetOpcode::G_ASHR:
case TargetOpcode::G_LSHR:
@@ -320,10 +311,6 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
case TargetOpcode::G_PTR_ADD:
case TargetOpcode::G_PTRTOINT:
case TargetOpcode::G_INTTOPTR:
- case TargetOpcode::G_SEXTLOAD:
- case TargetOpcode::G_ZEXTLOAD:
- return getInstructionMapping(DefaultMappingID, /*Cost=*/1, GPRValueMapping,
- NumOperands);
case TargetOpcode::G_FADD:
case TargetOpcode::G_FSUB:
case TargetOpcode::G_FMUL:
@@ -334,10 +321,34 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
case TargetOpcode::G_FMAXNUM:
case TargetOpcode::G_FMINNUM: {
LLT Ty = MRI.getType(MI.getOperand(0).getReg());
- return getInstructionMapping(DefaultMappingID, /*Cost=*/1,
- getFPValueMapping(Ty.getSizeInBits()),
- NumOperands);
+ TypeSize Size = Ty.getSizeInBits();
+
+ const ValueMapping *Mapping;
+ if (Ty.isVector())
+ Mapping = getVRBValueMapping(Size.getKnownMinValue());
+ else if (isPreISelGenericFloatingPointOpcode(Opc))
+ Mapping = getFPValueMapping(Size.getFixedValue());
+ else
+ Mapping = GPRValueMapping;
+
+#ifndef NDEBUG
+ // Make sure all the operands are using similar size and type.
+ for (unsigned Idx = 1; Idx != NumOperands; ++Idx) {
+ LLT OpTy = MRI.getType(MI.getOperand(Idx).getReg());
+ assert(Ty.isVector() == OpTy.isVector() &&
+ "Operand has incompatible type");
+ // Don't check size for GPR.
+ if (OpTy.isVector() || isPreISelGenericFloatingPointOpcode(Opc))
+ assert(Size == OpTy.getSizeInBits() && "Operand has incompatible size");
+ }
+#endif // End NDEBUG
+
+ return getInstructionMapping(DefaultMappingID, 1, Mapping, NumOperands);
}
+ case TargetOpcode::G_SEXTLOAD:
+ case TargetOpcode::G_ZEXTLOAD:
+ return getInstructionMapping(DefaultMappingID, /*Cost=*/1, GPRValueMapping,
+ NumOperands);
case TargetOpcode::G_IMPLICIT_DEF: {
Register Dst = MI.getOperand(0).getReg();
LLT DstTy = MRI.getType(Dst);
More information about the llvm-commits
mailing list