[PATCH] D82778: [InstCombine] fma x, y, 0 -> fmul x, y

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 29 11:54:17 PDT 2020


spatel added a comment.

In D82778#2120456 <https://reviews.llvm.org/D82778#2120456>, @dmgreen wrote:

> I think it's because of these ones:
>
>   fma(+0, -x, 0) -> +0
>  
>   fmul(+0, -x) -> -0
>   fadd(+0, -0) -> +0
>
>
> Removing the fadd would leave it at -0.


Right - we need 'nsz' to fold adding +0.0 (I think this patch is correct as-is).

We can also always fold fma(x, y, -0.0) --> fmul x, y because (this is in InstSimplify):
fadd X, -0 ==> X

But I can't get the online version of Alive2 to confirm that (time-out). Local version should verify it?
If we don't have tests for the add of -0.0 variant, it would be good to add them for the likely follow-on patch.



================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp:2385-2387
+      auto *FMul = BinaryOperator::CreateFMul(Src0, Src1);
+      FMul->copyFastMathFlags(II);
+      return FMul;
----------------
Can reduce this to something like:
  return BinaryOperator::CreateFMulFMF(Src0, Src1, II);


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

https://reviews.llvm.org/D82778





More information about the llvm-commits mailing list