[PATCH] D139549: [X86][ConstraintFP] Model `MXCSR` for function call

Serge Pavlov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 16 08:10:31 PST 2023


sepavloff added inline comments.


================
Comment at: llvm/include/llvm/CodeGen/TargetLowering.h:4474-4478
+  /// Returns a 0 terminated array of rounding control registers that can be
+  /// attached into strict FP call.
+  virtual const MCPhysReg *getRoundingControlRegisters() const {
+    return nullptr;
+  }
----------------
pengfei wrote:
> sepavloff wrote:
> > The function name is a bit misleading, maybe `getFPEnvironmentRegisters` or some thing like that?
> > 
> > If this function lists FP environment registers that can be changed by a call, then any FP control mode register, not only rounding control (for example, denormal treatment or precision control) also can be modified. FP status information, like raised exception, also may be changed in the called procedure, so it is reasonable to include relevant registers as well.
> > 
> > MXCSR contains all this information but other architectures may have different registers for such information.
> Thanks for the inputs! Modeling all the FP environment registers sounds attractive. However, it is not what the current strict FP required.
> 1. Denormal treatment is a good point. We haven't modeled it, but I think it's not a problem if we sort it into rounding control.
> 2. Precision as well as exception control registers do nothing with strict FP, because we just use MIFlag to ensure exception correctness.
> 3. The exception status registers are the same. We never use this information in strict FP.
> 
> In a word, only the rounding behaviors in strict FP mode relies on register modeling. So I think the name reflects the requirments correctly.
Current definition of `strictfp` in https://llvm.org/docs/LangRef.html#function-attributes explicitly mentions status flags:
```
LLVM will not attempt any optimizations that require assumptions about the floating-point rounding mode or that might alter the state of floating-point status flags ...
```
As for other control modes, like denormal mode, they behave similar to rounding direction. If a function call (like C2x library function `fesetmode`) modifies them, nothing prevents from moving the call across the users of the modified control register.

Listing all FP environment registers saves us from undesired code motion.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139549/new/

https://reviews.llvm.org/D139549



More information about the llvm-commits mailing list