1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 02:33:06 +01:00

[SDAG] fold fsub -0.0, undef to undef rather than NaN

A question about this behavior came up on llvm-dev:
http://lists.llvm.org/pipermail/llvm-dev/2020-February/139003.html
...and as part of backend improvements in D73978.

We decided not to implement a more general change that would have
folded any FP binop with nearly arbitrary constant + undef operand
to undef because that is not theoretically correct (even if it is
practically correct).

This is the SDAG-equivalent to the IR change in D74713.
This commit is contained in:
Sanjay Patel 2020-02-23 11:26:28 -05:00
parent d3ea77fff6
commit 63607bdd89
2 changed files with 6 additions and 3 deletions

View File

@ -5112,8 +5112,13 @@ SDValue SelectionDAG::foldConstantFPMath(unsigned Opcode, const SDLoc &DL,
}
switch (Opcode) {
case ISD::FADD:
case ISD::FSUB:
// -0.0 - undef --> undef (consistent with "fneg undef")
if (N1CFP && N1CFP->getValueAPF().isNegZero() && N2.isUndef())
return getUNDEF(VT);
LLVM_FALLTHROUGH;
case ISD::FADD:
case ISD::FMUL:
case ISD::FDIV:
case ISD::FREM:

View File

@ -76,12 +76,10 @@ define <4 x float> @fneg_undef(<4 x float> %Q) nounwind {
define <4 x float> @fsub_neg0_undef_elts_undef(<4 x float> %x) {
; X32-SSE-LABEL: fsub_neg0_undef_elts_undef:
; X32-SSE: # %bb.0:
; X32-SSE-NEXT: movaps {{.*#+}} xmm0 = <NaN,u,u,NaN>
; X32-SSE-NEXT: retl
;
; X64-SSE-LABEL: fsub_neg0_undef_elts_undef:
; X64-SSE: # %bb.0:
; X64-SSE-NEXT: movaps {{.*#+}} xmm0 = <NaN,u,u,NaN>
; X64-SSE-NEXT: retq
%r = fsub <4 x float> <float -0.0, float undef, float undef, float -0.0>, undef
ret <4 x float> %r