[llvm] [llubi] Initial support for floating-point numbers (PR #188453)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 5 11:41:19 PDT 2026


================
@@ -81,6 +83,165 @@ class InstExecutor : public InstVisitor<InstExecutor, void>,
     CurrentFrame->ValueMap.insert_or_assign(&I, std::move(V));
   }
 
+  APFloat handleDenormal(APFloat Val, DenormalMode::DenormalModeKind Mode,
+                         bool NonDet = false) {
+    if (!Val.isDenormal())
+      return Val;
+    if (NonDet) {
+      // Non-deterministically choose between flushing or preserving the
+      // denormal value.
+      if (Ctx.getRandomBool())
+        return Val;
+    }
+    if (Mode == DenormalMode::PositiveZero)
+      return APFloat::getZero(Val.getSemantics(), false);
+    if (Mode == DenormalMode::PreserveSign)
+      return APFloat::getZero(Val.getSemantics(), Val.isNegative());
+    // Default case for IEEE, Dynamic, and Invalid
+    // Currently we treat Dynamic the same as IEEE, since we don't support
+    // changing the mode at this point.
+    return Val;
+  }
+
+  AnyValue handleFMFFlags(AnyValue Val, FastMathFlags FMF) {
+    if (Val.isPoison())
+      return AnyValue::poison();
+
+    if (Val.isAggregate()) {
+      std::vector<AnyValue> ResVec;
+      ResVec.reserve(Val.asAggregate().size());
+      for (const auto &A : Val.asAggregate())
+        ResVec.push_back(handleFMFFlags(A, FMF));
+      return AnyValue(ResVec);
+    }
+
+    const APFloat &APVal = Val.asFloat();
+    if (FMF.noNaNs() && APVal.isNaN())
+      return AnyValue::poison();
+    if (FMF.noInfs() && APVal.isInfinity())
+      return AnyValue::poison();
+    if (FMF.noSignedZeros() && APVal.isZero())
----------------
dtcxzyw wrote:

nsz only applies to inputs.

> nsz
No Signed Zeros - Unless otherwise mentioned, the sign bit of 0.0 or -0.0 input operands can be non-deterministically flipped. This does not imply that -0.0 is poison and/or guaranteed to not exist in the operation.

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


More information about the llvm-commits mailing list