[llvm-dev] Reading FP Environment status from IR

Kevin Neal via llvm-dev llvm-dev at lists.llvm.org
Thu May 6 12:11:26 PDT 2021


I'd use the clang -ffp-exception-behavior=strict or =maytrap options instead of the #pragma. I'm not convinced the #pragma always works correctly and emits the correct metadata for constrained intrinsics. It's OK for now, but I'm working on optimizations for LLVM that rely on correct metadata. You'll get correct metadata with the command line option.

The first phab ticket for optimizations is https://reviews.llvm.org/D99962 with more on the way. It's an EarlyCSE change. If anyone wants to jump in as a reviewer I won't mind at all.
--
Kevin P. Neal
SAS/C and SAS/C++ Compiler
Compute Services
SAS Institute, Inc.



From: llvm-dev <llvm-dev-bounces at lists.llvm.org> On Behalf Of Craig Topper via llvm-dev
Sent: Thursday, May 06, 2021 12:21 PM
To: raghesh <raghesh.a at gmail.com>
Cc: LLVM Developers Mailing List <llvm-dev at lists.llvm.org>
Subject: Re: [llvm-dev] Reading FP Environment status from IR


EXTERNAL
We have intrinsic versions of the floating point instructions to suppress optimizations that are unsafe when exceptions are enabled. https://llvm.org/docs/LangRef.html#constrained-floating-point-intrinsics<https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fllvm.org%2Fdocs%2FLangRef.html%23constrained-floating-point-intrinsics&data=04%7C01%7Ckevin.neal%40sas.com%7Cd622922160e84ec9c41008d910aafdc9%7Cb1c14d5c362545b3a4309552373a0c2f%7C0%7C0%7C637559148851625050%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=b60qxgBEfIpp62incxubaK1xEs6cWeWgpKkmisjMGTk%3D&reserved=0> Currently I think it prevents nearly all optimizations.

Clang should emit these for some targets like X86 when it sees #pragma STDC FENV_ACCESS. Clang can only do this for targets that have implemented proper support for the constrained intrinsics in the backend.

~Craig


On Thu, May 6, 2021 at 2:26 AM raghesh via llvm-dev <llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>> wrote:
Hi All,

We would like to prevent certain optimizations (like hoisting an fdiv instruction) when the application has set the floating point environment flags using APIs like
feraiseexcept<https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fen.cppreference.com%2Fw%2Fcpp%2Fnumeric%2Ffenv%2Fferaiseexcept&data=04%7C01%7Ckevin.neal%40sas.com%7Cd622922160e84ec9c41008d910aafdc9%7Cb1c14d5c362545b3a4309552373a0c2f%7C0%7C0%7C637559148851635040%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=N8Sz1j3JxqmKxr4xKnuO8MMIKWJBYNI8e%2BXDVte6qE4%3D&reserved=0>  or if it uses  #pragma STDC FENV_ACCESS<https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fen.cppreference.com%2Fw%2Fcpp%2Fpreprocessor%2Fimpl&data=04%7C01%7Ckevin.neal%40sas.com%7Cd622922160e84ec9c41008d910aafdc9%7Cb1c14d5c362545b3a4309552373a0c2f%7C0%7C0%7C637559148851635040%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=84tVDGwyemDXatkCuZPfDn8%2B1ltRnEVr5uk%2Bh%2Fcu9%2FI%3D&reserved=0>.

Is there any way to know this at LLVM-IR level?

Regards,
Raghesh
------------------------------
Raghesh Aloor
AMD India Pvt. Ltd.
Bengaluru.
------------------------------
_______________________________________________
LLVM Developers mailing list
llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.llvm.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fllvm-dev&data=04%7C01%7Ckevin.neal%40sas.com%7Cd622922160e84ec9c41008d910aafdc9%7Cb1c14d5c362545b3a4309552373a0c2f%7C0%7C0%7C637559148851645051%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=8NMTYgvFNS9%2FlNTiAXcMfm%2BvEf7McmR%2BOoJa8T7%2BQnw%3D&reserved=0>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210506/dc6c157d/attachment.html>


More information about the llvm-dev mailing list