Skip to content

Commit 35afd02

Browse files
mahesh-attardemattarde
andauthored
[X86][GlobalISel] Support G_FCMP for scalar cases (#123598)
With this patch, we are enabling comparisons for Long double (80) types on X87 stack. It lowers G_FCMP. --------- Co-authored-by: mattarde <[email protected]>
1 parent 9b8297b commit 35afd02

File tree

6 files changed

+2802
-8
lines changed

6 files changed

+2802
-8
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: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,9 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
452452

453453
// fp comparison
454454
getActionDefinitionsBuilder(G_FCMP)
455-
.legalIf([=](const LegalityQuery &Query) {
456-
return (HasSSE1 && typePairInSet(0, 1, {{s8, s32}})(Query)) ||
457-
(HasSSE2 && typePairInSet(0, 1, {{s8, s64}})(Query));
458-
})
455+
.legalFor(HasSSE1 || UseX87, {s8, s32})
456+
.legalFor(HasSSE2 || UseX87, {s8, s64})
457+
.legalFor(UseX87, {s8, s80})
459458
.clampScalar(0, s8, s8)
460459
.clampScalar(1, s32, HasSSE2 ? s64 : s32)
461460
.widenScalarToNextPow2(1);

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)