public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] opts: fix -gtoggle + optimize attribute
@ 2022-02-28  9:03 Martin Liška
  2022-03-01  8:48 ` Richard Biener
  0 siblings, 1 reply; 4+ messages in thread
From: Martin Liška @ 2022-02-28  9:03 UTC (permalink / raw)
  To: gcc-patches

Note -fvar-tracking is enabled automatically with OPT_LEVELS_1_PLUS and
so we need to drop it if we are called from optimize attribute and the
option is unset.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

	PR middle-end/104381

gcc/ChangeLog:

	* opts.cc (finish_options): If debug info is disabled
	(debug_info_level) and -fvar-tracking is unset, disable it.

gcc/testsuite/ChangeLog:

	* gcc.dg/pr104381.c: New test.
---
  gcc/opts.cc                     | 49 +++++++++++++++++++--------------
  gcc/testsuite/gcc.dg/pr104381.c | 20 ++++++++++++++
  2 files changed, 48 insertions(+), 21 deletions(-)
  create mode 100644 gcc/testsuite/gcc.dg/pr104381.c

diff --git a/gcc/opts.cc b/gcc/opts.cc
index 19c68aed065..2370bb0aafe 100644
--- a/gcc/opts.cc
+++ b/gcc/opts.cc
@@ -1302,6 +1302,34 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
      SET_OPTION_IF_UNSET (opts, opts_set, flag_vect_cost_model,
  			 VECT_COST_MODEL_CHEAP);
  
+  if (flag_gtoggle)
+    {
+      /* Make sure to process -gtoggle only once.  */
+      flag_gtoggle = false;
+      if (debug_info_level == DINFO_LEVEL_NONE)
+	{
+	  debug_info_level = DINFO_LEVEL_NORMAL;
+
+	  if (write_symbols == NO_DEBUG)
+	    write_symbols = PREFERRED_DEBUGGING_TYPE;
+	}
+      else
+	debug_info_level = DINFO_LEVEL_NONE;
+    }
+
+  if (!OPTION_SET_P (debug_nonbind_markers_p))
+    debug_nonbind_markers_p
+      = (optimize
+	 && debug_info_level >= DINFO_LEVEL_NORMAL
+	 && dwarf_debuginfo_p ()
+	 && !(flag_selective_scheduling || flag_selective_scheduling2));
+
+  /* Note -fvar-tracking is enabled automatically with OPT_LEVELS_1_PLUS and
+     so we need to drop it if we are called from optimize attribute.  */
+  if (debug_info_level < DINFO_LEVEL_NORMAL
+      && !OPTION_SET_P (flag_var_tracking))
+    flag_var_tracking = false;
+
    /* One could use EnabledBy, but it would lead to a circular dependency.  */
    if (!OPTION_SET_P (flag_var_tracking_uninit))
       flag_var_tracking_uninit = flag_var_tracking;
@@ -1328,27 +1356,6 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
        profile_flag = 0;
      }
  
-  if (flag_gtoggle)
-    {
-      /* Make sure to process -gtoggle only once.  */
-      flag_gtoggle = false;
-      if (debug_info_level == DINFO_LEVEL_NONE)
-	{
-	  debug_info_level = DINFO_LEVEL_NORMAL;
-
-	  if (write_symbols == NO_DEBUG)
-	    write_symbols = PREFERRED_DEBUGGING_TYPE;
-	}
-      else
-	debug_info_level = DINFO_LEVEL_NONE;
-    }
-
-  if (!OPTION_SET_P (debug_nonbind_markers_p))
-    debug_nonbind_markers_p
-      = (optimize
-	 && debug_info_level >= DINFO_LEVEL_NORMAL
-	 && dwarf_debuginfo_p ()
-	 && !(flag_selective_scheduling || flag_selective_scheduling2));
  
    diagnose_options (opts, opts_set, loc);
  }
diff --git a/gcc/testsuite/gcc.dg/pr104381.c b/gcc/testsuite/gcc.dg/pr104381.c
new file mode 100644
index 00000000000..a3aec919bee
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr104381.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -g -gtoggle -fdump-tree-optimized" } */
+
+int foo (int x)
+{
+  int tem = x + 1;
+  int tem2 = tem - 1;
+  return tem2;
+}
+
+int
+__attribute__((optimize("no-tree-pre")))
+bar (int x)
+{
+  int tem = x + 1;
+  int tem2 = tem - 1;
+  return tem2;
+}
+
+// { dg-final { scan-tree-dump-not "DEBUG " "optimized" } }
-- 
2.35.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] opts: fix -gtoggle + optimize attribute
  2022-02-28  9:03 [PATCH] opts: fix -gtoggle + optimize attribute Martin Liška
@ 2022-03-01  8:48 ` Richard Biener
  2022-03-04 13:12   ` Martin Liška
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Biener @ 2022-03-01  8:48 UTC (permalink / raw)
  To: Martin Liška; +Cc: GCC Patches

On Mon, Feb 28, 2022 at 10:03 AM Martin Liška <mliska@suse.cz> wrote:
>
> Note -fvar-tracking is enabled automatically with OPT_LEVELS_1_PLUS and
> so we need to drop it if we are called from optimize attribute and the
> option is unset.
>
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> Ready to be installed?
> Thanks,
> Martin
>
>         PR middle-end/104381
>
> gcc/ChangeLog:
>
>         * opts.cc (finish_options): If debug info is disabled
>         (debug_info_level) and -fvar-tracking is unset, disable it.
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.dg/pr104381.c: New test.
> ---
>   gcc/opts.cc                     | 49 +++++++++++++++++++--------------
>   gcc/testsuite/gcc.dg/pr104381.c | 20 ++++++++++++++
>   2 files changed, 48 insertions(+), 21 deletions(-)
>   create mode 100644 gcc/testsuite/gcc.dg/pr104381.c
>
> diff --git a/gcc/opts.cc b/gcc/opts.cc
> index 19c68aed065..2370bb0aafe 100644
> --- a/gcc/opts.cc
> +++ b/gcc/opts.cc
> @@ -1302,6 +1302,34 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
>       SET_OPTION_IF_UNSET (opts, opts_set, flag_vect_cost_model,
>                          VECT_COST_MODEL_CHEAP);
>
> +  if (flag_gtoggle)
> +    {
> +      /* Make sure to process -gtoggle only once.  */
> +      flag_gtoggle = false;
> +      if (debug_info_level == DINFO_LEVEL_NONE)
> +       {
> +         debug_info_level = DINFO_LEVEL_NORMAL;
> +
> +         if (write_symbols == NO_DEBUG)
> +           write_symbols = PREFERRED_DEBUGGING_TYPE;
> +       }
> +      else
> +       debug_info_level = DINFO_LEVEL_NONE;
> +    }
> +
> +  if (!OPTION_SET_P (debug_nonbind_markers_p))
> +    debug_nonbind_markers_p
> +      = (optimize
> +        && debug_info_level >= DINFO_LEVEL_NORMAL
> +        && dwarf_debuginfo_p ()
> +        && !(flag_selective_scheduling || flag_selective_scheduling2));
> +
> +  /* Note -fvar-tracking is enabled automatically with OPT_LEVELS_1_PLUS and
> +     so we need to drop it if we are called from optimize attribute.  */
> +  if (debug_info_level < DINFO_LEVEL_NORMAL
> +      && !OPTION_SET_P (flag_var_tracking))
> +    flag_var_tracking = false;
> +

I think moving flag_gtoggle handling before the flag_syntax_only handling
is a good thing.  But I don't quite understand the flag_var_tracking disabling
or how it worked before.  At least I think you want to check for
debug_info_level == NONE, no?  Why should DINFO_LEVEL_TERSE be
special?

>     /* One could use EnabledBy, but it would lead to a circular dependency.  */
>     if (!OPTION_SET_P (flag_var_tracking_uninit))
>        flag_var_tracking_uninit = flag_var_tracking;
> @@ -1328,27 +1356,6 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
>         profile_flag = 0;
>       }
>
> -  if (flag_gtoggle)
> -    {
> -      /* Make sure to process -gtoggle only once.  */
> -      flag_gtoggle = false;
> -      if (debug_info_level == DINFO_LEVEL_NONE)
> -       {
> -         debug_info_level = DINFO_LEVEL_NORMAL;
> -
> -         if (write_symbols == NO_DEBUG)
> -           write_symbols = PREFERRED_DEBUGGING_TYPE;
> -       }
> -      else
> -       debug_info_level = DINFO_LEVEL_NONE;
> -    }
> -
> -  if (!OPTION_SET_P (debug_nonbind_markers_p))
> -    debug_nonbind_markers_p
> -      = (optimize
> -        && debug_info_level >= DINFO_LEVEL_NORMAL
> -        && dwarf_debuginfo_p ()
> -        && !(flag_selective_scheduling || flag_selective_scheduling2));
>
>     diagnose_options (opts, opts_set, loc);
>   }
> diff --git a/gcc/testsuite/gcc.dg/pr104381.c b/gcc/testsuite/gcc.dg/pr104381.c
> new file mode 100644
> index 00000000000..a3aec919bee
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/pr104381.c
> @@ -0,0 +1,20 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -g -gtoggle -fdump-tree-optimized" } */
> +
> +int foo (int x)
> +{
> +  int tem = x + 1;
> +  int tem2 = tem - 1;
> +  return tem2;
> +}
> +
> +int
> +__attribute__((optimize("no-tree-pre")))
> +bar (int x)
> +{
> +  int tem = x + 1;
> +  int tem2 = tem - 1;
> +  return tem2;
> +}
> +
> +// { dg-final { scan-tree-dump-not "DEBUG " "optimized" } }
> --
> 2.35.1
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] opts: fix -gtoggle + optimize attribute
  2022-03-01  8:48 ` Richard Biener
@ 2022-03-04 13:12   ` Martin Liška
  2022-03-07 13:48     ` Richard Biener
  0 siblings, 1 reply; 4+ messages in thread
From: Martin Liška @ 2022-03-04 13:12 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 893 bytes --]

On 3/1/22 09:48, Richard Biener wrote:
> I think moving flag_gtoggle handling before the flag_syntax_only handling
> is a good thing.  But I don't quite understand the flag_var_tracking disabling
> or how it worked before.

Well, as you know, the debugging options are a can of worms. During GCC 12 development I moved
most of the option logic to finish_options which is a place that is used both for command line
option processing and optimize/target pragma/attribute processing.

That's why we see this problem. OPT_LEVELS_1_PLUS enables flag_var_tracking but we have to drop
debug debug_info_level == DINFO_LEVEL_NONE.

> At least I think you want to check for
> debug_info_level == NONE, no?  Why should DINFO_LEVEL_TERSE be
> special?

No, sending updated version of the patch.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

[-- Attachment #2: 0001-opts-fix-gtoggle-optimize-attribute.patch --]
[-- Type: text/x-patch, Size: 3505 bytes --]

From 1d9f77f00f208cca4142abc9c56995b865291229 Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Fri, 4 Feb 2022 15:50:17 +0100
Subject: [PATCH] opts: fix -gtoggle + optimize attribute

Note -fvar-tracking is enabled automatically with OPT_LEVELS_1_PLUS and
so we need to drop it if we are called from optimize attribute and the
option is unset.

	PR middle-end/104381

gcc/ChangeLog:

	* opts.cc (finish_options): If debug info is disabled
	(debug_info_level) and -fvar-tracking is unset, disable it.

gcc/testsuite/ChangeLog:

	* gcc.dg/pr104381.c: New test.
---
 gcc/opts.cc                     | 49 +++++++++++++++++++--------------
 gcc/testsuite/gcc.dg/pr104381.c | 20 ++++++++++++++
 2 files changed, 48 insertions(+), 21 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr104381.c

diff --git a/gcc/opts.cc b/gcc/opts.cc
index 19c68aed065..ef5fe9b11ca 100644
--- a/gcc/opts.cc
+++ b/gcc/opts.cc
@@ -1302,6 +1302,34 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
     SET_OPTION_IF_UNSET (opts, opts_set, flag_vect_cost_model,
 			 VECT_COST_MODEL_CHEAP);
 
+  if (flag_gtoggle)
+    {
+      /* Make sure to process -gtoggle only once.  */
+      flag_gtoggle = false;
+      if (debug_info_level == DINFO_LEVEL_NONE)
+	{
+	  debug_info_level = DINFO_LEVEL_NORMAL;
+
+	  if (write_symbols == NO_DEBUG)
+	    write_symbols = PREFERRED_DEBUGGING_TYPE;
+	}
+      else
+	debug_info_level = DINFO_LEVEL_NONE;
+    }
+
+  if (!OPTION_SET_P (debug_nonbind_markers_p))
+    debug_nonbind_markers_p
+      = (optimize
+	 && debug_info_level >= DINFO_LEVEL_NORMAL
+	 && dwarf_debuginfo_p ()
+	 && !(flag_selective_scheduling || flag_selective_scheduling2));
+
+  /* Note -fvar-tracking is enabled automatically with OPT_LEVELS_1_PLUS and
+     so we need to drop it if we are called from optimize attribute.  */
+  if (debug_info_level == DINFO_LEVEL_NONE
+      && !OPTION_SET_P (flag_var_tracking))
+    flag_var_tracking = false;
+
   /* One could use EnabledBy, but it would lead to a circular dependency.  */
   if (!OPTION_SET_P (flag_var_tracking_uninit))
      flag_var_tracking_uninit = flag_var_tracking;
@@ -1328,27 +1356,6 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
       profile_flag = 0;
     }
 
-  if (flag_gtoggle)
-    {
-      /* Make sure to process -gtoggle only once.  */
-      flag_gtoggle = false;
-      if (debug_info_level == DINFO_LEVEL_NONE)
-	{
-	  debug_info_level = DINFO_LEVEL_NORMAL;
-
-	  if (write_symbols == NO_DEBUG)
-	    write_symbols = PREFERRED_DEBUGGING_TYPE;
-	}
-      else
-	debug_info_level = DINFO_LEVEL_NONE;
-    }
-
-  if (!OPTION_SET_P (debug_nonbind_markers_p))
-    debug_nonbind_markers_p
-      = (optimize
-	 && debug_info_level >= DINFO_LEVEL_NORMAL
-	 && dwarf_debuginfo_p ()
-	 && !(flag_selective_scheduling || flag_selective_scheduling2));
 
   diagnose_options (opts, opts_set, loc);
 }
diff --git a/gcc/testsuite/gcc.dg/pr104381.c b/gcc/testsuite/gcc.dg/pr104381.c
new file mode 100644
index 00000000000..a3aec919bee
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr104381.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -g -gtoggle -fdump-tree-optimized" } */
+
+int foo (int x)
+{
+  int tem = x + 1;
+  int tem2 = tem - 1;
+  return tem2;
+}
+
+int
+__attribute__((optimize("no-tree-pre")))
+bar (int x)
+{
+  int tem = x + 1;
+  int tem2 = tem - 1;
+  return tem2;
+}
+
+// { dg-final { scan-tree-dump-not "DEBUG " "optimized" } }
-- 
2.35.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] opts: fix -gtoggle + optimize attribute
  2022-03-04 13:12   ` Martin Liška
@ 2022-03-07 13:48     ` Richard Biener
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Biener @ 2022-03-07 13:48 UTC (permalink / raw)
  To: Martin Liška; +Cc: GCC Patches

On Fri, Mar 4, 2022 at 2:12 PM Martin Liška <mliska@suse.cz> wrote:
>
> On 3/1/22 09:48, Richard Biener wrote:
> > I think moving flag_gtoggle handling before the flag_syntax_only handling
> > is a good thing.  But I don't quite understand the flag_var_tracking disabling
> > or how it worked before.
>
> Well, as you know, the debugging options are a can of worms. During GCC 12 development I moved
> most of the option logic to finish_options which is a place that is used both for command line
> option processing and optimize/target pragma/attribute processing.
>
> That's why we see this problem. OPT_LEVELS_1_PLUS enables flag_var_tracking but we have to drop
> debug debug_info_level == DINFO_LEVEL_NONE.
>
> > At least I think you want to check for
> > debug_info_level == NONE, no?  Why should DINFO_LEVEL_TERSE be
> > special?
>
> No, sending updated version of the patch.
>
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> Ready to be installed?

OK.

> Thanks,
> Martin

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-03-07 13:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-28  9:03 [PATCH] opts: fix -gtoggle + optimize attribute Martin Liška
2022-03-01  8:48 ` Richard Biener
2022-03-04 13:12   ` Martin Liška
2022-03-07 13:48     ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).