diff mbox

[GCC/03] New option warning missed optimization on loops whose counter may overflow

Message ID HE1PR0801MB1755F8212E0C116A6FB0E28FE7090@HE1PR0801MB1755.eurprd08.prod.outlook.com
State New
Headers show

Commit Message

Bin Cheng July 21, 2016, 4:50 p.m. UTC
Hi,
This patch adds new option -Wmissed-loop-optimizations warning on loops whose counter may overflow, as well as makes -Wunsafe-loop-optimizations an alias to the new option.
Bootstrap and test on x86_64 ongoing.  Is it OK?

Thanks,
bin

2016-07-20  Bin Cheng  <bin.cheng@arm.com>

	* common.opt (Wmissed-loop-optimizations): New option.
	(Wunsafe-loop-optimizations): Alias to Wmissed-loop-optimizations.
	* doc/invoke.texi (Wmissed-loop-optimizations): Ditto.
	(Wunsafe-loop-optimizations): Alias to Wmissed-loop-optimizations.
	* tree-ssa-loop-niter.c (number_of_iterations_exit): Use option
	Wmissed-loop-optimizations.

Comments

Martin Jambor July 22, 2016, 8:48 a.m. UTC | #1
On Thu, Jul 21, 2016 at 04:50:31PM +0000, Bin Cheng wrote:
> Hi,
> This patch adds new option -Wmissed-loop-optimizations warning on loops whose counter may overflow, as well as makes -Wunsafe-loop-optimizations an alias to the new option.
> Bootstrap and test on x86_64 ongoing.  Is it OK?

I'm repeating myself and since we already have a warning for this it
might make sense to continue having one, but shouldn't we be trying to
move towards the -fopt-info mechanism for optimization feedback?  We
already seem to have OPTGROUP_LOOP even, so could you perhaps consider
also adding a call to

dump_printf_loc (MSG_MISSED_OPTIMIZATION, loc, text)

?

Thanks,

Martin

> 
> Thanks,
> bin
> 
> 2016-07-20  Bin Cheng  <bin.cheng@arm.com>
> 
> 	* common.opt (Wmissed-loop-optimizations): New option.
> 	(Wunsafe-loop-optimizations): Alias to Wmissed-loop-optimizations.
> 	* doc/invoke.texi (Wmissed-loop-optimizations): Ditto.
> 	(Wunsafe-loop-optimizations): Alias to Wmissed-loop-optimizations.
> 	* tree-ssa-loop-niter.c (number_of_iterations_exit): Use option
> 	Wmissed-loop-optimizations.

> diff --git a/gcc/common.opt b/gcc/common.opt
> index 8a292ed..3d62657 100644
> --- a/gcc/common.opt
> +++ b/gcc/common.opt
> @@ -625,7 +625,12 @@ Common Var(warn_null_dereference) Warning
>  Warn if dereferencing a NULL pointer may lead to erroneous or undefined behavior.
>  
>  Wunsafe-loop-optimizations
> -Common Var(warn_unsafe_loop_optimizations) Warning
> +Common Alias(Wmissed-loop-optimizations)
> +Warn if the loop cannot be optimized due to nontrivial assumptions.
> +Same as -Wmissed-loop-optimizations.
> +
> +Wmissed-loop-optimizations
> +Common Var(warn_missed_loop_optimizations) Warning
>  Warn if the loop cannot be optimized due to nontrivial assumptions.
>  
>  Wmissing-noreturn
> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
> index 3041c18..5a2bb09 100644
> --- a/gcc/doc/invoke.texi
> +++ b/gcc/doc/invoke.texi
> @@ -302,8 +302,8 @@ Objective-C and Objective-C++ Dialects}.
>  -Wswitch  -Wswitch-bool  -Wswitch-default  -Wswitch-enum @gol
>  -Wswitch-unreachable  -Wsync-nand @gol
>  -Wsystem-headers  -Wtautological-compare  -Wtrampolines  -Wtrigraphs @gol
> --Wtype-limits  -Wundef @gol
> --Wuninitialized  -Wunknown-pragmas  -Wunsafe-loop-optimizations @gol
> +-Wtype-limits  -Wundef -Wuninitialized  -Wunknown-pragmas @gol
> +-Wmissed-loop-optimizations -Wunsafe-loop-optimizations @gol
>  -Wunsuffixed-float-constants  -Wunused  -Wunused-function @gol
>  -Wunused-label  -Wunused-local-typedefs -Wunused-parameter @gol
>  -Wno-unused-result -Wunused-value @gol -Wunused-variable @gol
> @@ -4990,9 +4990,14 @@ If the stack usage is (partly) dynamic and not bounded, it's:
>  @opindex Wunsafe-loop-optimizations
>  @opindex Wno-unsafe-loop-optimizations
>  Warn if the loop cannot be optimized because the compiler cannot
> -assume anything on the bounds of the loop indices.  With
> -@option{-funsafe-loop-optimizations} warn if the compiler makes
> -such assumptions.
> +assume anything on the bounds of the loop indices.  Same as
> +@option{-Wmissed-loop-optimizations}.
> +
> +@item -Wmissed-loop-optimizations
> +@opindex Wmissed-loop-optimizations
> +@opindex Wno-missed-loop-optimizations
> +Warn if the loop cannot be optimized because the compiler cannot
> +assume anything on the bounds of the loop indices.
>  
>  @item -Wno-pedantic-ms-format @r{(MinGW targets only)}
>  @opindex Wno-pedantic-ms-format
> diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c
> index 2061eafa..38b5552 100644
> --- a/gcc/tree-ssa-loop-niter.c
> +++ b/gcc/tree-ssa-loop-niter.c
> @@ -2333,7 +2333,7 @@ number_of_iterations_exit (struct loop *loop, edge exit,
>  
>        wording = N_("missed loop optimization, the loop counter may overflow");
>        warning_at ((LOCATION_LINE (loc) > 0) ? loc : input_location,
> -		  OPT_Wunsafe_loop_optimizations, "%s", gettext (wording));
> +		  OPT_Wmissed_loop_optimizations, "%s", gettext (wording));
>      }
>  
>    return false;
Bin.Cheng July 22, 2016, 9:05 a.m. UTC | #2
On Fri, Jul 22, 2016 at 9:48 AM, Martin Jambor <mjambor@suse.cz> wrote:
> On Thu, Jul 21, 2016 at 04:50:31PM +0000, Bin Cheng wrote:
>> Hi,
>> This patch adds new option -Wmissed-loop-optimizations warning on loops whose counter may overflow, as well as makes -Wunsafe-loop-optimizations an alias to the new option.
>> Bootstrap and test on x86_64 ongoing.  Is it OK?
>
> I'm repeating myself and since we already have a warning for this it
> might make sense to continue having one, but shouldn't we be trying to
> move towards the -fopt-info mechanism for optimization feedback?  We
> already seem to have OPTGROUP_LOOP even, so could you perhaps consider
> also adding a call to
>
> dump_printf_loc (MSG_MISSED_OPTIMIZATION, loc, text)
>
> ?
Hmm, in this way I will see if I can change this single patch and add
warning message in opt-info category.

Thanks,
bin
>
> Thanks,
>
> Martin
>
diff mbox

Patch

diff --git a/gcc/common.opt b/gcc/common.opt
index 8a292ed..3d62657 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -625,7 +625,12 @@  Common Var(warn_null_dereference) Warning
 Warn if dereferencing a NULL pointer may lead to erroneous or undefined behavior.
 
 Wunsafe-loop-optimizations
-Common Var(warn_unsafe_loop_optimizations) Warning
+Common Alias(Wmissed-loop-optimizations)
+Warn if the loop cannot be optimized due to nontrivial assumptions.
+Same as -Wmissed-loop-optimizations.
+
+Wmissed-loop-optimizations
+Common Var(warn_missed_loop_optimizations) Warning
 Warn if the loop cannot be optimized due to nontrivial assumptions.
 
 Wmissing-noreturn
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 3041c18..5a2bb09 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -302,8 +302,8 @@  Objective-C and Objective-C++ Dialects}.
 -Wswitch  -Wswitch-bool  -Wswitch-default  -Wswitch-enum @gol
 -Wswitch-unreachable  -Wsync-nand @gol
 -Wsystem-headers  -Wtautological-compare  -Wtrampolines  -Wtrigraphs @gol
--Wtype-limits  -Wundef @gol
--Wuninitialized  -Wunknown-pragmas  -Wunsafe-loop-optimizations @gol
+-Wtype-limits  -Wundef -Wuninitialized  -Wunknown-pragmas @gol
+-Wmissed-loop-optimizations -Wunsafe-loop-optimizations @gol
 -Wunsuffixed-float-constants  -Wunused  -Wunused-function @gol
 -Wunused-label  -Wunused-local-typedefs -Wunused-parameter @gol
 -Wno-unused-result -Wunused-value @gol -Wunused-variable @gol
@@ -4990,9 +4990,14 @@  If the stack usage is (partly) dynamic and not bounded, it's:
 @opindex Wunsafe-loop-optimizations
 @opindex Wno-unsafe-loop-optimizations
 Warn if the loop cannot be optimized because the compiler cannot
-assume anything on the bounds of the loop indices.  With
-@option{-funsafe-loop-optimizations} warn if the compiler makes
-such assumptions.
+assume anything on the bounds of the loop indices.  Same as
+@option{-Wmissed-loop-optimizations}.
+
+@item -Wmissed-loop-optimizations
+@opindex Wmissed-loop-optimizations
+@opindex Wno-missed-loop-optimizations
+Warn if the loop cannot be optimized because the compiler cannot
+assume anything on the bounds of the loop indices.
 
 @item -Wno-pedantic-ms-format @r{(MinGW targets only)}
 @opindex Wno-pedantic-ms-format
diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c
index 2061eafa..38b5552 100644
--- a/gcc/tree-ssa-loop-niter.c
+++ b/gcc/tree-ssa-loop-niter.c
@@ -2333,7 +2333,7 @@  number_of_iterations_exit (struct loop *loop, edge exit,
 
       wording = N_("missed loop optimization, the loop counter may overflow");
       warning_at ((LOCATION_LINE (loc) > 0) ? loc : input_location,
-		  OPT_Wunsafe_loop_optimizations, "%s", gettext (wording));
+		  OPT_Wmissed_loop_optimizations, "%s", gettext (wording));
     }
 
   return false;