aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@sifive.com>2024-06-26 09:53:13 -0700
committerGitHub <noreply@github.com>2024-06-26 09:53:13 -0700
commitacd6cb85b3c410e88dbcc9e48733d0e1ac70eadc (patch)
tree569482264025129e4a79240137f04c93cbd2fb93 /llvm/lib
parente1015ae55d9ac729b0b0a41f4207241f8d4b2789 (diff)
downloadllvm-acd6cb85b3c410e88dbcc9e48733d0e1ac70eadc.zip
llvm-acd6cb85b3c410e88dbcc9e48733d0e1ac70eadc.tar.gz
llvm-acd6cb85b3c410e88dbcc9e48733d0e1ac70eadc.tar.bz2
[RISCV][GISel] Support fcmp and fclass for Zfh. (#96696)
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp10
-rw-r--r--llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp17
-rw-r--r--llvm/lib/Target/RISCV/GISel/RISCVRegisterBankInfo.cpp1
3 files changed, 17 insertions, 11 deletions
diff --git a/llvm/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp b/llvm/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp
index 53b2c7e..f511a20 100644
--- a/llvm/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp
+++ b/llvm/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp
@@ -1148,16 +1148,16 @@ bool RISCVInstructionSelector::selectSelect(MachineInstr &MI,
// Convert an FCMP predicate to one of the supported F or D instructions.
static unsigned getFCmpOpcode(CmpInst::Predicate Pred, unsigned Size) {
- assert((Size == 32 || Size == 64) && "Unsupported size");
+ assert((Size == 16 || Size == 32 || Size == 64) && "Unsupported size");
switch (Pred) {
default:
llvm_unreachable("Unsupported predicate");
case CmpInst::FCMP_OLT:
- return Size == 32 ? RISCV::FLT_S : RISCV::FLT_D;
+ return Size == 16 ? RISCV::FLT_H : Size == 32 ? RISCV::FLT_S : RISCV::FLT_D;
case CmpInst::FCMP_OLE:
- return Size == 32 ? RISCV::FLE_S : RISCV::FLE_D;
+ return Size == 16 ? RISCV::FLE_H : Size == 32 ? RISCV::FLE_S : RISCV::FLE_D;
case CmpInst::FCMP_OEQ:
- return Size == 32 ? RISCV::FEQ_S : RISCV::FEQ_D;
+ return Size == 16 ? RISCV::FEQ_H : Size == 32 ? RISCV::FEQ_S : RISCV::FEQ_D;
}
}
@@ -1209,7 +1209,7 @@ bool RISCVInstructionSelector::selectFPCompare(MachineInstr &MI,
Register RHS = CmpMI.getRHSReg();
unsigned Size = MRI.getType(LHS).getSizeInBits();
- assert((Size == 32 || Size == 64) && "Unexpected size");
+ assert((Size == 16 || Size == 32 || Size == 64) && "Unexpected size");
Register TmpReg = DstReg;
diff --git a/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp b/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
index 122b742..f6761ce 100644
--- a/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
+++ b/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
@@ -402,13 +402,20 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
typeIs(1, s32)(Query));
});
- getActionDefinitionsBuilder(G_FCMP)
- .legalIf(all(typeIs(0, sXLen), typeIsScalarFPArith(1, ST)))
- .clampScalar(0, sXLen, sXLen);
+ auto &FCmpActions = getActionDefinitionsBuilder(G_FCMP).legalIf(
+ all(typeIs(0, sXLen), typeIsScalarFPArith(1, ST)));
+ // TODO: Fold this into typeIsScalarFPArith.
+ if (ST.hasStdExtZfh())
+ FCmpActions.legalFor({sXLen, s16});
+ FCmpActions.clampScalar(0, sXLen, sXLen);
// TODO: Support vector version of G_IS_FPCLASS.
- getActionDefinitionsBuilder(G_IS_FPCLASS)
- .customIf(all(typeIs(0, s1), typeIsScalarFPArith(1, ST)));
+ auto &FClassActions =
+ getActionDefinitionsBuilder(G_IS_FPCLASS)
+ .customIf(all(typeIs(0, s1), typeIsScalarFPArith(1, ST)));
+ // TODO: Fold this into typeIsScalarFPArith.
+ if (ST.hasStdExtZfh())
+ FClassActions.customFor({s1, s16});
auto &FConstantActions = getActionDefinitionsBuilder(G_FCONSTANT)
.legalIf(typeIsScalarFPArith(0, ST));
diff --git a/llvm/lib/Target/RISCV/GISel/RISCVRegisterBankInfo.cpp b/llvm/lib/Target/RISCV/GISel/RISCVRegisterBankInfo.cpp
index 41ca164..d25e965 100644
--- a/llvm/lib/Target/RISCV/GISel/RISCVRegisterBankInfo.cpp
+++ b/llvm/lib/Target/RISCV/GISel/RISCVRegisterBankInfo.cpp
@@ -478,7 +478,6 @@ RISCVRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
LLT Ty = MRI.getType(MI.getOperand(2).getReg());
unsigned Size = Ty.getSizeInBits();
- assert((Size == 32 || Size == 64) && "Unsupported size for G_FCMP");
OpdsMapping[0] = GPRValueMapping;
OpdsMapping[2] = OpdsMapping[3] = getFPValueMapping(Size);