[X86] Avoid usage constant -1 for fminimum/fmaximum lowering
authorSerguei Katkov <serguei.katkov@azul.com>
Thu, 4 May 2023 03:00:42 +0000 (10:00 +0700)
committerSerguei Katkov <serguei.katkov@azul.com>
Fri, 5 May 2023 09:24:33 +0000 (16:24 +0700)
commit50cd2ff7bc5af557d23fb306dddaff794e22bb01
tree7b817957c590d1794a1243aa06083f765deb01ce
parent4247806690801cba0699552b711dbfdb943d05d2
[X86] Avoid usage constant -1 for fminimum/fmaximum lowering

Instead of equality comparison of value to preferred zero we can check just
the sign of value and if sign is set we should put this value as second operand for minimum
and first operand for maximum.
In this case FMIN/FMAX will choose the right result for 0.f and -0.f comparison.

This allows us:
1. avoid loading of big 64-bit constant for fminimum.
2. for double on non-64-nib platform we need to check only high part of value.
3. test against zero to check sign takes less size of instruction

Additionally, if we know that any of value is guaranteed to be non-zero
we should not care about 0.f and -0.f comparison.

Reviewed By: e-kud
Differential Revision: https://reviews.llvm.org/D149812
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/avx512fp16-fminimum-fmaximum.ll
llvm/test/CodeGen/X86/extractelement-fp.ll
llvm/test/CodeGen/X86/fminimum-fmaximum.ll