jcranmer-intel wrote:

> I think there is a bit of a problematic interaction with 
> getDenormalModeForType 
> [here](https://github.com/llvm/llvm-project/blob/7a94acb2da5b20d12f13f3c5f4eb0f3f46e78e73/clang/lib/Driver/ToolChains/Linux.cpp#L838C8-L838C37).
>  "-shared" is (should be) a flag used only for linking, but that function is 
> calling isFastMathRuntimeAvailable to affect the default denormal math mode 
> for _compilation_. That's not going to work.

The logic is already somewhat broken already: if `-ffast-math` isn't being 
added into the link line, or we're a shared library linked into a `-ffast-math` 
executable, we're not going to get the right value of denormal math mode. So 
it's a matter of which behavior is going to be the least likely to be incorrect 
in practice.

> I wonder if, instead, we should just have `-ffast-math` always downgrade 
> `-fdenormal-fp-math=ieee` to `-fdenormal-fp-math=preserve-sign`, under the 
> rationale of "you asked for fast math, and preserve-sign mode might let the 
> compiler generate faster code"?

One of the issues is that we have optimizations that are going to make 
assumptions about how denormals work in operations (particularly around being 
able to lower `llvm.is.fpclass` to `fcmp`). So you risk misoptimization if the 
value is wrong. Arguably, the only safe value is dynamic (compiler doesn't know 
what it's set to).

(We're wrong in another direction, which is that we don't attempt to set the 
flag to non-ieee for anything other x86. I tried looking up how the equivalents 
of FTZ/DAZ worked on other architectures and came to with the conclusion that 
the whole thing is a bundle of sadness that should have never been invented.)

https://github.com/llvm/llvm-project/pull/80475
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to