diff mbox

[RFC] Warn when optimization flag is given without -O

Message ID alpine.LNX.2.00.1204281841520.5002@monoid.intra.ispras.ru
State New
Headers show

Commit Message

Alexander Monakov April 28, 2012, 2:48 p.m. UTC
Looks like people who want to play with optimization options are still tripped
by the fact that optimizations are not enabled unless -O is given (even though
it's documented in the manual now).  Can we add a warning for that like below?

Untested beside bubblestrap.  I suppose this will produce noise for -O0
torture testsuite — what is the recommended way to fix that?

Comments

Richard Biener May 2, 2012, 8:56 a.m. UTC | #1
On Sat, Apr 28, 2012 at 4:48 PM, Alexander Monakov <amonakov@ispras.ru> wrote:
>
> Looks like people who want to play with optimization options are still tripped
> by the fact that optimizations are not enabled unless -O is given (even though
> it's documented in the manual now).  Can we add a warning for that like below?
>
> Untested beside bubblestrap.  I suppose this will produce noise for -O0
> torture testsuite — what is the recommended way to fix that?
>
> diff --git a/gcc/opts-common.c b/gcc/opts-common.c
> index 354bce0..a18a89d 100644
> --- a/gcc/opts-common.c
> +++ b/gcc/opts-common.c
> @@ -1056,6 +1056,11 @@ read_cmdline_option (struct gcc_options *opts,
>   if (!handle_option (opts, opts_set, decoded, lang_mask, DK_UNSPECIFIED,
>                      loc, handlers, false, dc))
>     error_at (loc, "unrecognized command line option %qs", opt);
> +
> +  if ((option->flags & CL_OPTIMIZATION)

That's surely too coarse - you will warn about options that _will_
have an effect.
There is currently no easy way to glob all affected options.

I don't think we want to warn about -O2 -ftree-pre -O0 either, nor
about -fno-tree-pre.

Overall I would expect people to have noticed that with -O0 these options have
no effect when they've gone all the way to figure out the separate optimization
options, no?

Thanks,
Richard.

> +      && !opts->x_optimize)
> +    warning_at (loc, 0, "optimization option %qs has no effect "
> +               "at zero -O level", opt);
>  }
>
>  /* Set any field in OPTS, and OPTS_SET if not NULL, for option
Alexander Monakov May 2, 2012, 10:03 a.m. UTC | #2
On Wed, 2 May 2012, Richard Guenther wrote:

> That's surely too coarse - you will warn about options that _will_
> have an effect.
> There is currently no easy way to glob all affected options.

Yeah, that's unfortunate.  Do we want to have a separate flag
(CL_OPTIMIZATION_O0) to mark such options?  Apropos, following is a list of
options that affect the list of produced dump files at O0.  If someone knows
an option that affects compilation at O0, but is not a part of this list,
please let me know.

-fbranch-probabilities
-fbranch-target-load-optimize
-fcombine-stack-adjustments
-fexceptions
-fhandle-exceptions
-fschedule-insns
-fsplit-wide-types
-fvar-tracking-assignments
-fvar-tracking-assignments-toggle

> I don't think we want to warn about -O2 -ftree-pre -O0 either, nor

Huh, I don't see why.  Please explain?

> about -fno-tree-pre.

Yeah, that's an oversight in the patch, should be easy to fix.
 
> Overall I would expect people to have noticed that with -O0 these options have
> no effect when they've gone all the way to figure out the separate optimization
> options, no?

At the moment people have two easy ways to find the list of optimization
options (-fverbose-asm and --help=optimizers), but O0 issue is mentioned
once not-quite-prominently in the manual and also in the FAQ in the wiki.
In my opinion, the amount of times I've seen this issue come up warrants
some effort on making it more visible (thus, a warning).

Thanks
Alexander
Richard Biener May 2, 2012, 10:18 a.m. UTC | #3
On Wed, May 2, 2012 at 12:03 PM, Alexander Monakov <amonakov@ispras.ru> wrote:
>
>
> On Wed, 2 May 2012, Richard Guenther wrote:
>
>> That's surely too coarse - you will warn about options that _will_
>> have an effect.
>> There is currently no easy way to glob all affected options.
>
> Yeah, that's unfortunate.  Do we want to have a separate flag
> (CL_OPTIMIZATION_O0) to mark such options?  Apropos, following is a list of
> options that affect the list of produced dump files at O0.  If someone knows
> an option that affects compilation at O0, but is not a part of this list,
> please let me know.
>
> -fbranch-probabilities
> -fbranch-target-load-optimize
> -fcombine-stack-adjustments
> -fexceptions
> -fhandle-exceptions
> -fschedule-insns
> -fsplit-wide-types
> -fvar-tracking-assignments
> -fvar-tracking-assignments-toggle
>
>> I don't think we want to warn about -O2 -ftree-pre -O0 either, nor
>
> Huh, I don't see why.  Please explain?

Because I routinely append -O0 to an existing command-line to disable
optimization.  I don't want to be spammed with unconditional warnings for this
(btw, I think it should be a note(), not a warning).

>> about -fno-tree-pre.
>
> Yeah, that's an oversight in the patch, should be easy to fix.
>
>> Overall I would expect people to have noticed that with -O0 these options have
>> no effect when they've gone all the way to figure out the separate optimization
>> options, no?
>
> At the moment people have two easy ways to find the list of optimization
> options (-fverbose-asm and --help=optimizers), but O0 issue is mentioned
> once not-quite-prominently in the manual and also in the FAQ in the wiki.
> In my opinion, the amount of times I've seen this issue come up warrants
> some effort on making it more visible (thus, a warning).

So maybe prominently say that in the output of --help=optimizers (-fverbose-asm
isn't to be found easily anyway).  Thus, at the end of --help-optimizers print
"Note: without any -On option, excluding -O0, most options do not have any
effect"

Richard.

> Thanks
> Alexander
diff mbox

Patch

diff --git a/gcc/opts-common.c b/gcc/opts-common.c
index 354bce0..a18a89d 100644
--- a/gcc/opts-common.c
+++ b/gcc/opts-common.c
@@ -1056,6 +1056,11 @@  read_cmdline_option (struct gcc_options *opts,
   if (!handle_option (opts, opts_set, decoded, lang_mask, DK_UNSPECIFIED,
 		      loc, handlers, false, dc))
     error_at (loc, "unrecognized command line option %qs", opt);
+
+  if ((option->flags & CL_OPTIMIZATION)
+      && !opts->x_optimize)
+    warning_at (loc, 0, "optimization option %qs has no effect "
+		"at zero -O level", opt);
 }
 
 /* Set any field in OPTS, and OPTS_SET if not NULL, for option