Skip to content

[RISCV][GISel] Support fcmp and fclass for Zfh. #96696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions llvm/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1146,16 +1146,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;
}
}

Expand Down Expand Up @@ -1207,7 +1207,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;

Expand Down
17 changes: 12 additions & 5 deletions llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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});

getActionDefinitionsBuilder(G_FCONSTANT)
.legalIf(typeIsScalarFPArith(0, ST))
Expand Down
1 change: 0 additions & 1 deletion llvm/lib/Target/RISCV/GISel/RISCVRegisterBankInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Copy link
Collaborator Author

@topperc topperc Jun 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deleted this assert instead of updating since getFPValueMapping has the same assert and is called a couple lines down.


OpdsMapping[0] = GPRValueMapping;
OpdsMapping[2] = OpdsMapping[3] = getFPValueMapping(Size);
Expand Down
Loading
Loading