Skip to content

Conversation

@huhu233
Copy link
Contributor

@huhu233 huhu233 commented Oct 20, 2023

No description provided.

@huhu233
Copy link
Contributor Author

huhu233 commented Oct 20, 2023

Similar to #67552

@huhu233 huhu233 requested review from RKSimon, arsenm and nikic October 24, 2023 13:39
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing avx512 checks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Supplement the check, thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

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

no need to create a method - just make it static inside X86ISelLowering.cpp

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

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

We'd be much better off adding a X86ISD::SCALEF nodetype rather than individual intrinsic lowering cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, @RKSimon, sorry for the delay in replying your comments, I have made some changes to the patch, please have a check, thanks very much!

@huhu233
Copy link
Contributor Author

huhu233 commented Dec 13, 2023

  • Rebase the branch
  • Use X86ISD::SCALEFS instead of specific intrinsics
  • Transfrom the function into static version
  • update the test file

@huhu233 huhu233 requested a review from RKSimon December 13, 2023 12:14
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use the single line style like (most of) the previous cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems that coding style check discourages this change ...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you need to vectorize to use SCALEFS? I thought SCALEFS was for scalar types and SCALEF was for vector types? (So it should be possible to add vector support here as well).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use vscalefph if we have AVX512FP16?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Contributor Author

@huhu233 huhu233 Dec 14, 2023

Choose a reason for hiding this comment

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

Hi, there may be risk of truncation, as the EXP operand of FLDEXP types i32, e.g., @llvm.ldexp.f16.i32(half, i32) ->@llvm.x86.avx512fp16.mask.scalef.sh(<8 x half>, <8 x half>, <8 x half>. I didn't know how to handle the issue elegantly, so I made an extension here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point! LangRef doesn't give an example f16 case. Should we define it as @llvm.ldexp.f16.i16(half, i16)? i32 is a too large range to be useful for FP16.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we use value tracking to check the bounds of the EXP operand?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Value tracking seems to make things very complicated.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd settle for a TODO comment for now

@RKSimon RKSimon requested a review from phoebewang December 13, 2023 16:02
@nikic nikic removed their request for review December 14, 2023 08:31
@github-actions
Copy link

github-actions bot commented Dec 14, 2023

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff e34c35a21ccc215ce507a1e19b4ff2a1ce9906f3 4ac55f1aecf19b4e2ce981ad757c79b0daf46e5e -- llvm/lib/Target/X86/X86ISelLowering.cpp
View the diff from clang-format here.
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 19510bbba0..7ac39cea21 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -2406,11 +2406,11 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
   }
 
   if (Subtarget.hasAVX512()) {
-    for (MVT VT : { MVT::f16, MVT::f32, MVT::f64, MVT::v4f32, MVT::v2f64 })
+    for (MVT VT : {MVT::f16, MVT::f32, MVT::f64, MVT::v4f32, MVT::v2f64})
       setOperationAction(ISD::FLDEXP, VT, Custom);
 
     if (Subtarget.hasVLX())
-      for (MVT VT : { MVT::v8f32, MVT::v4f64, MVT::v16f32, MVT::v8f64 })
+      for (MVT VT : {MVT::v8f32, MVT::v4f64, MVT::v16f32, MVT::v8f64})
         setOperationAction(ISD::FLDEXP, VT, Custom);
   }
 
@@ -32039,7 +32039,8 @@ SDValue X86TargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
   case ISD::ADDRSPACECAST:      return LowerADDRSPACECAST(Op, DAG);
   case X86ISD::CVTPS2PH:        return LowerCVTPS2PH(Op, DAG);
   case ISD::PREFETCH:           return LowerPREFETCH(Op, Subtarget, DAG);
-  case ISD::FLDEXP:             return LowerFLDEXP(Op, Subtarget, DAG);
+  case ISD::FLDEXP:
+    return LowerFLDEXP(Op, Subtarget, DAG);
   }
 }
 

@huhu233
Copy link
Contributor Author

huhu233 commented Dec 14, 2023

  • Fix coding style issues
  • Support vector versions of ldexp, e.g., @llvm.ldexp.v8f32.v8i32 -- +avx512vl , @llvm.ldexp.v4f32.v4i32 -- +avx512f or +avx512vl, etc.

@huhu233
Copy link
Contributor Author

huhu233 commented Dec 15, 2023

  • add TODO for avx512fp16

@huhu233 huhu233 requested a review from RKSimon December 27, 2023 06:25
}

if (Subtarget.hasAVX512()) {
for (MVT VT : { MVT::f16, MVT::f32, MVT::f64, MVT::v4f32, MVT::v2f64 })
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we sure this is right? I'd expect MVT::v4f32, MVT::v2f64, MVT::v8f32, MVT::v4f64 to be the VLX cases.

; AVX512VL-NEXT: vpinsrw $0, %eax, %xmm0, %xmm0
; AVX512VL-NEXT: retq
entry:
%r = tail call fast half @llvm.ldexp.f16.i32(half %x, i32 %exp)
Copy link
Contributor

Choose a reason for hiding this comment

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

Drop unnecessary fast flags?

@RKSimon
Copy link
Collaborator

RKSimon commented Apr 3, 2024

@huhu233 reverse-ping

@Andarwinux
Copy link
Contributor

Any progress on this PR?

@RKSimon
Copy link
Collaborator

RKSimon commented Oct 30, 2025

Closing this abandoned PR and adding a issue (#165694) to track future work - I'll add the test coverage from this patch to trunk so we have something to work from.

@RKSimon RKSimon closed this Oct 30, 2025
RKSimon added a commit to RKSimon/llvm-project that referenced this pull request Oct 30, 2025
Pulled out of the abandoned patch llvm#69710 to act as a baseline for llvm#165694
RKSimon added a commit that referenced this pull request Oct 30, 2025
Pulled out of the abandoned patch #69710 to act as a baseline for #165694
aokblast pushed a commit to aokblast/llvm-project that referenced this pull request Oct 30, 2025
Pulled out of the abandoned patch llvm#69710 to act as a baseline for llvm#165694
luciechoi pushed a commit to luciechoi/llvm-project that referenced this pull request Nov 1, 2025
Pulled out of the abandoned patch llvm#69710 to act as a baseline for llvm#165694
DEBADRIBASAK pushed a commit to DEBADRIBASAK/llvm-project that referenced this pull request Nov 3, 2025
Pulled out of the abandoned patch llvm#69710 to act as a baseline for llvm#165694
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.

6 participants