[llvm] LangRef: state explicitly that floats generally behave according to IEEE-754 (PR #102140)

via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 6 06:38:51 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-ir

Author: Ralf Jung (RalfJung)

<details>
<summary>Changes</summary>

Fixes https://github.com/llvm/llvm-project/issues/60942: IEEE semantics is likely what many frontends want (it definitely is what Rust wants), and it is what LLVM passes already assume when they use APFloat to propagate float operations.

This does not reflect what happens on x87, but what happens there is just plain unsound (https://github.com/llvm/llvm-project/issues/89885, https://github.com/llvm/llvm-project/issues/44218); there is no coherent specification that will describe this behavior correctly -- the backend in combination with standard LLVM passes is just fundamentally buggy in a hard-to-fix-way.

There's also the questions around flushing subnormals to zero, but [this discussion](https://discourse.llvm.org/t/questions-about-llvm-canonicalize/79378) seems to indicate that the expectation here is -- this is specific non-standard hardware behavior, and generally needs LLVM to be told that basic float ops do not return the standard result. Just naively running LLVM-compiler code on FTZ hardware will lead to #<!-- -->89885-like issues.

AFAIK this is also what Alive2 implements (@<!-- -->nunoplopes please correct me if I am wrong).

@<!-- -->nikic @<!-- -->arsenm @<!-- -->jcranmer-intel  what do you think is the best way to word this?

---
Full diff: https://github.com/llvm/llvm-project/pull/102140.diff


1 Files Affected:

- (modified) llvm/docs/LangRef.rst (+6) 


``````````diff
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index b17e3c828ed3d..7fc4e9385a1e1 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -3577,6 +3577,12 @@ seq\_cst total orderings of other operations that are not marked
 Floating-Point Environment
 --------------------------
 
+Unless noted otherwise, LLVM works with IEEE 754 floating-point semantics: LLVM
+backends assume that the CPU is configured to provide IEEE-compatible behavior,
+and LLVM frontends can assume that LLVM IR floating-point operations behave
+according to the IEEE specification (with an :ref:`exception around NaN values
+<floatnan>`).
+
 The default LLVM floating-point environment assumes that traps are disabled and
 status flags are not observable. Therefore, floating-point math operations do
 not have side effects and may be speculated freely. Results assume the

``````````

</details>


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


More information about the llvm-commits mailing list