<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Feb 23, 2020 at 11:41 AM Roman Lebedev <<a href="mailto:lebedev.ri@gmail.com">lebedev.ri@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Sun, Feb 23, 2020 at 7:37 PM Sanjay Patel via llvm-commits<br>
<<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br>
><br>
><br>
> Author: Sanjay Patel<br>
> Date: 2020-02-23T11:36:53-05:00<br>
> New Revision: a253a2a793cda34d1f6421ee9b7ca76a03fdfc59<br>
><br>
> URL: <a href="https://github.com/llvm/llvm-project/commit/a253a2a793cda34d1f6421ee9b7ca76a03fdfc59" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/a253a2a793cda34d1f6421ee9b7ca76a03fdfc59</a><br>
> DIFF: <a href="https://github.com/llvm/llvm-project/commit/a253a2a793cda34d1f6421ee9b7ca76a03fdfc59.diff" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/a253a2a793cda34d1f6421ee9b7ca76a03fdfc59.diff</a><br>
><br>
> LOG: [SDAG] fold fsub -0.0, undef to undef rather than NaN<br>
><br>
> A question about this behavior came up on llvm-dev:<br>
> <a href="http://lists.llvm.org/pipermail/llvm-dev/2020-February/139003.html" rel="noreferrer" target="_blank">http://lists.llvm.org/pipermail/llvm-dev/2020-February/139003.html</a><br>
> ...and as part of backend improvements in D73978.<br>
<br>
> We decided not to implement a more general change that would have<br>
> folded any FP binop with nearly arbitrary constant + undef operand<br>
> to undef because that is not theoretically correct (even if it is<br>
> practically correct).<br>
This is a bit too pessimistic. Alive experiments show that it would be fine<br>
in general at least for the fsub, as long as we don't have NaN's<br></blockquote><div><br></div>Maybe I'm not seeing it correctly. We said this:<br>    fsub float 4.000000, undef --> undef<br><br>...is invalid in D74713, and that's independent of "nnan". Ie, we can't produce some tiny number like a denormal given a known constant like "4.0". So it would be wrong to say the output is fully undef - there is some range of values that can never be produced given (just about?) any fixed FP constant and any of the FP opcodes.<br><div><br></div><div><br></div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> This is the SDAG-equivalent to the IR change in D74713.<br>
><br>
> Added:<br>
><br>
><br>
> Modified:<br>
>     llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp<br>
>     llvm/test/CodeGen/X86/vec_fneg.ll<br>
><br>
> Removed:<br>
><br>
><br>
><br>
> ################################################################################<br>
> diff  --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp<br>
> index e809816d68be..d2db4bccc3ac 100644<br>
> --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp<br>
> +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp<br>
> @@ -5112,8 +5112,13 @@ SDValue SelectionDAG::foldConstantFPMath(unsigned Opcode, const SDLoc &DL,<br>
>    }<br>
><br>
>    switch (Opcode) {<br>
> -  case ISD::FADD:<br>
>    case ISD::FSUB:<br>
> +    // -0.0 - undef --> undef (consistent with "fneg undef")<br>
> +    if (N1CFP && N1CFP->getValueAPF().isNegZero() && N2.isUndef())<br>
> +      return getUNDEF(VT);<br>
> +    LLVM_FALLTHROUGH;<br>
> +<br>
> +  case ISD::FADD:<br>
>    case ISD::FMUL:<br>
>    case ISD::FDIV:<br>
>    case ISD::FREM:<br>
><br>
> diff  --git a/llvm/test/CodeGen/X86/vec_fneg.ll b/llvm/test/CodeGen/X86/vec_fneg.ll<br>
> index 4d5539feef3c..c3c1932c2311 100644<br>
> --- a/llvm/test/CodeGen/X86/vec_fneg.ll<br>
> +++ b/llvm/test/CodeGen/X86/vec_fneg.ll<br>
> @@ -76,12 +76,10 @@ define <4 x float> @fneg_undef(<4 x float> %Q) nounwind {<br>
>  define <4 x float> @fsub_neg0_undef_elts_undef(<4 x float> %x) {<br>
>  ; X32-SSE-LABEL: fsub_neg0_undef_elts_undef:<br>
>  ; X32-SSE:       # %bb.0:<br>
> -; X32-SSE-NEXT:    movaps {{.*#+}} xmm0 = <NaN,u,u,NaN><br>
>  ; X32-SSE-NEXT:    retl<br>
>  ;<br>
>  ; X64-SSE-LABEL: fsub_neg0_undef_elts_undef:<br>
>  ; X64-SSE:       # %bb.0:<br>
> -; X64-SSE-NEXT:    movaps {{.*#+}} xmm0 = <NaN,u,u,NaN><br>
>  ; X64-SSE-NEXT:    retq<br>
>    %r = fsub <4 x float> <float -0.0, float undef, float undef, float -0.0>, undef<br>
>    ret <4 x float> %r<br>
><br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div>