[PATCH] D75982: [DAGCombine] Respect the uses when combine FMA for a*b+/-c*d and add target hook if there uses are the same

qshanz via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 11 07:24:42 PDT 2020


steven.zhang added a comment.

In D75982#1916780 <https://reviews.llvm.org/D75982#1916780>, @lebedev.ri wrote:

> > If their uses are the same, add a target hook to allow some platform such as PowerPC to make the choice, as it has different precisions between these two folding which is caused by round a*b or c*d.
> >  In PowerPC, we have some floating precision quite sensitive libraries that depend on the slightly difference between rounding a*b or c*d. So, we need some way to control the behavior of this combine.
>
> To me that sounds like strict floating point semantics should be used there?


I have no idea if llvm has suitable flag to indicate this semantics, and if yes, that would be great to guard it under some flag instead of the target hook. Do you have any suggestions ?

The precision difference is caused by follows to make the semantics clear(pls ignore this if you have understood it from the patch description):

  // current implementation
  x = a*b - c*d
  -->
  t = c*d; (rounding happens)
  x = a*b - t  (fma(a,b, -t))
  
  // another folding is:
  x = a*b - c*d
  -->
  t = a*b (rounding happens)
  x = t - c*d (fma(-c, d, t)

It is UB on evaluating which operand first for expression "lhs op rhs". Now, llvm prefer evaluating the rhs first for this case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75982





More information about the llvm-commits mailing list