[V2,2/2,x86] x86: Add a new option -mdaz-ftz to enable FTZ and DAZ flags in MXCSR.

Message ID 20221215062137.3128845-2-hongtao.liu@intel.com
State Accepted
Headers
Series [V2,1/2] x86: Don't add crtfastmath.o for -shared |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

liuhongt Dec. 15, 2022, 6:21 a.m. UTC
  Update in v2:
1. Support -mno-daz-ftz, and make the the option effectively three state as:

if (mdaz-ftz)
  link crtfastmath.o
else if ((Ofast || ffast-math || funsafe-math-optimizations)
     	 && !shared && !mno-daz-ftz)
  link crtfastmath.o
else
  Don't link crtfastmath.o

2. Still make the option Target since
   a. cc1: error: command-line option ‘-mdaz-ftz’ is valid for the driver but not for C
   b. Since there's no real variable speicified by mdaz-ftz, I saw in options.h, it's marked as
   #ifndef GENERATOR_FILE
  int x_VAR_mdaz_ftz;
  #define x_VAR_mdaz_ftz do_not_use
  #endif

and not be saved and restored in cl_target_option_save and cl_target_option_restore(am I missing something?)

3. Capital the first letter and add more descriptions about -mdaz-ftz and -shared.

gcc/ChangeLog:

	PR target/55522
	PR target/36821
	* config/i386/gnu-user-common.h (GNU_USER_TARGET_MATHFILE_SPEC):
	Link crtfastmath.o whenever -mdaz-ftz is specified. Don't link
	crtfastmath.o when -share or -mno-daz-ftz is specified.
	* config/i386/i386.opt (mdaz-ftz): New option.
	* doc/invoke.texi (x86 options): Document mftz-daz.
---
 gcc/config/i386/gnu-user-common.h |  2 +-
 gcc/config/i386/i386.opt          |  4 ++++
 gcc/doc/invoke.texi               | 12 +++++++++++-
 3 files changed, 16 insertions(+), 2 deletions(-)
  

Comments

Jakub Jelinek Dec. 15, 2022, 7:39 a.m. UTC | #1
On Thu, Dec 15, 2022 at 02:21:37PM +0800, liuhongt via Gcc-patches wrote:
> --- a/gcc/config/i386/i386.opt
> +++ b/gcc/config/i386/i386.opt
> @@ -420,6 +420,10 @@ mpc80
>  Target RejectNegative
>  Set 80387 floating-point precision to 80-bit.
>  
> +mdaz-ftz
> +Target

s/Target/Driver/

> +Set the FTZ and DAZ Flags.

	Jakub
  
Hongtao Liu Dec. 15, 2022, 7:45 a.m. UTC | #2
On Thu, Dec 15, 2022 at 3:39 PM Jakub Jelinek <jakub@redhat.com> wrote:
>
> On Thu, Dec 15, 2022 at 02:21:37PM +0800, liuhongt via Gcc-patches wrote:
> > --- a/gcc/config/i386/i386.opt
> > +++ b/gcc/config/i386/i386.opt
> > @@ -420,6 +420,10 @@ mpc80
> >  Target RejectNegative
> >  Set 80387 floating-point precision to 80-bit.
> >
> > +mdaz-ftz
> > +Target
>
> s/Target/Driver/
Change to Driver and Got error like:cc1: error: command-line option
‘-mdaz-ftz’ is valid for the driver but not for C.
>
> > +Set the FTZ and DAZ Flags.
>
>         Jakub
>
  
Hongtao Liu Dec. 20, 2022, 4:51 a.m. UTC | #3
On Thu, Dec 15, 2022 at 3:45 PM Hongtao Liu <crazylht@gmail.com> wrote:
>
> On Thu, Dec 15, 2022 at 3:39 PM Jakub Jelinek <jakub@redhat.com> wrote:
> >
> > On Thu, Dec 15, 2022 at 02:21:37PM +0800, liuhongt via Gcc-patches wrote:
> > > --- a/gcc/config/i386/i386.opt
> > > +++ b/gcc/config/i386/i386.opt
> > > @@ -420,6 +420,10 @@ mpc80
> > >  Target RejectNegative
> > >  Set 80387 floating-point precision to 80-bit.
> > >
> > > +mdaz-ftz
> > > +Target
> >
> > s/Target/Driver/
> Change to Driver and Got error like:cc1: error: command-line option
> ‘-mdaz-ftz’ is valid for the driver but not for C.
Hi Jakub:
  I didn't find a good solution to handle this error after changing
*Target* to *Driver*, Could you give some hints how to solve this
problem?
Or is it ok for you to mark this as *Target*(there won't be any save
and restore in cfun since there's no variable defined here.)
> >
> > > +Set the FTZ and DAZ Flags.
> >
> >         Jakub
> >
>
>
> --
> BR,
> Hongtao
  
H.J. Lu Dec. 21, 2022, 8:20 p.m. UTC | #4
On Mon, Dec 19, 2022 at 8:52 PM Hongtao Liu <crazylht@gmail.com> wrote:
>
> On Thu, Dec 15, 2022 at 3:45 PM Hongtao Liu <crazylht@gmail.com> wrote:
> >
> > On Thu, Dec 15, 2022 at 3:39 PM Jakub Jelinek <jakub@redhat.com> wrote:
> > >
> > > On Thu, Dec 15, 2022 at 02:21:37PM +0800, liuhongt via Gcc-patches wrote:
> > > > --- a/gcc/config/i386/i386.opt
> > > > +++ b/gcc/config/i386/i386.opt
> > > > @@ -420,6 +420,10 @@ mpc80
> > > >  Target RejectNegative
> > > >  Set 80387 floating-point precision to 80-bit.
> > > >
> > > > +mdaz-ftz
> > > > +Target
> > >
> > > s/Target/Driver/
> > Change to Driver and Got error like:cc1: error: command-line option
> > ‘-mdaz-ftz’ is valid for the driver but not for C.
> Hi Jakub:
>   I didn't find a good solution to handle this error after changing
> *Target* to *Driver*, Could you give some hints how to solve this
> problem?
> Or is it ok for you to mark this as *Target*(there won't be any save
> and restore in cfun since there's no variable defined here.)

Since all -m* options are passed to cc1, -mdaz-ftz can't be marked
as Driver.  We need to give it a different name to mark it as Driver.
  
Jakub Jelinek Dec. 21, 2022, 10:35 p.m. UTC | #5
On Wed, Dec 21, 2022 at 12:20:23PM -0800, H.J. Lu wrote:
> On Mon, Dec 19, 2022 at 8:52 PM Hongtao Liu <crazylht@gmail.com> wrote:
> >
> > On Thu, Dec 15, 2022 at 3:45 PM Hongtao Liu <crazylht@gmail.com> wrote:
> > >
> > > On Thu, Dec 15, 2022 at 3:39 PM Jakub Jelinek <jakub@redhat.com> wrote:
> > > >
> > > > On Thu, Dec 15, 2022 at 02:21:37PM +0800, liuhongt via Gcc-patches wrote:
> > > > > --- a/gcc/config/i386/i386.opt
> > > > > +++ b/gcc/config/i386/i386.opt
> > > > > @@ -420,6 +420,10 @@ mpc80
> > > > >  Target RejectNegative
> > > > >  Set 80387 floating-point precision to 80-bit.
> > > > >
> > > > > +mdaz-ftz
> > > > > +Target
> > > >
> > > > s/Target/Driver/
> > > Change to Driver and Got error like:cc1: error: command-line option
> > > ‘-mdaz-ftz’ is valid for the driver but not for C.
> > Hi Jakub:
> >   I didn't find a good solution to handle this error after changing
> > *Target* to *Driver*, Could you give some hints how to solve this
> > problem?
> > Or is it ok for you to mark this as *Target*(there won't be any save
> > and restore in cfun since there's no variable defined here.)
> 
> Since all -m* options are passed to cc1, -mdaz-ftz can't be marked
> as Driver.  We need to give it a different name to mark it as Driver.

It is ok like that.

	Jakub
  
H.J. Lu Dec. 21, 2022, 10:43 p.m. UTC | #6
On Wed, Dec 21, 2022 at 2:35 PM Jakub Jelinek <jakub@redhat.com> wrote:
>
> On Wed, Dec 21, 2022 at 12:20:23PM -0800, H.J. Lu wrote:
> > On Mon, Dec 19, 2022 at 8:52 PM Hongtao Liu <crazylht@gmail.com> wrote:
> > >
> > > On Thu, Dec 15, 2022 at 3:45 PM Hongtao Liu <crazylht@gmail.com> wrote:
> > > >
> > > > On Thu, Dec 15, 2022 at 3:39 PM Jakub Jelinek <jakub@redhat.com> wrote:
> > > > >
> > > > > On Thu, Dec 15, 2022 at 02:21:37PM +0800, liuhongt via Gcc-patches wrote:
> > > > > > --- a/gcc/config/i386/i386.opt
> > > > > > +++ b/gcc/config/i386/i386.opt
> > > > > > @@ -420,6 +420,10 @@ mpc80
> > > > > >  Target RejectNegative
> > > > > >  Set 80387 floating-point precision to 80-bit.
> > > > > >
> > > > > > +mdaz-ftz
> > > > > > +Target
> > > > >
> > > > > s/Target/Driver/
> > > > Change to Driver and Got error like:cc1: error: command-line option
> > > > ‘-mdaz-ftz’ is valid for the driver but not for C.
> > > Hi Jakub:
> > >   I didn't find a good solution to handle this error after changing
> > > *Target* to *Driver*, Could you give some hints how to solve this
> > > problem?
> > > Or is it ok for you to mark this as *Target*(there won't be any save
> > > and restore in cfun since there's no variable defined here.)
> >
> > Since all -m* options are passed to cc1, -mdaz-ftz can't be marked
> > as Driver.  We need to give it a different name to mark it as Driver.
>
> It is ok like that.
>
>         Jakub
>

The GCC driver handles -mno-XXX automatically for -mXXX.  Use
a different name needs to handle the negation.   Or we can do something
like this to check for CL_DRIVER before passing it to cc1.
  
Jakub Jelinek Dec. 21, 2022, 10:46 p.m. UTC | #7
On Wed, Dec 21, 2022 at 02:43:43PM -0800, H.J. Lu wrote:
> > > > > > >  Target RejectNegative
> > > > > > >  Set 80387 floating-point precision to 80-bit.
> > > > > > >
> > > > > > > +mdaz-ftz
> > > > > > > +Target
> > > > > >
> > > > > > s/Target/Driver/
> > > > > Change to Driver and Got error like:cc1: error: command-line option
> > > > > ‘-mdaz-ftz’ is valid for the driver but not for C.
> > > > Hi Jakub:
> > > >   I didn't find a good solution to handle this error after changing
> > > > *Target* to *Driver*, Could you give some hints how to solve this
> > > > problem?
> > > > Or is it ok for you to mark this as *Target*(there won't be any save
> > > > and restore in cfun since there's no variable defined here.)
> > >
> > > Since all -m* options are passed to cc1, -mdaz-ftz can't be marked
> > > as Driver.  We need to give it a different name to mark it as Driver.
> >
> > It is ok like that.
> >
> >         Jakub
> >
> 
> The GCC driver handles -mno-XXX automatically for -mXXX.  Use
> a different name needs to handle the negation.   Or we can do something
> like this to check for CL_DRIVER before passing it to cc1.

I meant I'm ok with -m{,no-}daz-ftz option being Target rather than Driver.

	Jakub
  
Hongtao Liu Dec. 22, 2022, 4:40 a.m. UTC | #8
On Thu, Dec 22, 2022 at 6:46 AM Jakub Jelinek <jakub@redhat.com> wrote:
>
> On Wed, Dec 21, 2022 at 02:43:43PM -0800, H.J. Lu wrote:
> > > > > > > >  Target RejectNegative
> > > > > > > >  Set 80387 floating-point precision to 80-bit.
> > > > > > > >
> > > > > > > > +mdaz-ftz
> > > > > > > > +Target
> > > > > > >
> > > > > > > s/Target/Driver/
> > > > > > Change to Driver and Got error like:cc1: error: command-line option
> > > > > > ‘-mdaz-ftz’ is valid for the driver but not for C.
> > > > > Hi Jakub:
> > > > >   I didn't find a good solution to handle this error after changing
> > > > > *Target* to *Driver*, Could you give some hints how to solve this
> > > > > problem?
> > > > > Or is it ok for you to mark this as *Target*(there won't be any save
> > > > > and restore in cfun since there's no variable defined here.)
> > > >
> > > > Since all -m* options are passed to cc1, -mdaz-ftz can't be marked
> > > > as Driver.  We need to give it a different name to mark it as Driver.
> > >
> > > It is ok like that.
> > >
> > >         Jakub
> > >
> >
> > The GCC driver handles -mno-XXX automatically for -mXXX.  Use
> > a different name needs to handle the negation.   Or we can do something
> > like this to check for CL_DRIVER before passing it to cc1.
>
> I meant I'm ok with -m{,no-}daz-ftz option being Target rather than Driver.
>
Thanks.
Uros, Is the patch for you?
>         Jakub
>
  
Uros Bizjak Dec. 22, 2022, 8:04 a.m. UTC | #9
On Thu, Dec 22, 2022 at 5:40 AM Hongtao Liu <crazylht@gmail.com> wrote:
>
> On Thu, Dec 22, 2022 at 6:46 AM Jakub Jelinek <jakub@redhat.com> wrote:
> >
> > On Wed, Dec 21, 2022 at 02:43:43PM -0800, H.J. Lu wrote:
> > > > > > > > >  Target RejectNegative
> > > > > > > > >  Set 80387 floating-point precision to 80-bit.
> > > > > > > > >
> > > > > > > > > +mdaz-ftz
> > > > > > > > > +Target
> > > > > > > >
> > > > > > > > s/Target/Driver/
> > > > > > > Change to Driver and Got error like:cc1: error: command-line option
> > > > > > > ‘-mdaz-ftz’ is valid for the driver but not for C.
> > > > > > Hi Jakub:
> > > > > >   I didn't find a good solution to handle this error after changing
> > > > > > *Target* to *Driver*, Could you give some hints how to solve this
> > > > > > problem?
> > > > > > Or is it ok for you to mark this as *Target*(there won't be any save
> > > > > > and restore in cfun since there's no variable defined here.)
> > > > >
> > > > > Since all -m* options are passed to cc1, -mdaz-ftz can't be marked
> > > > > as Driver.  We need to give it a different name to mark it as Driver.
> > > >
> > > > It is ok like that.
> > > >
> > > >         Jakub
> > > >
> > >
> > > The GCC driver handles -mno-XXX automatically for -mXXX.  Use
> > > a different name needs to handle the negation.   Or we can do something
> > > like this to check for CL_DRIVER before passing it to cc1.
> >
> > I meant I'm ok with -m{,no-}daz-ftz option being Target rather than Driver.
> >
> Thanks.
> Uros, Is the patch for you?

The original patch is then OK.

Thanks,
Uros.
  
Hongtao Liu May 4, 2023, 5:35 a.m. UTC | #10
On Thu, Dec 22, 2022 at 4:04 PM Uros Bizjak <ubizjak@gmail.com> wrote:
>
> On Thu, Dec 22, 2022 at 5:40 AM Hongtao Liu <crazylht@gmail.com> wrote:
> >
> > On Thu, Dec 22, 2022 at 6:46 AM Jakub Jelinek <jakub@redhat.com> wrote:
> > >
> > > On Wed, Dec 21, 2022 at 02:43:43PM -0800, H.J. Lu wrote:
> > > > > > > > > >  Target RejectNegative
> > > > > > > > > >  Set 80387 floating-point precision to 80-bit.
> > > > > > > > > >
> > > > > > > > > > +mdaz-ftz
> > > > > > > > > > +Target
> > > > > > > > >
> > > > > > > > > s/Target/Driver/
> > > > > > > > Change to Driver and Got error like:cc1: error: command-line option
> > > > > > > > ‘-mdaz-ftz’ is valid for the driver but not for C.
> > > > > > > Hi Jakub:
> > > > > > >   I didn't find a good solution to handle this error after changing
> > > > > > > *Target* to *Driver*, Could you give some hints how to solve this
> > > > > > > problem?
> > > > > > > Or is it ok for you to mark this as *Target*(there won't be any save
> > > > > > > and restore in cfun since there's no variable defined here.)
> > > > > >
> > > > > > Since all -m* options are passed to cc1, -mdaz-ftz can't be marked
> > > > > > as Driver.  We need to give it a different name to mark it as Driver.
> > > > >
> > > > > It is ok like that.
> > > > >
> > > > >         Jakub
> > > > >
> > > >
> > > > The GCC driver handles -mno-XXX automatically for -mXXX.  Use
> > > > a different name needs to handle the negation.   Or we can do something
> > > > like this to check for CL_DRIVER before passing it to cc1.
> > >
> > > I meant I'm ok with -m{,no-}daz-ftz option being Target rather than Driver.
> > >
> > Thanks.
> > Uros, Is the patch for you?
>
> The original patch is then OK.
Some users found the -mdaz-ftz option to be very useful, and want it
to be backport to GCC12 and GCC11.
But the patch is not a bugfix one, so i'd like to ask options from
other maintainers, if the patch is suitable for backport?

The backport patches include both this one and [1] which apply
-mdaz-ftz to all other x86 targets.

[1] https://gcc.gnu.org/pipermail/gcc-patches/2023-January/610053.html

>
> Thanks,
> Uros.
  
Hongtao Liu May 4, 2023, 5:36 a.m. UTC | #11
On Thu, May 4, 2023 at 1:35 PM Hongtao Liu <crazylht@gmail.com> wrote:
>
> On Thu, Dec 22, 2022 at 4:04 PM Uros Bizjak <ubizjak@gmail.com> wrote:
> >
> > On Thu, Dec 22, 2022 at 5:40 AM Hongtao Liu <crazylht@gmail.com> wrote:
> > >
> > > On Thu, Dec 22, 2022 at 6:46 AM Jakub Jelinek <jakub@redhat.com> wrote:
> > > >
> > > > On Wed, Dec 21, 2022 at 02:43:43PM -0800, H.J. Lu wrote:
> > > > > > > > > > >  Target RejectNegative
> > > > > > > > > > >  Set 80387 floating-point precision to 80-bit.
> > > > > > > > > > >
> > > > > > > > > > > +mdaz-ftz
> > > > > > > > > > > +Target
> > > > > > > > > >
> > > > > > > > > > s/Target/Driver/
> > > > > > > > > Change to Driver and Got error like:cc1: error: command-line option
> > > > > > > > > ‘-mdaz-ftz’ is valid for the driver but not for C.
> > > > > > > > Hi Jakub:
> > > > > > > >   I didn't find a good solution to handle this error after changing
> > > > > > > > *Target* to *Driver*, Could you give some hints how to solve this
> > > > > > > > problem?
> > > > > > > > Or is it ok for you to mark this as *Target*(there won't be any save
> > > > > > > > and restore in cfun since there's no variable defined here.)
> > > > > > >
> > > > > > > Since all -m* options are passed to cc1, -mdaz-ftz can't be marked
> > > > > > > as Driver.  We need to give it a different name to mark it as Driver.
> > > > > >
> > > > > > It is ok like that.
> > > > > >
> > > > > >         Jakub
> > > > > >
> > > > >
> > > > > The GCC driver handles -mno-XXX automatically for -mXXX.  Use
> > > > > a different name needs to handle the negation.   Or we can do something
> > > > > like this to check for CL_DRIVER before passing it to cc1.
> > > >
> > > > I meant I'm ok with -m{,no-}daz-ftz option being Target rather than Driver.
> > > >
> > > Thanks.
> > > Uros, Is the patch for you?
> >
> > The original patch is then OK.
> Some users found the -mdaz-ftz option to be very useful, and want it
> to be backport to GCC12 and GCC11.
> But the patch is not a bugfix one, so i'd like to ask options from
s/options/opinions/g
> other maintainers, if the patch is suitable for backport?
>
> The backport patches include both this one and [1] which apply
> -mdaz-ftz to all other x86 targets.
>
> [1] https://gcc.gnu.org/pipermail/gcc-patches/2023-January/610053.html
>
> >
> > Thanks,
> > Uros.
>
>
>
> --
> BR,
> Hongtao
  
Richard Biener May 4, 2023, 9:49 a.m. UTC | #12
On Thu, May 4, 2023 at 7:37 AM Hongtao Liu via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> On Thu, May 4, 2023 at 1:35 PM Hongtao Liu <crazylht@gmail.com> wrote:
> >
> > On Thu, Dec 22, 2022 at 4:04 PM Uros Bizjak <ubizjak@gmail.com> wrote:
> > >
> > > On Thu, Dec 22, 2022 at 5:40 AM Hongtao Liu <crazylht@gmail.com> wrote:
> > > >
> > > > On Thu, Dec 22, 2022 at 6:46 AM Jakub Jelinek <jakub@redhat.com> wrote:
> > > > >
> > > > > On Wed, Dec 21, 2022 at 02:43:43PM -0800, H.J. Lu wrote:
> > > > > > > > > > > >  Target RejectNegative
> > > > > > > > > > > >  Set 80387 floating-point precision to 80-bit.
> > > > > > > > > > > >
> > > > > > > > > > > > +mdaz-ftz
> > > > > > > > > > > > +Target
> > > > > > > > > > >
> > > > > > > > > > > s/Target/Driver/
> > > > > > > > > > Change to Driver and Got error like:cc1: error: command-line option
> > > > > > > > > > ‘-mdaz-ftz’ is valid for the driver but not for C.
> > > > > > > > > Hi Jakub:
> > > > > > > > >   I didn't find a good solution to handle this error after changing
> > > > > > > > > *Target* to *Driver*, Could you give some hints how to solve this
> > > > > > > > > problem?
> > > > > > > > > Or is it ok for you to mark this as *Target*(there won't be any save
> > > > > > > > > and restore in cfun since there's no variable defined here.)
> > > > > > > >
> > > > > > > > Since all -m* options are passed to cc1, -mdaz-ftz can't be marked
> > > > > > > > as Driver.  We need to give it a different name to mark it as Driver.
> > > > > > >
> > > > > > > It is ok like that.
> > > > > > >
> > > > > > >         Jakub
> > > > > > >
> > > > > >
> > > > > > The GCC driver handles -mno-XXX automatically for -mXXX.  Use
> > > > > > a different name needs to handle the negation.   Or we can do something
> > > > > > like this to check for CL_DRIVER before passing it to cc1.
> > > > >
> > > > > I meant I'm ok with -m{,no-}daz-ftz option being Target rather than Driver.
> > > > >
> > > > Thanks.
> > > > Uros, Is the patch for you?
> > >
> > > The original patch is then OK.
> > Some users found the -mdaz-ftz option to be very useful, and want it
> > to be backport to GCC12 and GCC11.
> > But the patch is not a bugfix one, so i'd like to ask options from
> s/options/opinions/g
> > other maintainers, if the patch is suitable for backport?
> >
> > The backport patches include both this one and [1] which apply
> > -mdaz-ftz to all other x86 targets.
> >
> > [1] https://gcc.gnu.org/pipermail/gcc-patches/2023-January/610053.html

Please make sure to not backport the -ffast-math linker spec change though.
Also note the 12 branch is currently frozen.

I'll defer to x86 maintainers on the -mdaz-ftz flag itself.

Richard.

> > >
> > > Thanks,
> > > Uros.
> >
> >
> >
> > --
> > BR,
> > Hongtao
>
>
>
> --
> BR,
> Hongtao
  
Hongtao Liu May 10, 2023, 1:41 a.m. UTC | #13
On Thu, May 4, 2023 at 5:49 PM Richard Biener
<richard.guenther@gmail.com> wrote:
>
> On Thu, May 4, 2023 at 7:37 AM Hongtao Liu via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
> >
> > On Thu, May 4, 2023 at 1:35 PM Hongtao Liu <crazylht@gmail.com> wrote:
> > >
> > > On Thu, Dec 22, 2022 at 4:04 PM Uros Bizjak <ubizjak@gmail.com> wrote:
> > > >
> > > > On Thu, Dec 22, 2022 at 5:40 AM Hongtao Liu <crazylht@gmail.com> wrote:
> > > > >
> > > > > On Thu, Dec 22, 2022 at 6:46 AM Jakub Jelinek <jakub@redhat.com> wrote:
> > > > > >
> > > > > > On Wed, Dec 21, 2022 at 02:43:43PM -0800, H.J. Lu wrote:
> > > > > > > > > > > > >  Target RejectNegative
> > > > > > > > > > > > >  Set 80387 floating-point precision to 80-bit.
> > > > > > > > > > > > >
> > > > > > > > > > > > > +mdaz-ftz
> > > > > > > > > > > > > +Target
> > > > > > > > > > > >
> > > > > > > > > > > > s/Target/Driver/
> > > > > > > > > > > Change to Driver and Got error like:cc1: error: command-line option
> > > > > > > > > > > ‘-mdaz-ftz’ is valid for the driver but not for C.
> > > > > > > > > > Hi Jakub:
> > > > > > > > > >   I didn't find a good solution to handle this error after changing
> > > > > > > > > > *Target* to *Driver*, Could you give some hints how to solve this
> > > > > > > > > > problem?
> > > > > > > > > > Or is it ok for you to mark this as *Target*(there won't be any save
> > > > > > > > > > and restore in cfun since there's no variable defined here.)
> > > > > > > > >
> > > > > > > > > Since all -m* options are passed to cc1, -mdaz-ftz can't be marked
> > > > > > > > > as Driver.  We need to give it a different name to mark it as Driver.
> > > > > > > >
> > > > > > > > It is ok like that.
> > > > > > > >
> > > > > > > >         Jakub
> > > > > > > >
> > > > > > >
> > > > > > > The GCC driver handles -mno-XXX automatically for -mXXX.  Use
> > > > > > > a different name needs to handle the negation.   Or we can do something
> > > > > > > like this to check for CL_DRIVER before passing it to cc1.
> > > > > >
> > > > > > I meant I'm ok with -m{,no-}daz-ftz option being Target rather than Driver.
> > > > > >
> > > > > Thanks.
> > > > > Uros, Is the patch for you?
> > > >
> > > > The original patch is then OK.
> > > Some users found the -mdaz-ftz option to be very useful, and want it
> > > to be backport to GCC12 and GCC11.
> > > But the patch is not a bugfix one, so i'd like to ask options from
> > s/options/opinions/g
> > > other maintainers, if the patch is suitable for backport?
> > >
> > > The backport patches include both this one and [1] which apply
> > > -mdaz-ftz to all other x86 targets.
> > >
> > > [1] https://gcc.gnu.org/pipermail/gcc-patches/2023-January/610053.html
>
> Please make sure to not backport the -ffast-math linker spec change though.
> Also note the 12 branch is currently frozen.
You're meaning don't backport -shared part since it will cause
different behavior between different backends. ?
I'm trying to backport the daz-ftz part, it won't change the existed
behavior for fast-math or shared.
%{mdaz-ftz:crtfastmath.o%s;Ofast|ffast-math|funsafe-math-optimizations:%{!mno-daz-ftz:crtfastmath.o%s}}
>
> I'll defer to x86 maintainers on the -mdaz-ftz flag itself.
>
> Richard.
>
> > > >
> > > > Thanks,
> > > > Uros.
> > >
> > >
> > >
> > > --
> > > BR,
> > > Hongtao
> >
> >
> >
> > --
> > BR,
> > Hongtao
  
Richard Biener May 10, 2023, 6:41 a.m. UTC | #14
On Wed, May 10, 2023 at 3:41 AM Hongtao Liu <crazylht@gmail.com> wrote:
>
> On Thu, May 4, 2023 at 5:49 PM Richard Biener
> <richard.guenther@gmail.com> wrote:
> >
> > On Thu, May 4, 2023 at 7:37 AM Hongtao Liu via Gcc-patches
> > <gcc-patches@gcc.gnu.org> wrote:
> > >
> > > On Thu, May 4, 2023 at 1:35 PM Hongtao Liu <crazylht@gmail.com> wrote:
> > > >
> > > > On Thu, Dec 22, 2022 at 4:04 PM Uros Bizjak <ubizjak@gmail.com> wrote:
> > > > >
> > > > > On Thu, Dec 22, 2022 at 5:40 AM Hongtao Liu <crazylht@gmail.com> wrote:
> > > > > >
> > > > > > On Thu, Dec 22, 2022 at 6:46 AM Jakub Jelinek <jakub@redhat.com> wrote:
> > > > > > >
> > > > > > > On Wed, Dec 21, 2022 at 02:43:43PM -0800, H.J. Lu wrote:
> > > > > > > > > > > > > >  Target RejectNegative
> > > > > > > > > > > > > >  Set 80387 floating-point precision to 80-bit.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > +mdaz-ftz
> > > > > > > > > > > > > > +Target
> > > > > > > > > > > > >
> > > > > > > > > > > > > s/Target/Driver/
> > > > > > > > > > > > Change to Driver and Got error like:cc1: error: command-line option
> > > > > > > > > > > > ‘-mdaz-ftz’ is valid for the driver but not for C.
> > > > > > > > > > > Hi Jakub:
> > > > > > > > > > >   I didn't find a good solution to handle this error after changing
> > > > > > > > > > > *Target* to *Driver*, Could you give some hints how to solve this
> > > > > > > > > > > problem?
> > > > > > > > > > > Or is it ok for you to mark this as *Target*(there won't be any save
> > > > > > > > > > > and restore in cfun since there's no variable defined here.)
> > > > > > > > > >
> > > > > > > > > > Since all -m* options are passed to cc1, -mdaz-ftz can't be marked
> > > > > > > > > > as Driver.  We need to give it a different name to mark it as Driver.
> > > > > > > > >
> > > > > > > > > It is ok like that.
> > > > > > > > >
> > > > > > > > >         Jakub
> > > > > > > > >
> > > > > > > >
> > > > > > > > The GCC driver handles -mno-XXX automatically for -mXXX.  Use
> > > > > > > > a different name needs to handle the negation.   Or we can do something
> > > > > > > > like this to check for CL_DRIVER before passing it to cc1.
> > > > > > >
> > > > > > > I meant I'm ok with -m{,no-}daz-ftz option being Target rather than Driver.
> > > > > > >
> > > > > > Thanks.
> > > > > > Uros, Is the patch for you?
> > > > >
> > > > > The original patch is then OK.
> > > > Some users found the -mdaz-ftz option to be very useful, and want it
> > > > to be backport to GCC12 and GCC11.
> > > > But the patch is not a bugfix one, so i'd like to ask options from
> > > s/options/opinions/g
> > > > other maintainers, if the patch is suitable for backport?
> > > >
> > > > The backport patches include both this one and [1] which apply
> > > > -mdaz-ftz to all other x86 targets.
> > > >
> > > > [1] https://gcc.gnu.org/pipermail/gcc-patches/2023-January/610053.html
> >
> > Please make sure to not backport the -ffast-math linker spec change though.
> > Also note the 12 branch is currently frozen.
> You're meaning don't backport -shared part since it will cause
> different behavior between different backends. ?
> I'm trying to backport the daz-ftz part, it won't change the existed
> behavior for fast-math or shared.
> %{mdaz-ftz:crtfastmath.o%s;Ofast|ffast-math|funsafe-math-optimizations:%{!mno-daz-ftz:crtfastmath.o%s}}

The quoted patch shows -shared in context and  you didn't post a
backport version
to look at.  But yes, we shouldn't change -shared behavior on a
branch, even less so make it
inconsistent between targets.

Richard.

> >
> > I'll defer to x86 maintainers on the -mdaz-ftz flag itself.
> >
> > Richard.
> >
> > > > >
> > > > > Thanks,
> > > > > Uros.
> > > >
> > > >
> > > >
> > > > --
> > > > BR,
> > > > Hongtao
> > >
> > >
> > >
> > > --
> > > BR,
> > > Hongtao
>
>
>
> --
> BR,
> Hongtao
  

Patch

diff --git a/gcc/config/i386/gnu-user-common.h b/gcc/config/i386/gnu-user-common.h
index 9910cd64363..f910524a6c3 100644
--- a/gcc/config/i386/gnu-user-common.h
+++ b/gcc/config/i386/gnu-user-common.h
@@ -47,7 +47,7 @@  along with GCC; see the file COPYING3.  If not see
 
 /* Similar to standard GNU userspace, but adding -ffast-math support.  */
 #define GNU_USER_TARGET_MATHFILE_SPEC \
-  "%{Ofast|ffast-math|funsafe-math-optimizations:%{!shared:crtfastmath.o%s}} \
+  "%{mdaz-ftz:crtfastmath.o%s;Ofast|ffast-math|funsafe-math-optimizations:%{!shared:%{!mno-daz-ftz:crtfastmath.o%s}}} \
    %{mpc32:crtprec32.o%s} \
    %{mpc64:crtprec64.o%s} \
    %{mpc80:crtprec80.o%s}"
diff --git a/gcc/config/i386/i386.opt b/gcc/config/i386/i386.opt
index fb4e57ada7c..0b7df429734 100644
--- a/gcc/config/i386/i386.opt
+++ b/gcc/config/i386/i386.opt
@@ -420,6 +420,10 @@  mpc80
 Target RejectNegative
 Set 80387 floating-point precision to 80-bit.
 
+mdaz-ftz
+Target
+Set the FTZ and DAZ Flags.
+
 mpreferred-stack-boundary=
 Target RejectNegative Joined UInteger Var(ix86_preferred_stack_boundary_arg)
 Attempt to keep stack aligned to this power of 2.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index cba4f19f4f4..7f1d002f228 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -1433,7 +1433,7 @@  See RS/6000 and PowerPC Options.
 -m96bit-long-double  -mlong-double-64  -mlong-double-80  -mlong-double-128 @gol
 -mregparm=@var{num}  -msseregparm @gol
 -mveclibabi=@var{type}  -mvect8-ret-in-mem @gol
--mpc32  -mpc64  -mpc80  -mstackrealign @gol
+-mpc32  -mpc64  -mpc80  -mdaz-ftz -mstackrealign @gol
 -momit-leaf-frame-pointer  -mno-red-zone  -mno-tls-direct-seg-refs @gol
 -mcmodel=@var{code-model}  -mabi=@var{name}  -maddress-mode=@var{mode} @gol
 -m32  -m64  -mx32  -m16  -miamcu  -mlarge-data-threshold=@var{num} @gol
@@ -32753,6 +32753,16 @@  are enabled by default; routines in such libraries could suffer significant
 loss of accuracy, typically through so-called ``catastrophic cancellation'',
 when this option is used to set the precision to less than extended precision.
 
+@item -mdaz-ftz
+@opindex mdaz-ftz
+
+The flush-to-zero (FTZ) and denormals-are-zero (DAZ) flags in the MXCSR register
+are used to control floating-point calculations.SSE and AVX instructions
+including scalar and vector instructions could benefit from enabling the FTZ
+and DAZ flags when @option{-mdaz-ftz} is specified. Don't set FTZ/DAZ flags
+when @option{-mno-daz-ftz} or @option{-shared} is specified, @option{-mdaz-ftz}
+will set FTZ/DAZ flags even with @option{-shared}.
+
 @item -mstackrealign
 @opindex mstackrealign
 Realign the stack at entry.  On the x86, the @option{-mstackrealign}