[cfe-dev] Documentation on -ffp-contract=fast vs pragma contract(off)

Marius Hillenbrand via cfe-dev cfe-dev at lists.llvm.org
Wed Sep 23 07:53:09 PDT 2020


Hi,

The documentation of the #pragma clang fp contract appears to
misrepresent the interaction of -ffp-contract=fast with the #pragma
clang fp contract(off). The documentation states:

> The pragma can also be used with off which turns FP contraction off for a section of the code. This can be useful when fast contraction is otherwise enabled for the translation unit with the -ffp-contract=fast flag.

(https://clang.llvm.org/docs/LanguageExtensions.html#extensions-to-specify-floating-point-flags)


However, a minimal example contradicts that:

float abc_pragma_off(float a, float b, float c) {
#pragma clang fp contract(off)
	return a * b + c;
}

... is compiled to a fused multiply-add:
$ clang -o - -S -march=haswell -O3 -ffp-contract=fast min.c

abc_pragma_off:
  vfmadd213ss	%xmm2, %xmm1, %xmm0 # xmm0 = (xmm1 * xmm0) + xmm2
  retq

In my understanding, setting -ffp-contract=fast allows the backend to
always contract FP operations. Since setting the pragma to off only
controls clang's frontend and the pragma is not expressed in the IR, it
cannot override the backend's behavior.

If clang behaves as designed in that case, I think we should fix the
documentation, along the lines of

"The pragma can also be used with off which turns FP contraction off for
a section of the code. Note that if fast contraction is enabled for a
translation unit with the flag -ffp-contract=fast then using the pragma
with off will have not effect".

Marius
-- 
Marius Hillenbrand
Linux on Z development
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Gregor Pillen / Geschäftsführung: Dirk
Wittkopp
Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht
Stuttgart, HRB 243294


More information about the cfe-dev mailing list