[PATCH] D61675: [WIP] Update IRBuilder::CreateFNeg(...) to return a UnaryOperator

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 15 07:15:14 PDT 2019


spatel added a comment.

In D61675#1663625 <https://reviews.llvm.org/D61675#1663625>, @cameron.mcinally wrote:

> Ping.
>
> I've been digging through this pass and it seems to be ok AFAICT.  OptimizeInst(...) canonicalizes both unary and binary FNegs to -1.0*X, if they are fast and part of a special multiply tree. Other FNegs end up as leaf nodes, so no problem there.
>
> Anyone aware of other situations I should look at?


Do we need to enhance EarlyCSE to see this equivalence:

  define float @cse_fneg(float %x, i1 %cond) {
    %fneg_unary = fneg float %x
    %fneg_binary = fsub float -0.0, %x
    %r = select i1 %cond, float %fneg_unary, float %fneg_binary
    ret float %r
  }

The binary fneg has the looser requirement for NaN propagation (IEEE-754 6.3: "this standard does not specify the sign bit of a NaN result [for math ops]"), but that's less important for optimization than knowing the 2 values are otherwise equivalent.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61675/new/

https://reviews.llvm.org/D61675





More information about the llvm-commits mailing list