[clang] [llvm] Clang: Add nsz to llvm.minnum and llvm.maxnum emitted from fmin and fmax (PR #113133)

YunQiang Su via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 9 00:53:21 PST 2025


================
@@ -4002,8 +4012,11 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
       Result = Builder.CreateBinaryIntrinsic(
           Ty->isSignedIntegerType() ? Intrinsic::smin : Intrinsic::umin, Op0,
           Op1, nullptr, "elt.min");
-    } else
-      Result = Builder.CreateMinNum(Op0, Op1, /*FMFSource=*/nullptr, "elt.min");
+    } else {
+      FastMathFlags FMF;
+      FMF.setNoSignedZeros(true);
----------------
wzssyqa wrote:

> I agree this should not continue to use minnum/maxnum, though that change should not be part of this PR.
> 

So can we merge this PR?

> minnum/maxnum behavior has never been consistent across targets (or across scenarios). 

In fact, all of the architectures that claims implement IEEE754-2008, has the same behavior:
     AArch64, MIPSr6, LoongArch, PowerPC/VSX
That's why I'd plan to define `minnum/maxnum` as the same as these architectures.

> But we could also add __builtin_elementwise_maximumnum/__builtin_elementwise_minimnumnum

I will do it.

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


More information about the llvm-commits mailing list