This is an archive of the discontinued LLVM Phabricator instance.

[X86][FP16] Optimize FMAXNUM/FMINNUM into SMAX/SMIN for FP16 emulation under fast math
Changes PlannedPublic

Authored by pengfei on Mar 12 2023, 4:42 AM.

Details

Summary

We don't need to promote it to f32 FMAXNUM/FMINNUM if we can make sure
no NaN in inputs.

Fixes #61271

Diff Detail

Event Timeline

pengfei created this revision.Mar 12 2023, 4:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 12 2023, 4:42 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
pengfei requested review of this revision.Mar 12 2023, 4:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 12 2023, 4:42 AM
RKSimon added inline comments.Mar 12 2023, 5:02 AM
llvm/lib/Target/X86/X86ISelLowering.cpp
53165

We might need to improve soft float test coverage?

llvm/test/CodeGen/X86/half.ll
1368

It seems a shame to scalarize this when we're already on the FPU, and we have pminsw/pmaxsw since SSE2

pengfei updated this revision to Diff 504425.Mar 12 2023, 6:11 AM

Address review commnets.

llvm/lib/Target/X86/X86ISelLowering.cpp
53165

Good catch! I didn't intend to support soft float. And IIRC, we have problems in supporting soft float. So bail it out.

llvm/test/CodeGen/X86/half.ll
1368

Good point! We can vectorize it first, though we still need to improve the f16 extract.

LuoYuanke added inline comments.Mar 12 2023, 5:03 PM
llvm/lib/Target/X86/X86ISelLowering.cpp
53175

I forget the encoding of exponent. Is the result same for min(vXf16) and min(i16)?

pengfei planned changes to this revision.Mar 12 2023, 5:46 PM

The negative comparison is not correct.

llvm/lib/Target/X86/X86ISelLowering.cpp
53175

Thanks for the reminding. Review it again, I found it is only correct to positive value. The reason is FP is represented in Sign-Magnitude while integer is 2’s Complement Code. Let me try to think out some way to solve it.

Matt added a subscriber: Matt.Aug 9 2023, 3:52 PM