[llvm] [LangRef] Clarify the behavior of select with FP poison-generating flags (PR #137131)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 24 00:51:16 PDT 2025


https://github.com/dtcxzyw created https://github.com/llvm/llvm-project/pull/137131

RFC link: https://discourse.llvm.org/t/rfc-clarify-the-behavior-of-select-with-fp-poison-generating-flags/85974

Actually, it does not conflict with the definition of FMF if we interpret a select as `applyFMF(select cond, applyFMF(TrueArm), applyFMF(FalseArm))`.


>From bf12fa74839be2e4cb915a97593b55aae4c72891 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Thu, 24 Apr 2025 15:43:04 +0800
Subject: [PATCH] [LangRef] Clarify the behavior of select with FP
 poison-generating flags

---
 llvm/docs/LangRef.rst | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 9e78f317bd9ea..fe8eb411612b5 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -12895,12 +12895,16 @@ vectors of the same size, and the selection is done element by element.
 If the condition is an i1 and the value arguments are vectors of the
 same size, then an entire vector is selected.
 
+Note that violations of poison-generating flags for both arms may not result in poison return values.
+For simplicity, if :ref:`fast-math flags <fastmath>` are present, they are only applied to the result, not both arms.
+
 Example:
 """"""""
 
 .. code-block:: llvm
 
-      %X = select i1 true, i8 17, i8 42          ; yields i8:17
+      %X = select i1 true, i8 17, i8 42                   ; yields i8:17
+      %Y = select nnan i1 true, float 0.0, float NaN      ; yields float:0.0
 
 
 .. _i_freeze:



More information about the llvm-commits mailing list