-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[X86][GlobalIsel] support G_FABS #136718
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_FABS #136718
Changes from 9 commits
d4475cb
22e2c83
0ed32a7
8221bc6
6a58699
db0e1cb
f35b674
2782568
860903d
d4d3d44
4838b22
63eebe0
a718a5b
e57ab03
f5e5274
ac44b20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -466,6 +466,10 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI, | |
| (UseX87 && typeInSet(0, {s80})(Query)); | ||
| }); | ||
|
|
||
| getActionDefinitionsBuilder(G_FABS) | ||
| .legalFor(UseX87 && !HasSSE2, {s32, s64, s80}) | ||
| .custom(); | ||
|
|
||
| // fp comparison | ||
| getActionDefinitionsBuilder(G_FCMP) | ||
| .legalFor(HasSSE1 || UseX87, {s8, s32}) | ||
|
|
@@ -669,6 +673,8 @@ bool X86LegalizerInfo::legalizeCustom(LegalizerHelper &Helper, MachineInstr &MI, | |
| return legalizeSITOFP(MI, MRI, Helper); | ||
| case TargetOpcode::G_FPTOSI: | ||
| return legalizeFPTOSI(MI, MRI, Helper); | ||
| case TargetOpcode::G_FABS: | ||
| return legalizeFAbs(MI, MRI, Helper); | ||
| } | ||
| llvm_unreachable("expected switch to return"); | ||
| } | ||
|
|
@@ -835,6 +841,43 @@ bool X86LegalizerInfo::legalizeNarrowingStore(MachineInstr &MI, | |
| return true; | ||
| } | ||
|
|
||
| bool X86LegalizerInfo::legalizeFAbs(MachineInstr &MI, | ||
| MachineRegisterInfo &MRI, | ||
| LegalizerHelper &Helper) const { | ||
|
|
||
| MachineIRBuilder &MIRBuilder = Helper.MIRBuilder; | ||
| Register SrcReg = MI.getOperand(1).getReg(); | ||
| Register DstReg = MI.getOperand(0).getReg(); | ||
| LLT Ty = MRI.getType(DstReg); | ||
| if (Subtarget.is32Bit()) { | ||
|
||
| // Reset sign bit | ||
| MIRBuilder.buildAnd( | ||
| DstReg, SrcReg, | ||
| MIRBuilder.buildConstant( | ||
| Ty, APInt::getSignedMaxValue(Ty.getScalarSizeInBits()))); | ||
| } else { | ||
| // In 64 bit mode, constant pool is used. | ||
| auto &MF = MIRBuilder.getMF(); | ||
| Type *IRTy = getTypeForLLT(Ty, MF.getFunction().getContext()); | ||
| Constant *ConstMask = ConstantInt::get( | ||
| IRTy, APInt::getSignedMaxValue(Ty.getScalarSizeInBits())); | ||
| LLT DstTy = MRI.getType(DstReg); | ||
| const DataLayout &DL = MIRBuilder.getDataLayout(); | ||
| unsigned AddrSpace = DL.getDefaultGlobalsAddressSpace(); | ||
| Align Alignment(DL.getABITypeAlign( | ||
| getTypeForLLT(DstTy, MF.getFunction().getContext()))); | ||
| auto Addr = MIRBuilder.buildConstantPool( | ||
| LLT::pointer(AddrSpace, DL.getPointerSizeInBits(AddrSpace)), | ||
| MF.getConstantPool()->getConstantPoolIndex(ConstMask, Alignment)); | ||
| MachineMemOperand *MMO = | ||
| MF.getMachineMemOperand(MachinePointerInfo::getConstantPool(MF), | ||
| MachineMemOperand::MOLoad, DstTy, Alignment); | ||
| auto LoadedMask = MIRBuilder.buildLoad(DstTy, Addr, *MMO); | ||
| MIRBuilder.buildAnd(DstReg, SrcReg, LoadedMask); | ||
| } | ||
| MI.eraseFromParent(); | ||
| return true; | ||
| } | ||
| bool X86LegalizerInfo::legalizeIntrinsic(LegalizerHelper &Helper, | ||
| MachineInstr &MI) const { | ||
| return true; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,10 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 | ||
| ; RUN: llc < %s -mtriple=x86_64-- -mattr=+x87,-sse2,-sse | FileCheck %s --check-prefixes=X64 | ||
| ; RUN: llc < %s -mtriple=x86_64-- -mattr=+x87,-sse2,-sse -fast-isel -fast-isel-abort=1 | FileCheck %s --check-prefixes=X64 | ||
| ; RUN: llc < %s -mtriple=x86_64-- -mattr=+x87,-sse2,-sse -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=X64 | ||
| ; RUN: llc < %s -mtriple=i686-- -mattr=+x87,-sse2,-sse | FileCheck %s --check-prefixes=X86 | ||
| ; RUN: llc < %s -mtriple=i686-- -mattr=+x87,-sse2,-sse -fast-isel -fast-isel-abort=1 | FileCheck %s --check-prefixes=X86 | ||
| ; RUN: llc < %s -mtriple=i686-- -mattr=+x87,-sse2,-sse -global-isel -global-isel-abort=1 | FileCheck %s --check-prefixes=X86 | ||
|
||
|
|
||
| define x86_fp80 @test_x86_fp80_abs(x86_fp80 %arg) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably would be nice to see how we handle floats and double without SSE. |
||
| ; X64-LABEL: test_x86_fp80_abs: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format this ?