[llvm-dev] ffp-model=fast ignores #pragma STDC FP_CONTRACT OFF
Kaylor, Andrew via llvm-dev
llvm-dev at lists.llvm.org
Tue Oct 26 09:38:13 PDT 2021
A bug has been filed about this: https://bugs.llvm.org/show_bug.cgi?id=39679
On the other hand, a change was made to add a new setting, fast-honor-pragmas, to the -ffp-contract option (though it doesn't seem to work from the command line) and document the current behavior: https://reviews.llvm.org/D90174
I've brought this up before and I feel very strongly that the pragma should be honored even when fp-contract=fast is used on the command line. The current behavior depends on a communication channel outside the IR, which is bad. The argument has been made in the past that ignoring the pragma is consistent with gcc behavior, but gcc doesn't support the pragma at all, so I don't think that's a very strong argument.
There are tests in llvm-test-suite, which fail when FMA is performed, and without the pragma being respected, the only practical way to force the tests to pass with fast-math enabled is to override the option and set fp-contract=off for these tests. If the pragma were respected, we'd be able to have these tests use two kernels -- one with FMA enabled for performance measurements, and one with FMA disabled to provide a baseline for results verification. Here's an example of such a test: https://github.com/llvm/llvm-test-suite/tree/main/SingleSource/Benchmarks/Polybench/linear-algebra/kernels/3mm The CMakeLists.txt and Makefile for this test have been modified to force fp-contract=off, but there is code in the test that would perform a relative error comparison if the pragma could be relied upon.
I would like to build a consensus, for or against, changing the current behavior. If you care about this either way, please respond.
Thanks,
Andy
From: Ammarguellat, Zahira <zahira.ammarguellat at intel.com>
Sent: Tuesday, October 26, 2021 6:10 AM
To: cfe-dev at lists.llvm.org
Cc: Kaylor, Andrew <andrew.kaylor at intel.com>
Subject: ffp-model=fast ignores #pragma STDC FP_CONTRACT OFF
Hi All,
Using option ffp-model=fast and #pragma STDC FP_CONTRACT OFF doesn't have the expected clang's behavior of pragmas.
See for example https://godbolt.org/z/PYYd5zd4Pthis The pragma is honored; FMA instructions are generated following the option and are suppressed as directed by the pragma at codegen.
In contrast, https://godbolt.org/z/WvvaKrv1b shows that the option -ffp-model=fast is honored in the FE, but the pragma is ignored. The LLVM IR generated is correct, but codegen doesn't honor the pragma as expected. Although this seems to be "historically" (codegen didn't used to get fast-math flags so a global option was used; now codegen sees these flags) the pragma should be honored. This should be filed as a bug.
Thoughts?
Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20211026/e191fa82/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.gif
Type: image/gif
Size: 69751 bytes
Desc: image002.gif
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20211026/e191fa82/attachment-0001.gif>
More information about the llvm-dev
mailing list