[clang] Disable FTZ/DAZ when compiling shared libraries by default. (PR #80475)

Joshua Cranmer via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 9 10:09:56 PST 2024


jcranmer-intel wrote:

> > > I'd like to see this change land, but with the "-mdaz-ftz" option removed (because I don't think it's useful). That would fix the critical problem of fast-math infecting shared libraries with the ftz setting, and we could straighten out the other problems, which are relatively minor, afterwards.
> > 
> > 
> > There is, without this change, no way to control whether or not `crtfastmath.o` is linked independent of all of the other fast-math options. The `-mdaz-ftz` option would at least add a flag to explicitly control the parameter (for the people who care), and we can then have discussions about different ways to effect setting DAZ/FTZ bits or what options imply `-mdaz-ftz` in future PRs. That alone makes it a worthy addition IMHO; the compatibility with gcc is another nice feature.
> 
> You can always link crtfastmath.o directly, of course. Ultimately, I don't think the compiler should ever be adding the crtfastmath.o file. I would prefer to insert code directly into the entry function as @arsenm indicated the AMDGPU backend does for kernels. That would then be controlled by the -fdenormal-fp-math option or something more explicitly linked to the entry function.
> 
> I don't want to add -mdaz-ftz because once we do we're kind of stuck with it. If you don't add it here, we'd continue the current behavior of linking with crtfastmath.o normally but we'd stop infecting shared libraries with it.

I don't think it's unreasonable to switch the logic of `-mdaz-ftz` from linking a file with a global initializer that sets the flags to making it emit the entry-point call to such a function instead, it still largely follows the same logic to me. And having a command line flag makes it easier for users to access rather than manually linking in a file located who-knows-where in the toolchain (although I suspect anyone who cares hard enough would rather just write the calls to set FTZ/DAZ than track it down from the toolchain).

https://github.com/llvm/llvm-project/pull/80475


More information about the cfe-commits mailing list