[PATCH] D80416: [RFC][OpenCL] Set fp contract flag on -cl-mad-enable

Anastasia Stulova via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 22 08:01:45 PDT 2020


Anastasia marked an inline comment as done.
Anastasia added inline comments.


================
Comment at: clang/test/CodeGenOpenCL/relaxed-fpmath.cl:21
+float fused_mad(float a, float b, float c) {
+  // NORMAL: @llvm.fmuladd.f32
+  // FAST: fmul fast float
----------------
Anastasia wrote:
> Anastasia wrote:
> > Anastasia wrote:
> > > I don't find this behavior "NORMAL". I don't believe we should contract expressions by default in OpenCL...
> > I just found in table 38 of OpenCL C spec, last entry says:
> > 
> > 
> > > x * y + z
> > > Implemented either as a correctly rounded fma or as a multiply and an add both of which are correctly rounded.
> > 
> > In table 8 for `fma` it states:
> > 
> > > Returns the correctly rounded floating-point representation of the sum of c with the infinitely precise product of a and b. Rounding of intermediate products shall not occur. 
> > 
> > 
> > When I check LLVM doecumentation for fmuladd it says:
> > 
> > > is equivalent to the expression a * b + c, except that it is unspecified whether rounding will be performed between the multiplication and addition steps. Fusion is not guaranteed, even if the target platform supports it. If a fused multiply-add is required, the corresponding llvm.fma intrinsic function should be used instead. This never sets errno, just as ‘llvm.fma.*’.
> > 
> > Does this mean that rounding of an intermediate product may occur and therefore it is not safe to use it for OpenCL mode by default?
> > 
> After more digging I conclude that the use of `fmuladd` for `x * y + z` should be ok as per table 38 of OpenCL C because it allows either fused or non-fused operation i.e. it is ok if either intermediate value is rounded or not.
I changed my mind again. This is now covered by https://reviews.llvm.org/D80440.


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

https://reviews.llvm.org/D80416





More information about the cfe-commits mailing list