https://gcc.gnu.org/g:05e1cda2bd6ef370de19599d174c1146bd730ccf

commit r16-4364-g05e1cda2bd6ef370de19599d174c1146bd730ccf
Author: Juergen Christ <[email protected]>
Date:   Mon Sep 15 12:13:22 2025 +0200

    s390x: Fix fmin/fmax patterns
    
    s390x floating point minimum and maximum functions unfortunately do
    not canonicalize NaNs.  Hence, test pr105414.c fails since
    c476f554e3f.  Fix this by only allowing fmin/fmax pattern if signaling
    NaNs are disabled.
    
    gcc/ChangeLog:
    
            * config/s390/vector.md (fmax<mode>3): Restrict to no trapping
            math.
            (fmin<mode>3): Ditto.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/s390/fminmax-1.c: Disable for signaling NaNs.
            * gcc.target/s390/fminmax-2.c: Ditto.
            * gcc.target/s390/vector/reduc-minmax-1.c: Ditto.
    
    Signed-off-by: Juergen Christ <[email protected]>

Diff:
---
 gcc/config/s390/vector.md                             | 8 ++++----
 gcc/testsuite/gcc.target/s390/fminmax-1.c             | 2 +-
 gcc/testsuite/gcc.target/s390/fminmax-2.c             | 2 +-
 gcc/testsuite/gcc.target/s390/vector/reduc-minmax-1.c | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/gcc/config/s390/vector.md b/gcc/config/s390/vector.md
index 205ead2ca9d8..375e3e81ae17 100644
--- a/gcc/config/s390/vector.md
+++ b/gcc/config/s390/vector.md
@@ -3663,7 +3663,7 @@
               (match_operand:VFT_BFP           2 "register_operand")
               (const_int 4)]
              UNSPEC_FMAX))]
-  "TARGET_VXE")
+  "TARGET_VXE && !flag_signaling_nans")
 
 ; fmin
 (define_expand "fmin<mode>3"
@@ -3672,7 +3672,7 @@
               (match_operand:VFT_BFP           2 "register_operand")
               (const_int 4)]
              UNSPEC_FMIN))]
-  "TARGET_VXE")
+  "TARGET_VXE && !flag_signaling_nans")
 
 ; reduc_plus
 (define_expand "reduc_plus_scal_<mode>"
@@ -3764,7 +3764,7 @@
        (unspec:V2DF [(match_dup 1) (match_dup 2) (const_int 4)] REDUC_FMINMAX))
    (set (match_operand:DF 0 "register_operand" "")
        (vec_select:DF (match_dup 3) (parallel [(const_int 0)])))]
-  "TARGET_VX"
+  "TARGET_VX && !flag_trapping_math"
 {
   operands[2] = gen_reg_rtx (V2DFmode);
   operands[3] = gen_reg_rtx (V2DFmode);
@@ -3787,7 +3787,7 @@
        (unspec:V4SF [(match_dup 3) (match_dup 4) (const_int 4)] REDUC_FMINMAX))
    (set (match_operand:SF 0 "register_operand")
        (vec_select:SF (match_dup 5) (parallel [(const_int 0)])))]
-   "TARGET_VXE"
+   "TARGET_VXE && !flag_trapping_math"
 {
   operands[2] = gen_reg_rtx (V4SFmode);
   operands[3] = gen_reg_rtx (V4SFmode);
diff --git a/gcc/testsuite/gcc.target/s390/fminmax-1.c 
b/gcc/testsuite/gcc.target/s390/fminmax-1.c
index df10905f037a..756a19970a50 100644
--- a/gcc/testsuite/gcc.target/s390/fminmax-1.c
+++ b/gcc/testsuite/gcc.target/s390/fminmax-1.c
@@ -1,7 +1,7 @@
 /* Check fmin/fmax expanders for scalars on VXE targets.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O2 -march=z14 -mzarch" } */
+/* { dg-options "-O2 -march=z14 -mzarch -fno-trapping-math" } */
 /* { dg-final { check-function-bodies "**" "" } } */
 
 /*
diff --git a/gcc/testsuite/gcc.target/s390/fminmax-2.c 
b/gcc/testsuite/gcc.target/s390/fminmax-2.c
index ea37a0a821de..ac090c65d1bd 100644
--- a/gcc/testsuite/gcc.target/s390/fminmax-2.c
+++ b/gcc/testsuite/gcc.target/s390/fminmax-2.c
@@ -1,7 +1,7 @@
 /* Check fmin/fmax expanders for scalars on non-VXE targets.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O2 -march=z13 -mzarch" } */
+/* { dg-options "-O2 -march=z13 -mzarch -fno-trapping-math" } */
 /* { dg-final { scan-assembler-times "jg" 4 } } */
 
 double
diff --git a/gcc/testsuite/gcc.target/s390/vector/reduc-minmax-1.c 
b/gcc/testsuite/gcc.target/s390/vector/reduc-minmax-1.c
index 5295250dcb74..7f4d16a03ddd 100644
--- a/gcc/testsuite/gcc.target/s390/vector/reduc-minmax-1.c
+++ b/gcc/testsuite/gcc.target/s390/vector/reduc-minmax-1.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O3 -mzarch -march=z14 -ftree-vectorize 
-fdump-tree-optimized" } */
+/* { dg-options "-O3 -mzarch -march=z14 -ftree-vectorize -fdump-tree-optimized 
-fno-trapping-math" } */
 
 #define MAX(a, b) ((a) > (b) ? (a) : (b))
 #define MIN(a, b) ((a) > (b) ? (b) : (a))

Reply via email to