Skip to content

Commit 94c3fca

Browse files
author
mattarde
committed
Support G_FCMP for scalar cases
1 parent a79ae86 commit 94c3fca

File tree

4 files changed

+1072
-5
lines changed

4 files changed

+1072
-5
lines changed

llvm/lib/Target/X86/GISel/X86InstructionSelector.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,17 +1048,29 @@ bool X86InstructionSelector::selectFCmp(MachineInstr &I,
10481048
break;
10491049
}
10501050

1051+
assert((LhsReg.isVirtual() && RhsReg.isVirtual()) &&
1052+
"Both arguments of FCMP need to be virtual!");
1053+
auto *LhsBank = RBI.getRegBank(LhsReg, MRI, TRI);
1054+
auto *RhsBank = RBI.getRegBank(RhsReg, MRI, TRI);
1055+
assert((LhsBank == RhsBank) &&
1056+
"Both banks assigned to FCMP arguments need to be same!");
1057+
10511058
// Compute the opcode for the CMP instruction.
10521059
unsigned OpCmp;
10531060
LLT Ty = MRI.getType(LhsReg);
10541061
switch (Ty.getSizeInBits()) {
10551062
default:
10561063
return false;
10571064
case 32:
1058-
OpCmp = X86::UCOMISSrr;
1065+
OpCmp = LhsBank->getID() == X86::PSRRegBankID ? X86::UCOM_FpIr32
1066+
: X86::UCOMISSrr;
10591067
break;
10601068
case 64:
1061-
OpCmp = X86::UCOMISDrr;
1069+
OpCmp = LhsBank->getID() == X86::PSRRegBankID ? X86::UCOM_FpIr64
1070+
: X86::UCOMISDrr;
1071+
break;
1072+
case 80:
1073+
OpCmp = X86::UCOM_FpIr80;
10621074
break;
10631075
}
10641076

llvm/lib/Target/X86/GISel/X86LegalizerInfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,8 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
450450
getActionDefinitionsBuilder(G_FCMP)
451451
.legalIf([=](const LegalityQuery &Query) {
452452
return (HasSSE1 && typePairInSet(0, 1, {{s8, s32}})(Query)) ||
453-
(HasSSE2 && typePairInSet(0, 1, {{s8, s64}})(Query));
453+
(HasSSE2 && typePairInSet(0, 1, {{s8, s64}})(Query)) ||
454+
(UseX87 && typePairInSet(0, 1, {{s8, s80}})(Query));
454455
})
455456
.clampScalar(0, s8, s8)
456457
.clampScalar(1, s32, HasSSE2 ? s64 : s32)

llvm/lib/Target/X86/GISel/X86RegisterBankInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,8 @@ X86RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
321321

322322
unsigned Size = Ty1.getSizeInBits();
323323
(void)Size;
324-
assert((Size == 32 || Size == 64) && "Unsupported size for G_FCMP");
325-
324+
assert((Size == 32 || Size == 64 || Size == 80) &&
325+
"Unsupported size for G_FCMP");
326326
auto FpRegBank = getPartialMappingIdx(MI, Ty1, /* isFP= */ true);
327327
OpRegBankIdx = {PMI_GPR8,
328328
/* Predicate */ PMI_None, FpRegBank, FpRegBank};

0 commit comments

Comments
 (0)