[gcc r17-3377] [PATCH 1/7] alpha: honor -frounding-math by selecting dynamic rounding

Jeff Law via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:a7a7368a2f78b53adff0371045be97ac7eb1ec35

commit r17-3377-ga7a7368a2f78b53adff0371045be97ac7eb1ec35
Author: Matt Turner <[email protected]>
Date:   Tue Aug 18 08:58:21 2026 -0600

    [PATCH 1/7] alpha: honor -frounding-math by selecting dynamic rounding
    
    Alpha encodes the rounding mode in the instruction itself, so honoring a
    rounding mode chosen at run time requires the /d qualifier, which takes the
    mode from the FPCR.  alpha_fprm defaulted to ALPHA_FPRM_NORM and was only
    ever changed by an explicit -mfp-rounding-mode, so -frounding-math emitted
    statically rounded instructions and fesetround was silently ignored.
    
    Default alpha_fprm to ALPHA_FPRM_DYN when -frounding-math is in effect and
    -mfp-rounding-mode was not given, leaving both ordinary code generation and
    an explicit -mfp-rounding-mode unaffected.  The VAX floating-point
    instructions have no dynamic rounding qualifier, so -mfloat-vax keeps the
    static default.
    
    This fixes the execution failures of gcc.dg/torture/fp-uint64-convert-double-1.c,
    fp-uint64-convert-double-2.c and fp-double-convert-float-1.c.
    
    gcc/ChangeLog:
    
            * config/alpha/alpha.cc (alpha_option_override): Set alpha_fprm to
            ALPHA_FPRM_DYN when flag_rounding_math is set, -mfp-rounding-mode
            was not given explicitly and -mfloat-vax is not in effect.
            * doc/invoke.texi (Alpha Options): Document the default rounding
            mode and its interaction with -frounding-math.

Diff:
---
 gcc/config/alpha/alpha.cc |  6 ++++++
 gcc/doc/invoke.texi       | 13 ++++++++++---
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/gcc/config/alpha/alpha.cc b/gcc/config/alpha/alpha.cc
index 90e4c21dd11b..43443f82baca 100644
--- a/gcc/config/alpha/alpha.cc
+++ b/gcc/config/alpha/alpha.cc
@@ -435,6 +435,12 @@ alpha_option_override (void)
 	error ("bad value %qs for %<-mfp-rounding-mode%> switch",
 	       alpha_fprm_string);
     }
+  else if (flag_rounding_math && !TARGET_FLOAT_VAX)
+    /* Honoring a rounding mode chosen at run time requires instructions
+       that take their rounding mode from the FPCR.  Without this, code
+       built with -frounding-math silently ignores fesetround.  The VAX
+       floating-point instructions have no dynamic rounding qualifier.  */
+    alpha_fprm = ALPHA_FPRM_DYN;
 
   if (alpha_fptm_string)
     {
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 85491759020b..01925ecf30d7 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -26310,11 +26310,18 @@ Chopped rounding mode.  Floating-point numbers are rounded towards zero.
 @item d
 Dynamic rounding mode.  A field in the floating-point control register
 (@var{fpcr}, see Alpha architecture reference manual) controls the
-rounding mode in effect.  The C library initializes this register for
-rounding towards plus infinity.  Thus, unless your program modifies the
-@var{fpcr}, @samp{d} corresponds to round towards plus infinity.
+rounding mode in effect.  The C library initializes this register, so
+unless your program modifies the @var{fpcr}, for example through
+@code{fesetround}, @samp{d} corresponds to the rounding mode the C
+library selected.
 @end table
 
+The default is @samp{n}, except that @samp{d} is the default when
+@option{-frounding-math} is in effect, since only dynamic rounding can
+honor a rounding mode chosen at run time.  This does not apply to
+@option{-mfloat-vax}, whose instructions have no dynamic rounding
+qualifier.
+
 @opindex mtrap-precision
 @item -mtrap-precision=@var{trap-precision}
 In the Alpha architecture, floating-point traps are imprecise.  This
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.