public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/19659] New: GCC does remove an "if" statement that never triggers.
@ 2005-01-27 19:59 kazu at cs dot umass dot edu
  2005-01-27 20:24 ` [Bug tree-optimization/19659] GCC does not " steven at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: kazu at cs dot umass dot edu @ 2005-01-27 19:59 UTC (permalink / raw)
  To: gcc-bugs

extern void abort (void) __attribute__ ((__noreturn__));

/* Count up to *LENGTHP and then return 0.  */

int
foo (unsigned *lengthp)
{
  unsigned index;

  for (index = 0; index != *lengthp; index++)
    {
      const unsigned *lengthp2 = lengthp;

      /* Note that this condition is never true.  */
      if (index >= *lengthp2)
	abort ();
    }

  return 0;
}

GCC does not remove the "if" statement even though it never triggers.

Interestingly, if you remove "const" from the testcase above, GCC does
remove the "if" statement.

If you feed the testcase with "const" into GCC, CSE removes it.
Hey, but isn't this a machine-independent optimization?

-- 
           Summary: GCC does remove an "if" statement that never triggers.
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Keywords: missed-optimization, TREE
          Severity: enhancement
          Priority: P2
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kazu at cs dot umass dot edu
                CC: gcc-bugs at gcc dot gnu dot org


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


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

* [Bug tree-optimization/19659] GCC does not remove an "if" statement that never triggers.
  2005-01-27 19:59 [Bug tree-optimization/19659] New: GCC does remove an "if" statement that never triggers kazu at cs dot umass dot edu
@ 2005-01-27 20:24 ` steven at gcc dot gnu dot org
  2005-01-27 20:34 ` pinskia at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: steven at gcc dot gnu dot org @ 2005-01-27 20:24 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2005-01-27 20:23:21
               date|                            |
            Summary|GCC does remove an "if"     |GCC does not remove an "if"
                   |statement that never        |statement that never
                   |triggers.                   |triggers.


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


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

* [Bug tree-optimization/19659] GCC does not remove an "if" statement that never triggers.
  2005-01-27 19:59 [Bug tree-optimization/19659] New: GCC does remove an "if" statement that never triggers kazu at cs dot umass dot edu
  2005-01-27 20:24 ` [Bug tree-optimization/19659] GCC does not " steven at gcc dot gnu dot org
@ 2005-01-27 20:34 ` pinskia at gcc dot gnu dot org
  2005-01-27 21:26 ` steven at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-01-27 20:34 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-01-27 20:29 -------
This is related to PR 18178 (which is the java equivant) by the way.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
  BugsThisDependsOn|                            |18178


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


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

* [Bug tree-optimization/19659] GCC does not remove an "if" statement that never triggers.
  2005-01-27 19:59 [Bug tree-optimization/19659] New: GCC does remove an "if" statement that never triggers kazu at cs dot umass dot edu
  2005-01-27 20:24 ` [Bug tree-optimization/19659] GCC does not " steven at gcc dot gnu dot org
  2005-01-27 20:34 ` pinskia at gcc dot gnu dot org
@ 2005-01-27 21:26 ` steven at gcc dot gnu dot org
  2005-02-17 14:33 ` pinskia at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: steven at gcc dot gnu dot org @ 2005-01-27 21:26 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From steven at gcc dot gnu dot org  2005-01-27 21:26 -------
The lang hook thinks that with the 'const' the types of 'dest' and 'orig' 
in may_propagate_copy are not the same. 
 
(gdb) 
2820          else if (!may_propagate_copy (op, val)) 
4: debug_generic_stmt (stmt) = #   VUSE <TMT.0D.1464_10>; 
D.1457_8 = *lengthp2D.1453_7; 
 
void 
(gdb) p may_propagate_copy (op, val) 
$17 = 0 '\0' 
 
In may_propagate_copy : 
(gdb) next 
111           if (mt_dest && mt_orig && mt_dest != mt_orig) 
(gdb) 
113           else if (!lang_hooks.types_compatible_p (type_d, type_o)) 
(gdb) 
156     } 
(gdb) p debug_generic_expr(dest) 
lengthp2D.1453_7 
$18 = void 
(gdb) p debug_generic_expr(orig) 
lengthpD.1449_3 
(gdb) p lang_hooks.types_compatible_p (type_d, type_o) 
$20 = 0 
(gdb) p debug_tree (type_d) 
 <pointer_type 0x2a95a301a0 
    type <integer_type 0x2a95a300d0 unsigned int readonly unsigned SI 
        size <integer_cst 0x2a95890a80 constant invariant 32> 
        unit size <integer_cst 0x2a958905a0 constant invariant 4> 
        align 32 symtab 0 alias set -1 precision 32 min <integer_cst 
0x2a95890b70 0> max <integer_cst 0x2a95890b40 4294967295> 
        pointer_to_this <pointer_type 0x2a95a301a0>> 
    unsigned DI 
    size <integer_cst 0x2a95890c30 type <integer_type 0x2a958965b0 
bit_size_type> constant invariant 64> 
    unit size <integer_cst 0x2a95890c60 type <integer_type 0x2a958964e0 long 
unsigned int> constant invariant 8> 
    align 64 symtab 0 alias set -1> 
$21 = void 
(gdb) p debug_tree (type_o) 
 <pointer_type 0x2a95988a90 
    type <integer_type 0x2a95896b60 unsigned int public unsigned SI 
        size <integer_cst 0x2a95890a80 constant invariant 32> 
        unit size <integer_cst 0x2a958905a0 constant invariant 4> 
        align 32 symtab 0 alias set -1 precision 32 min <integer_cst 
0x2a95890b70 0> max <integer_cst 0x2a95890b40 4294967295> 
        pointer_to_this <pointer_type 0x2a95988a90>> 
    unsigned DI 
    size <integer_cst 0x2a95890c30 type <integer_type 0x2a958965b0 
bit_size_type> constant invariant 64> 
    unit size <integer_cst 0x2a95890c60 type <integer_type 0x2a958964e0 long 
unsigned int> constant invariant 8> 
    align 64 symtab 0 alias set -1> 
$22 = void 
 
 
 

-- 


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


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

* [Bug tree-optimization/19659] GCC does not remove an "if" statement that never triggers.
  2005-01-27 19:59 [Bug tree-optimization/19659] New: GCC does remove an "if" statement that never triggers kazu at cs dot umass dot edu
                   ` (2 preceding siblings ...)
  2005-01-27 21:26 ` steven at gcc dot gnu dot org
@ 2005-02-17 14:33 ` pinskia at gcc dot gnu dot org
  2005-02-19  4:02 ` dnovillo at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-02-17 14:33 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-02-17 04:12 -------
This is not fully related to PR 18178 but this case is just a missed optimization dealing with const int * 
vs int*.

Another testcase for the const* vs * is:
void link_error(void);
void f(void)
{
  int a[1];
  a[0] = 1;
  const int *b = a;
  if (*b != 1)
    link_error();
}

If we look at the last tree dump we see there is a link_error in it.

-- 


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


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

* [Bug tree-optimization/19659] GCC does not remove an "if" statement that never triggers.
  2005-01-27 19:59 [Bug tree-optimization/19659] New: GCC does remove an "if" statement that never triggers kazu at cs dot umass dot edu
                   ` (3 preceding siblings ...)
  2005-02-17 14:33 ` pinskia at gcc dot gnu dot org
@ 2005-02-19  4:02 ` dnovillo at gcc dot gnu dot org
  2005-02-19  5:45 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: dnovillo at gcc dot gnu dot org @ 2005-02-19  4:02 UTC (permalink / raw)
  To: gcc-bugs



-- 
Bug 19659 depends on bug 18178, which changed state.

Bug 18178 Summary: Missed opportunity for removing bounds checking
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18178

           What    |Old Value                   |New Value
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED

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


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

* [Bug tree-optimization/19659] GCC does not remove an "if" statement that never triggers.
  2005-01-27 19:59 [Bug tree-optimization/19659] New: GCC does remove an "if" statement that never triggers kazu at cs dot umass dot edu
                   ` (4 preceding siblings ...)
  2005-02-19  4:02 ` dnovillo at gcc dot gnu dot org
@ 2005-02-19  5:45 ` pinskia at gcc dot gnu dot org
  2005-03-16 12:32 ` steven at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-02-19  5:45 UTC (permalink / raw)
  To: gcc-bugs



-- 
Bug 19659 depends on bug 18178, which changed state.

Bug 18178 Summary: Missed opportunity for removing bounds checking
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18178

           What    |Old Value                   |New Value
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |

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


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

* [Bug tree-optimization/19659] GCC does not remove an "if" statement that never triggers.
  2005-01-27 19:59 [Bug tree-optimization/19659] New: GCC does remove an "if" statement that never triggers kazu at cs dot umass dot edu
                   ` (5 preceding siblings ...)
  2005-02-19  5:45 ` pinskia at gcc dot gnu dot org
@ 2005-03-16 12:32 ` steven at gcc dot gnu dot org
  2005-03-23 19:59 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: steven at gcc dot gnu dot org @ 2005-03-16 12:32 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From steven at gcc dot gnu dot org  2005-03-16 12:32 -------
Diego, this happens *a lot* in GCC itself.  All suggestions
on how we can fix this problem are welcome... ;-)

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dnovillo at gcc dot gnu dot
                   |                            |org


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


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

* [Bug tree-optimization/19659] GCC does not remove an "if" statement that never triggers.
  2005-01-27 19:59 [Bug tree-optimization/19659] New: GCC does remove an "if" statement that never triggers kazu at cs dot umass dot edu
                   ` (6 preceding siblings ...)
  2005-03-16 12:32 ` steven at gcc dot gnu dot org
@ 2005-03-23 19:59 ` pinskia at gcc dot gnu dot org
  2005-04-13 18:11 ` pinskia at gcc dot gnu dot org
  2005-06-04 17:00 ` dnovillo at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-03-23 19:59 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-03-23 19:59 -------
Hmm, the example in comment #3 is fixed on the mainline but the orginal one is just as bad when 
removing const now.

-- 


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


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

* [Bug tree-optimization/19659] GCC does not remove an "if" statement that never triggers.
  2005-01-27 19:59 [Bug tree-optimization/19659] New: GCC does remove an "if" statement that never triggers kazu at cs dot umass dot edu
                   ` (7 preceding siblings ...)
  2005-03-23 19:59 ` pinskia at gcc dot gnu dot org
@ 2005-04-13 18:11 ` pinskia at gcc dot gnu dot org
  2005-06-04 17:00 ` dnovillo at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-04-13 18:11 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-04-13 18:10 -------
Fixed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.1.0


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


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

* [Bug tree-optimization/19659] GCC does not remove an "if" statement that never triggers.
  2005-01-27 19:59 [Bug tree-optimization/19659] New: GCC does remove an "if" statement that never triggers kazu at cs dot umass dot edu
                   ` (8 preceding siblings ...)
  2005-04-13 18:11 ` pinskia at gcc dot gnu dot org
@ 2005-06-04 17:00 ` dnovillo at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: dnovillo at gcc dot gnu dot org @ 2005-06-04 17:00 UTC (permalink / raw)
  To: gcc-bugs



-- 
Bug 19659 depends on bug 18178, which changed state.

Bug 18178 Summary: Missed opportunity for removing bounds checking
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18178

           What    |Old Value                   |New Value
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE

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


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

end of thread, other threads:[~2005-06-04 17:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-27 19:59 [Bug tree-optimization/19659] New: GCC does remove an "if" statement that never triggers kazu at cs dot umass dot edu
2005-01-27 20:24 ` [Bug tree-optimization/19659] GCC does not " steven at gcc dot gnu dot org
2005-01-27 20:34 ` pinskia at gcc dot gnu dot org
2005-01-27 21:26 ` steven at gcc dot gnu dot org
2005-02-17 14:33 ` pinskia at gcc dot gnu dot org
2005-02-19  4:02 ` dnovillo at gcc dot gnu dot org
2005-02-19  5:45 ` pinskia at gcc dot gnu dot org
2005-03-16 12:32 ` steven at gcc dot gnu dot org
2005-03-23 19:59 ` pinskia at gcc dot gnu dot org
2005-04-13 18:11 ` pinskia at gcc dot gnu dot org
2005-06-04 17:00 ` dnovillo 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).