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][LegalizeDAG] FPOWI: promote f16 operand #105775

Merged

Conversation

v01dXYZ
Copy link
Contributor

@v01dXYZ v01dXYZ commented Aug 23, 2024

Fixes #105747

@llvmbot
Copy link
Member

llvmbot commented Aug 23, 2024

@llvm/pr-subscribers-backend-x86

Author: None (v01dXYZ)

Changes

Fixes #105747


Full diff: https://github.com/llvm/llvm-project/pull/105775.diff

1 Files Affected:

  • (modified) llvm/lib/Target/X86/X86ISelLowering.cpp (+1)
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index e0face6b6a7904..83bb2577777864 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -614,6 +614,7 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
     setOperationAction(ISD::FTAN, VT, Action);
     setOperationAction(ISD::FSQRT, VT, Action);
     setOperationAction(ISD::FPOW, VT, Action);
+    setOperationAction(ISD::FPOWI, VT, Action);
     setOperationAction(ISD::FLOG, VT, Action);
     setOperationAction(ISD::FLOG2, VT, Action);
     setOperationAction(ISD::FLOG10, VT, Action);

@phoebewang
Copy link
Contributor

Add a test case for it?

@v01dXYZ
Copy link
Contributor Author

v01dXYZ commented Aug 23, 2024

@phoebewang Hi, I hesitate between putting this test in CodeGen/Generic or in CodeGen/X86 b/c some other targets may show the same problem.

I'll put it in CodeGen/X86 as this one won't break the buildbot builds.

@phoebewang
Copy link
Contributor

CodeGen/X86 since you changed the X86 backend code rather than generic code. Besides, some targets may have the test already.

@v01dXYZ
Copy link
Contributor Author

v01dXYZ commented Aug 23, 2024

I discovered something strange with FEXPR/f16. It expands it (when looking at the code it seems rather it converts it to a same sized integer type) instead of promoting it.

BTW the reason I'm looking into that is because that's another Opcode with a default value set to Expand in TargetLoweringBase.cpp and not mentionned in X86ISelLowering.cpp.

@v01dXYZ
Copy link
Contributor Author

v01dXYZ commented Aug 23, 2024

There is something I don't understand in TargetLoweringBase, some default operation actions are Expand but what does it mean to Expand with types that are already the smallest ones possible (in our case, that's f16).

Copy link
Collaborator

@RKSimon RKSimon left a comment

Choose a reason for hiding this comment

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

Add a test case (probably to avx512fp16-scalar.ll ?)

RKSimon added a commit that referenced this pull request Aug 23, 2024
…tion

We can add additional tests in the future, but this is an initial placeholder

Inspired by #105775
@RKSimon
Copy link
Collaborator

RKSimon commented Aug 23, 2024

Add a test case (probably to avx512fp16-scalar.ll ?)

I've added fp16-libcalls.ll which should give us better test coverage - please add the powi tests there

cjdb pushed a commit to cjdb/llvm-project that referenced this pull request Aug 23, 2024
…tion

We can add additional tests in the future, but this is an initial placeholder

Inspired by llvm#105775
5chmidti pushed a commit that referenced this pull request Aug 24, 2024
…tion

We can add additional tests in the future, but this is an initial placeholder

Inspired by #105775
@v01dXYZ v01dXYZ force-pushed the 105747-x86-SD-legalise-dag-fpowi-f16-promote branch from 374c8d8 to 80246e0 Compare August 26, 2024 08:34
@v01dXYZ
Copy link
Contributor Author

v01dXYZ commented Aug 26, 2024

I was worried than another Opcode presented the same problem (ie with LegalizeAction defaulting to Expand and spawning an assert when LegalizeDAG fallthroughs to libcall convertion). But it seems FPOWI is special, that's the only float Opcode in ConvertNodeToLibcall that checks for the libcall existence and if it does not exist fallbacks to using FPOW.

I have a vocabulary question: in the strict terminology of Legalisation, expand means breaking up a complex operation using smaller types, should I rather think of it as an Instruction Expand ?

@v01dXYZ v01dXYZ force-pushed the 105747-x86-SD-legalise-dag-fpowi-f16-promote branch from 80246e0 to 1710821 Compare August 26, 2024 09:12
RKSimon added a commit that referenced this pull request Aug 28, 2024
@RKSimon
Copy link
Collaborator

RKSimon commented Aug 28, 2024

I have a vocabulary question: in the strict terminology of Legalisation, expand means breaking up a complex operation using smaller types, should I rather think of it as an Instruction Expand ?

It depends on what legalization stage you're dealing with - expand to legal type / scalarize / split into simpler instructions etc.

I've added more tests to fp16-libcalls.ll - please can you rebase?

v01dxyz added 2 commits August 28, 2024 14:41
Instead of defaulting to Expand.

Warning: The added test case fails with asserts enabled.
Instead of defaulting to Expand.

Without that, since Expand is not implemented for FPOWI, it
fallthroughs to Libcall. As there are no f16 libcalls, the program
aborts when asserts are enabled.
@v01dXYZ v01dXYZ force-pushed the 105747-x86-SD-legalise-dag-fpowi-f16-promote branch from 1710821 to 56673ee Compare August 28, 2024 12:50
Copy link
Collaborator

@RKSimon RKSimon left a comment

Choose a reason for hiding this comment

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

LGTM

@RKSimon RKSimon merged commit ecd9e0b into llvm:main Aug 28, 2024
8 checks passed
5c4lar pushed a commit to 5c4lar/llvm-project that referenced this pull request Aug 29, 2024
5c4lar pushed a commit to 5c4lar/llvm-project that referenced this pull request Aug 29, 2024
dmpolukhin pushed a commit to dmpolukhin/llvm-project that referenced this pull request Sep 2, 2024
…tion

We can add additional tests in the future, but this is an initial placeholder

Inspired by llvm#105775
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SelectionDAGLegalize crash with assertions on powi.f16/powi.f16.i32
4 participants