[llvm] [Inline] Propagate FMFs from calls to inlined instructions. (PR #145537)

Andy Kaylor via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 24 09:29:40 PDT 2025


andykaylor wrote:

I agree with @nikic on the limitations of applying fast-math flags to calls. In fact, I think it would be reasonable to state outright that fast-math flags can't be applied transitively to defined functions.  Consider this situation:

```
float foo(float a, float b, float c) {
  #pragma STDC FP_CONTRACT OFF
  return a * b + c;
}

float bar(float a, float b, float c) {
  return foo(a, b, c);
}
```
Here a pragma has been used to disallow `contract` on the definition of `foo`, but currently clang sets the `contract` flag on the call to `foo` in `bar`. This call is going to be inlined, but that should not re-enable `contract` on the inlined operations.

We should probably update clang to stop setting the fast-math flags on non-intrinsic calls, but I don't think we should try to apply them if they are present. The `nofpclass` attribute covers the effects of the poison-inducing flags, and those flags can be applied during inlining based on the `nofpclass` attribute settings, but the rewrite flags should not be applied.

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


More information about the llvm-commits mailing list