public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/30730]  New: -Wunsafe-loop-optimizations gives too many warnings
@ 2007-02-07 20:25 roland dot illig at gmx dot de
  2007-02-08  9:34 ` [Bug tree-optimization/30730] " rguenth at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: roland dot illig at gmx dot de @ 2007-02-07 20:25 UTC (permalink / raw)
  To: gcc-bugs

$ cat > warning.c
#if 0
gcc-4.1.1 -c -Os warning.c -Wunsafe-loop-optimizations
exit 0
#endif

void foo(unsigned int n)
{
        while (n > 10)
                n -= 2;
}
^D

$ sh warning.c
warning.c: In function 'foo':
warning.c:8: warning: cannot optimize loop, the loop counter may overflow
warning.c:8: warning: cannot optimize loop, the loop counter may overflow
...

This warning seems to be wrong to me, or at least badly worded. Furthermore,
gcc should notice that the condition states "n >= 10", and n is decremented by
only 2 in each iteration, so the loop _will_ terminate. There won't be any
overflow.

It would also be nice if this warning were only printed once instead of 9
times.


-- 
           Summary: -Wunsafe-loop-optimizations gives too many warnings
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: roland dot illig at gmx dot de
 GCC build triplet: any
  GCC host triplet: any
GCC target triplet: any


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30730


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

* [Bug tree-optimization/30730] -Wunsafe-loop-optimizations gives too many warnings
  2007-02-07 20:25 [Bug c/30730] New: -Wunsafe-loop-optimizations gives too many warnings roland dot illig at gmx dot de
@ 2007-02-08  9:34 ` rguenth at gcc dot gnu dot org
  2007-02-08  9:38 ` rakdver at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2007-02-08  9:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2007-02-08 09:34 -------
Confirmed.  The duplicate warnings are annoying.  Note that the warning is
emitted because we change n -= 2 to n += 4294967294 (oops).

>From the .original tree dump:

{
  goto <D1972>;
  <D1971>:;
  n = n + 4294967294;
  <D1972>:;
  if (n > 10) goto <D1971>; else goto <D1973>;
  <D1973>:;
}

this is because 2 is easily negatable and the canonical form in this case
is an addition.  While we can fix that, the loop optimizer should be fixed
as well to note that this unsigned addition is just a subtraction of two.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu dot
                   |                            |org, rakdver at gcc dot gnu
                   |                            |dot org
             Status|UNCONFIRMED                 |NEW
          Component|c                           |tree-optimization
     Ever Confirmed|0                           |1
  GCC build triplet|any                         |
   GCC host triplet|any                         |
 GCC target triplet|any                         |
           Keywords|                            |diagnostic
   Last reconfirmed|0000-00-00 00:00:00         |2007-02-08 09:34:14
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30730


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

* [Bug tree-optimization/30730] -Wunsafe-loop-optimizations gives too many warnings
  2007-02-07 20:25 [Bug c/30730] New: -Wunsafe-loop-optimizations gives too many warnings roland dot illig at gmx dot de
  2007-02-08  9:34 ` [Bug tree-optimization/30730] " rguenth at gcc dot gnu dot org
@ 2007-02-08  9:38 ` rakdver at gcc dot gnu dot org
  2007-03-14  0:39 ` rakdver at gcc dot gnu dot org
  2007-07-10  8:31 ` spop at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: rakdver at gcc dot gnu dot org @ 2007-02-08  9:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rakdver at gcc dot gnu dot org  2007-02-08 09:38 -------
> Note that the warning is
> emitted because we change n -= 2 to n += 4294967294 (oops).
> this is because 2 is easily negatable and the canonical form in this case
> is an addition.  While we can fix that,

No, you cannot -- loop optimizer would represent n-=2 this way in any case.

> the loop optimizer should be fixed
> as well to note that this unsigned addition is just a subtraction of two.

Loop optimizers are aware of this on most places.


-- 

rakdver at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |rakdver at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2007-02-08 09:34:14         |2007-02-08 09:38:28
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30730


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

* [Bug tree-optimization/30730] -Wunsafe-loop-optimizations gives too many warnings
  2007-02-07 20:25 [Bug c/30730] New: -Wunsafe-loop-optimizations gives too many warnings roland dot illig at gmx dot de
  2007-02-08  9:34 ` [Bug tree-optimization/30730] " rguenth at gcc dot gnu dot org
  2007-02-08  9:38 ` rakdver at gcc dot gnu dot org
@ 2007-03-14  0:39 ` rakdver at gcc dot gnu dot org
  2007-07-10  8:31 ` spop at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: rakdver at gcc dot gnu dot org @ 2007-03-14  0:39 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from rakdver at gcc dot gnu dot org  2007-03-14 00:39 -------
Subject: Bug 30730

Author: rakdver
Date: Wed Mar 14 00:38:34 2007
New Revision: 122896

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122896
Log:
        PR tree-optimization/30730
        PR tree-optimization/26900
        * tree-ssa-loop-niter.c: Include gmp.h.
        (bounds): New type.
        (mpz_set_double_int, get_type_bounds, mpz_to_double_int,
        split_to_var_and_offset, determine_value_range,
        bound_difference_of_offsetted_base, refine_bounds_using_guard,
        bound_difference, bounds_add, bounds_negate,
        number_of_iterations_ne_max, dump_affine_iv): New functions.
        (number_of_iterations_ne, number_of_iterations_lt_to_ne,
        assert_loop_rolls_lt, assert_loop_rolls_le): Use bounds on the
        difference of initial and final value of control iv to validate
        results.
        (number_of_iterations_cond): Add loop parameter.  Determine bounds
        on the difference of the extremes of the control iv.  Add dumps.
        (expand_simple_operations): Handle phi nodes.
        (simplify_using_initial_conditions): Do not record used conditions.
        (number_of_iterations_exit): Pass loop to number_of_iterations_cond.
        Do not set additional_info.
        (implies_nonnegative_p, implies_ge_p): Removed.
        (derive_constant_upper_bound): Do not use parameter `additional'.
        (record_estimate): Parameter `additional' removed.  Parameter
        `i_bound' added.  Do not call derive_constant_upper_bound.
        (record_nonwrapping_iv): Use derive_constant_upper_bound to
        bound the number of iterations estimate.
        (estimate_numbers_of_iterations_loop): Pass the estimate from
        the number of iterations analysis to record_estimate.
        * tree.h (multiple_of_p): Declare.
        * tree-scalar-evolution.c (expression_expensive_p): Removed.
        (scev_const_prop): Do not check expression_expensive_p.
        * fold-const.c (multiple_of_p): Exported.
        * double-int.c (double_int_mask): Exported.
        * double-int.h (double_int_mask): Declare.
        * tree-flow.h (struct tree_niter_desc): Removed additional_info
        field.  Added max field.

        * gcc.dg/tree-ssa/loop-26.c: New test.


Added:
    trunk/gcc/testsuite/gcc.dg/tree-ssa/loop-26.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/double-int.c
    trunk/gcc/double-int.h
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-flow.h
    trunk/gcc/tree-scalar-evolution.c
    trunk/gcc/tree-ssa-loop-niter.c
    trunk/gcc/tree.h


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30730


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

* [Bug tree-optimization/30730] -Wunsafe-loop-optimizations gives too many warnings
  2007-02-07 20:25 [Bug c/30730] New: -Wunsafe-loop-optimizations gives too many warnings roland dot illig at gmx dot de
                   ` (2 preceding siblings ...)
  2007-03-14  0:39 ` rakdver at gcc dot gnu dot org
@ 2007-07-10  8:31 ` spop at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: spop at gcc dot gnu dot org @ 2007-07-10  8:31 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from spop at gcc dot gnu dot org  2007-07-10 08:31 -------
Fixed.


-- 

spop at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30730


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

end of thread, other threads:[~2007-07-10  8:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-07 20:25 [Bug c/30730] New: -Wunsafe-loop-optimizations gives too many warnings roland dot illig at gmx dot de
2007-02-08  9:34 ` [Bug tree-optimization/30730] " rguenth at gcc dot gnu dot org
2007-02-08  9:38 ` rakdver at gcc dot gnu dot org
2007-03-14  0:39 ` rakdver at gcc dot gnu dot org
2007-07-10  8:31 ` spop at gcc dot gnu dot org

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).