[llvm] simplifyBinaryIntrinsic: Return nan if snan is passed maxnum/minnum (PR #158470)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 15 04:49:18 PDT 2025


================
@@ -830,6 +830,39 @@ define float @maxnum(float %a, float %b) {
   ret float %r
 }
 
+define float @maxnum_const_snan(float %x) {
+; CHECK-LABEL: @maxnum_const_snan(
+; CHECK-NEXT:    ret float 0x7FFC000000000000
+;
+  %r = call float @llvm.minnum.f32(float %x, float 0x7FF4000000000000)
+  ret float %r
+}
+
+define double @minnum_const_snan(double %x) {
+; CHECK-LABEL: @minnum_const_snan(
+; CHECK-NEXT:    ret double 0x7FFC000000000000
+;
+  %r = call double @llvm.minnum.f64(double %x, double 0x7FF4000000000000)
+  ret double %r
+}
+
+define float @maxnum_const_qnan(float %x) {
+; CHECK-LABEL: @maxnum_const_qnan(
+; CHECK-NEXT:    ret float [[X:%.*]]
+;
+  %r = call float @llvm.minnum.f32(float %x, float 0x7FF8000000000000)
+  ret float %r
+}
+
+define double @minnum_const_qnan(double %x) {
+; CHECK-LABEL: @minnum_const_qnan(
+; CHECK-NEXT:    ret double [[X:%.*]]
+;
+  %r = call double @llvm.minnum.f64(double %x, double 0x7FF8000000000000)
+  ret double %r
+}
+
----------------
arsenm wrote:

Test vectors, particularly a scalable vector and non-splat vectors with mixed snan and qnans 

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


More information about the llvm-commits mailing list