On Thu, Aug 14, 2025 at 5:37 AM H.J. Lu <hjl.to...@gmail.com> wrote: > > On Wed, Aug 13, 2025 at 11:33 PM Uros Bizjak <ubiz...@gmail.com> wrote: > > > > On Thu, Aug 14, 2025 at 6:58 AM H.J. Lu <hjl.to...@gmail.com> wrote: > > > > > > Add target("80387") attribute to enable and disable x87 instructions in a > > > function. > > > > > > gcc/ > > > > > > PR target/121541 > > > * config/i386/i386-options.cc > > > (ix86_valid_target_attribute_inner_p): Add a bool argument to > > > return if x87 is disabled by target("no-80387") attribute. Add > > > and handle target("80387") attribute. > > > (ix86_valid_target_attribute_tree): Get the x87 info from > > > ix86_valid_target_attribute_inner_p and pass the info to > > > ix86_option_override_internal. > > > (ix86_option_override_internal): Add a bool argument to indicate > > > if x87 should be disabled. Don't enable x87 if it should be > > > disabled. > > > (ix86_option_override): Pass false to > > > ix86_option_override_internal. > > > * doc/extend.texi: Document target("80387") function attribute. > > > > > > gcc/testsuite/ > > > > > > PR target/121541 > > > * gcc.target/i386/pr121541-1a.c: New test. > > > * gcc.target/i386/pr121541-1b.c: Likewise. > > > * gcc.target/i386/pr121541-2.c: Likewise. > > > * gcc.target/i386/pr121541-3.c: Likewise. > > > * gcc.target/i386/pr121541-4.c: Likewise. > > > * gcc.target/i386/pr121541-5a.c: Likewise. > > > * gcc.target/i386/pr121541-5b.c: Likewise. > > > > > > Signed-off-by: H.J. Lu <hjl.to...@gmail.com> > > > --- > > > gcc/config/i386/i386-options.cc | 42 +++++++++++++++------ > > > gcc/doc/extend.texi | 5 +++ > > > gcc/testsuite/gcc.target/i386/pr121541-1a.c | 11 ++++++ > > > gcc/testsuite/gcc.target/i386/pr121541-1b.c | 6 +++ > > > gcc/testsuite/gcc.target/i386/pr121541-2.c | 11 ++++++ > > > gcc/testsuite/gcc.target/i386/pr121541-3.c | 11 ++++++ > > > gcc/testsuite/gcc.target/i386/pr121541-4.c | 11 ++++++ > > > gcc/testsuite/gcc.target/i386/pr121541-5a.c | 11 ++++++ > > > gcc/testsuite/gcc.target/i386/pr121541-5b.c | 6 +++ > > > 9 files changed, 102 insertions(+), 12 deletions(-) > > > create mode 100644 gcc/testsuite/gcc.target/i386/pr121541-1a.c > > > create mode 100644 gcc/testsuite/gcc.target/i386/pr121541-1b.c > > > create mode 100644 gcc/testsuite/gcc.target/i386/pr121541-2.c > > > create mode 100644 gcc/testsuite/gcc.target/i386/pr121541-3.c > > > create mode 100644 gcc/testsuite/gcc.target/i386/pr121541-4.c > > > create mode 100644 gcc/testsuite/gcc.target/i386/pr121541-5a.c > > > create mode 100644 gcc/testsuite/gcc.target/i386/pr121541-5b.c > > > > > > diff --git a/gcc/config/i386/i386-options.cc > > > b/gcc/config/i386/i386-options.cc > > > index 09a35ef6298..30c10bed6bc 100644 > > > --- a/gcc/config/i386/i386-options.cc > > > +++ b/gcc/config/i386/i386-options.cc > > > @@ -825,7 +825,8 @@ STATIC_ASSERT (ARRAY_SIZE (processor_cost_table) == > > > PROCESSOR_max); > > > static bool > > > ix86_option_override_internal (bool main_args_p, > > > struct gcc_options *opts, > > > - struct gcc_options *opts_set); > > > + struct gcc_options *opts_set, > > > + bool disable_80387); > > > > m80387 option is a target option just like e.g. mrecip, so it should > > be processed in the same way. A new bool argument should not be > > needed, everything you need should be available via *opts and > > *opts_set. > > It doesn't work because > > /* Don't enable x87 instructions if only general registers are > allowed by target("general-regs-only") function attribute or > -mgeneral-regs-only. */ > if (!(opts->x_ix86_target_flags & OPTION_MASK_GENERAL_REGS_ONLY) > && !(opts_set->x_target_flags & MASK_80387)) > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > When MASK_80387 in opts_set and opts are cleared by target("80387") > function attribute, MASK_80387 will be turned on again without > target("general-regs-only") function attribute nor -mgeneral-regs-only. > > { > if (((processor_alias_table[i].flags & PTA_NO_80387) != 0)) > opts->x_target_flags &= ~MASK_80387; > else > opts->x_target_flags |= MASK_80387; > } >
Fixed in the v2 patch by updating opts_set->x_target_flags: @@ -1281,6 +1285,8 @@ ix86_valid_target_attribute_inner_p (tree fndecl, tree args, char *p_strings[], else if (type == ix86_opt_yes || type == ix86_opt_no) { + opts_set->x_target_flags |= mask; + if (type == ix86_opt_no) opt_set_p = !opt_set_p; -- H.J.