Skip to content
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

[X86][GlobalISel] Support G_FCMP for scalar cases #123598

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
16 changes: 14 additions & 2 deletions llvm/lib/Target/X86/GISel/X86InstructionSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1048,17 +1048,29 @@ bool X86InstructionSelector::selectFCmp(MachineInstr &I,
break;
}

assert((LhsReg.isVirtual() && RhsReg.isVirtual()) &&
"Both arguments of FCMP need to be virtual!");
auto *LhsBank = RBI.getRegBank(LhsReg, MRI, TRI);
auto *RhsBank = RBI.getRegBank(RhsReg, MRI, TRI);
assert((LhsBank == RhsBank) &&
"Both banks assigned to FCMP arguments need to be same!");

// Compute the opcode for the CMP instruction.
unsigned OpCmp;
LLT Ty = MRI.getType(LhsReg);
switch (Ty.getSizeInBits()) {
default:
return false;
case 32:
OpCmp = X86::UCOMISSrr;
OpCmp = LhsBank->getID() == X86::PSRRegBankID ? X86::UCOM_FpIr32
: X86::UCOMISSrr;
break;
case 64:
OpCmp = X86::UCOMISDrr;
OpCmp = LhsBank->getID() == X86::PSRRegBankID ? X86::UCOM_FpIr64
: X86::UCOMISDrr;
break;
case 80:
OpCmp = X86::UCOM_FpIr80;
break;
}

Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,8 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
getActionDefinitionsBuilder(G_FCMP)
.legalIf([=](const LegalityQuery &Query) {
return (HasSSE1 && typePairInSet(0, 1, {{s8, s32}})(Query)) ||
(HasSSE2 && typePairInSet(0, 1, {{s8, s64}})(Query));
(HasSSE2 && typePairInSet(0, 1, {{s8, s64}})(Query)) ||
(UseX87 && typePairInSet(0, 1, {{s8, s80}})(Query));
})
.clampScalar(0, s8, s8)
.clampScalar(1, s32, HasSSE2 ? s64 : s32)
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/X86/GISel/X86RegisterBankInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ X86RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {

unsigned Size = Ty1.getSizeInBits();
(void)Size;
assert((Size == 32 || Size == 64) && "Unsupported size for G_FCMP");

assert((Size == 32 || Size == 64 || Size == 80) &&
"Unsupported size for G_FCMP");
auto FpRegBank = getPartialMappingIdx(MI, Ty1, /* isFP= */ true);
OpRegBankIdx = {PMI_GPR8,
/* Predicate */ PMI_None, FpRegBank, FpRegBank};
Expand Down
Loading
Loading