public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug optimization/13869] New: wrong code
@ 2004-01-26 20:35 stefaandr at hotmail dot com
  2004-01-26 20:49 ` [Bug optimization/13869] [tree-ssa] wrong code with a simple loop pinskia at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: stefaandr at hotmail dot com @ 2004-01-26 20:35 UTC (permalink / raw)
  To: gcc-bugs

Compiling this:
int test() {
        bool my_bool = true;
        for (int i=0; i<10; ++i) {
                if (!my_bool) {
                } else {
                        my_bool = false;
                }
        };
        return my_bool;
};

with optimization enabled, returns 1, though it returns 0 when compiled without
optimization.  Function calls in the else-scope are executed though...

Reading specs from
/esat/firenze/install/lib/gcc/i686-pc-linux-gnu/3.5-tree-ssa/specs
Configured with: ../../src/gcc/ssa/configure --prefix=/esat/firenze/install
--program-suffix=-ssa --enable-languages=c,c++
Thread model: posix
gcc version 3.5-tree-ssa 20040126 (merged 20040102)
 /esat/firenze/install/libexec/gcc/i686-pc-linux-gnu/3.5-tree-ssa/cc1plus -quiet
-v -D_GNU_SOURCE test.cpp -quiet -dumpbase test.cpp -mtune=pentiumpro
-auxbase-strip test.s -O9 -version -o test.s
ignoring nonexistent directory
"/esat/firenze/install/lib/gcc/i686-pc-linux-gnu/3.5-tree-ssa/../../../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /esat/firenze/install/lib/gcc/i686-pc-linux-gnu/3.5-tree-ssa/../../../../include/c++/3.5-tree-ssa
 /esat/firenze/install/lib/gcc/i686-pc-linux-gnu/3.5-tree-ssa/../../../../include/c++/3.5-tree-ssa/i686-pc-linux-gnu
 /esat/firenze/install/lib/gcc/i686-pc-linux-gnu/3.5-tree-ssa/../../../../include/c++/3.5-tree-ssa/backward
 /usr/local/include
 /esat/firenze/install/include
 /esat/firenze/install/lib/gcc/i686-pc-linux-gnu/3.5-tree-ssa/include
 /usr/include
End of search list.
GNU C++ version 3.5-tree-ssa 20040126 (merged 20040102) (i686-pc-linux-gnu)
        compiled by GNU C version 3.3.1.
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096

-- 
           Summary: wrong code
           Product: gcc
           Version: tree-ssa
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: stefaandr at hotmail dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


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

* [Bug optimization/13869] [tree-ssa] wrong code with a simple loop
  2004-01-26 20:35 [Bug optimization/13869] New: wrong code stefaandr at hotmail dot com
@ 2004-01-26 20:49 ` pinskia at gcc dot gnu dot org
  2004-01-28 21:21 ` steven at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-01-26 20:49 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-01-26 20:49 -------
Confirmed, some thing is going funny in the unssa phase.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |critical
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |wrong-code
      Known to fail|                            |tree-ssa
   Last reconfirmed|0000-00-00 00:00:00         |2004-01-26 20:49:26
               date|                            |
            Summary|wrong code                  |[tree-ssa] wrong code with a
                   |                            |simple loop
   Target Milestone|---                         |tree-ssa


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


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

* [Bug optimization/13869] [tree-ssa] wrong code with a simple loop
  2004-01-26 20:35 [Bug optimization/13869] New: wrong code stefaandr at hotmail dot com
  2004-01-26 20:49 ` [Bug optimization/13869] [tree-ssa] wrong code with a simple loop pinskia at gcc dot gnu dot org
@ 2004-01-28 21:21 ` steven at gcc dot gnu dot org
  2004-02-04  3:22 ` rth at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: steven at gcc dot gnu dot org @ 2004-01-28 21:21 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From steven at gcc dot gnu dot org  2004-01-28 21:21 -------
With optimization we also return 0 AFAICT. 
Something looks strange in DOM1, but the results look OK. 
 
After DCE1 we have the following tree: 
 
main () 
{ 
  int i; 
  int my_bool; 
 
  # BLOCK 0 
  # PRED: ENTRY (fallthru) 
  my_bool_4 = 1; 
  i_5 = 0; 
  goto <bb 4> (<L3>); 
  # SUCC: 4 (fallthru) 
 
  # BLOCK 1 
  # PRED: 4 (true) 
<L0>:; 
  if (my_bool_2 == 0) goto <L2>; else goto <L1>; 
  # SUCC: 2 (false) 3 (true) 
 
  # BLOCK 2 
  # PRED: 1 (false) 
<L1>:; 
  my_bool_8 = 0; 
  # SUCC: 3 (fallthru) 
 
  # BLOCK 3 
  # PRED: 2 (fallthru) 1 (true) 
  # my_bool_1 = PHI <my_bool_2(1), my_bool_8(2)>; 
<L2>:; 
  i_7 = i_3 + 1; 
  # SUCC: 4 (fallthru) 
 
  # BLOCK 4 
  # PRED: 3 (fallthru) 0 (fallthru) 
  # i_3 = PHI <i_5(0), i_7(3)>; 
  # my_bool_2 = PHI <my_bool_4(0), my_bool_1(3)>; 
<L3>:; 
  if (i_3 <= 9) goto <L0>; else goto <L4>; 
  # SUCC: 5 (false) 1 (true) 
 
  # BLOCK 5 
  # PRED: 4 (false) 
<L4>:; 
  return my_bool_2; 
  # SUCC: EXIT 
 
} 
 
 
Then we go do jump threading in DOM1, and we start with: 
  Threaded jump 0 --> 4 to 1 
 
I.e. we bypass the PHI my_bool_2, then note that my_bool must 
be 0, and finally we make the function return 0, effectively 
making all other statements dead: 
 
main () 
{ 
  int i; 
  int my_bool; 
 
  # BLOCK 0 
  # PRED: ENTRY (fallthru) 
  my_bool_1 = 1; 
  i_16 = 0; 
  my_bool_17 = 1; 
  i_18 = 0; 
  my_bool_19 = 1; 
  i_20 = 0; 
  # SUCC: 1 (fallthru) 
 
  # BLOCK 1 
  # PRED: 0 (fallthru) 
<L1>:; 
  my_bool_21 = 0; 
  my_bool_22 = 0; 
  my_bool_23 = 0; 
  # SUCC: 2 (fallthru) 
 
  # BLOCK 2 
  # PRED: 2 (true) 1 (fallthru) 
  # i_2 = PHI <0(1), i_24(2)>; 
<L2>:; 
  i_24 = i_2 + 1; 
  if (i_24 <= 9) goto <L2>; else goto <L4>; 
  # SUCC: 3 (false) 2 (true) 
 
  # BLOCK 3 
  # PRED: 2 (false) 
<L4>:; 
  return 0; 
  # SUCC: EXIT 
 
} 
 
After DCE2, not a whole lot remains of the original function: 
 
main () 
{ 
  int i; 
  int my_bool; 
 
  # BLOCK 0 
  # PRED: ENTRY (fallthru) 
  # SUCC: 1 (fallthru) 
 
  # BLOCK 1 
  # PRED: 0 (fallthru) 1 (true) 
  # i_2 = PHI <0(0), i_24(1)>; 
<L2>:; 
  i_24 = i_2 + 1; 
  if (i_24 <= 9) goto <L2>; else goto <L4>; 
  # SUCC: 2 (false) 1 (true) 
 
  # BLOCK 2 
  # PRED: 1 (false) 
<L4>:; 
  return 0; 
  # SUCC: EXIT 
} 
 
So returns 0 with optimization enabled. 
 
Perhaps Jeff can look into all those dead assignments??? 
 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |law at gcc dot gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED


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


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

* [Bug optimization/13869] [tree-ssa] wrong code with a simple loop
  2004-01-26 20:35 [Bug optimization/13869] New: wrong code stefaandr at hotmail dot com
  2004-01-26 20:49 ` [Bug optimization/13869] [tree-ssa] wrong code with a simple loop pinskia at gcc dot gnu dot org
  2004-01-28 21:21 ` steven at gcc dot gnu dot org
@ 2004-02-04  3:22 ` rth at gcc dot gnu dot org
  2004-02-04  6:08 ` cvs-commit at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rth at gcc dot gnu dot org @ 2004-02-04  3:22 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From rth at gcc dot gnu dot org  2004-02-04 03:21 -------
It's cfg_remove_useless_stmts_bb, not dom at all.  Working on a patch.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|law at gcc dot gnu dot org  |rth at gcc dot gnu dot org


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


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

* [Bug optimization/13869] [tree-ssa] wrong code with a simple loop
  2004-01-26 20:35 [Bug optimization/13869] New: wrong code stefaandr at hotmail dot com
                   ` (2 preceding siblings ...)
  2004-02-04  3:22 ` rth at gcc dot gnu dot org
@ 2004-02-04  6:08 ` cvs-commit at gcc dot gnu dot org
  2004-02-04  6:17 ` rth at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-02-04  6:08 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2004-02-04 06:08 -------
Subject: Bug 13869

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	tree-ssa-20020619-branch
Changes by:	rth@gcc.gnu.org	2004-02-04 06:08:21

Modified files:
	gcc            : ChangeLog.tree-ssa tree-cfg.c 
Added files:
	gcc/testsuite/g++.dg/opt: bool1.C 

Log message:
	PR opt/13869
	* tree-cfg.c (cfg_remove_useless_stmts_bb): Correct handling of
	boolean variables in COND_EXPR_COND.
	* g++.dg/opt/bool1.C: New.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.tree-ssa.diff?cvsroot=gcc&only_with_tag=tree-ssa-20020619-branch&r1=1.1.2.1147&r2=1.1.2.1148
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-cfg.c.diff?cvsroot=gcc&only_with_tag=tree-ssa-20020619-branch&r1=1.1.4.263&r2=1.1.4.264
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/opt/bool1.C.diff?cvsroot=gcc&only_with_tag=tree-ssa-20020619-branch&r1=NONE&r2=1.1.2.1



-- 


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


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

* [Bug optimization/13869] [tree-ssa] wrong code with a simple loop
  2004-01-26 20:35 [Bug optimization/13869] New: wrong code stefaandr at hotmail dot com
                   ` (3 preceding siblings ...)
  2004-02-04  6:08 ` cvs-commit at gcc dot gnu dot org
@ 2004-02-04  6:17 ` rth at gcc dot gnu dot org
  2004-02-09 20:50 ` law at redhat dot com
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rth at gcc dot gnu dot org @ 2004-02-04  6:17 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From rth at gcc dot gnu dot org  2004-02-04 06:17 -------
http://gcc.gnu.org/ml/gcc-patches/2004-02/msg00279.html

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


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


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

* [Bug optimization/13869] [tree-ssa] wrong code with a simple loop
  2004-01-26 20:35 [Bug optimization/13869] New: wrong code stefaandr at hotmail dot com
                   ` (4 preceding siblings ...)
  2004-02-04  6:17 ` rth at gcc dot gnu dot org
@ 2004-02-09 20:50 ` law at redhat dot com
  2004-02-09 21:19 ` rth at redhat dot com
  2004-02-11 21:32 ` law at redhat dot com
  7 siblings, 0 replies; 9+ messages in thread
From: law at redhat dot com @ 2004-02-09 20:50 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From law at redhat dot com  2004-02-09 20:50 -------
Subject: Re:  [tree-ssa] wrong code with a simple loop 

In message <20040128212153.4623.qmail@sources.redhat.com>, "steven at gcc dot g
nu dot org" writes:
 >After DCE2, not a whole lot remains of the original function: 
 > 
 >main () 
 >{ 
 >  int i; 
 >  int my_bool; 
 > 
 >  # BLOCK 0 
 >  # PRED: ENTRY (fallthru) 
 >  # SUCC: 1 (fallthru) 
 > 
 >  # BLOCK 1 
 >  # PRED: 0 (fallthru) 1 (true) 
 >  # i_2 = PHI <0(0), i_24(1)>; 
 ><L2>:; 
 >  i_24 = i_2 + 1; 
 >  if (i_24 <= 9) goto <L2>; else goto <L4>; 
 >  # SUCC: 2 (false) 1 (true) 
 > 
 >  # BLOCK 2 
 >  # PRED: 1 (false) 
 ><L4>:; 
 >  return 0; 
 >  # SUCC: EXIT 
 >} 
 > 
 >So returns 0 with optimization enabled. 
 > 
 >Perhaps Jeff can look into all those dead assignments??? 
I'm not sure what you want me to do.  The dead assignments in the dom
dumps are normal as dom does not try to eliminate dead code.  That is
the job of DCE.  In fact, DOM can create dead code when jumps are
threaded (as an artifact of the out-of-ssa translation we must do).


Jeff



-- 


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


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

* [Bug optimization/13869] [tree-ssa] wrong code with a simple loop
  2004-01-26 20:35 [Bug optimization/13869] New: wrong code stefaandr at hotmail dot com
                   ` (5 preceding siblings ...)
  2004-02-09 20:50 ` law at redhat dot com
@ 2004-02-09 21:19 ` rth at redhat dot com
  2004-02-11 21:32 ` law at redhat dot com
  7 siblings, 0 replies; 9+ messages in thread
From: rth at redhat dot com @ 2004-02-09 21:19 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From rth at redhat dot com  2004-02-09 21:19 -------
Subject: Re:  [tree-ssa] wrong code with a simple loop

On Mon, Feb 09, 2004 at 08:50:40PM -0000, law at redhat dot com wrote:
> I'm not sure what you want me to do.

Nothing.  The original analysis was flawed -- hindered by the fact
that, at the time, we did not print non-memory-tag PHI nodes unless
you gave the -vops dump option.

The real problem had nothing to do with DOM at all, and I fixed it.


r~


-- 


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


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

* [Bug optimization/13869] [tree-ssa] wrong code with a simple loop
  2004-01-26 20:35 [Bug optimization/13869] New: wrong code stefaandr at hotmail dot com
                   ` (6 preceding siblings ...)
  2004-02-09 21:19 ` rth at redhat dot com
@ 2004-02-11 21:32 ` law at redhat dot com
  7 siblings, 0 replies; 9+ messages in thread
From: law at redhat dot com @ 2004-02-11 21:32 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From law at redhat dot com  2004-02-11 21:32 -------
Subject: Re:  [tree-ssa] wrong code with a simple loop 

In message <20040128212153.4623.qmail@sources.redhat.com>, "steven at gcc dot g
nu dot org" writes:
 >
 >------- Additional Comments From steven at gcc dot gnu dot org  2004-01-28 21
 >:21 -------
 >With optimization we also return 0 AFAICT. 
 >Something looks strange in DOM1, but the results look OK. 
 > 
 >After DCE1 we have the following tree: 
[ ... ]
BTW, with my changes from this afternoon, cc1plus will compile this code
down to a simple "return 0".

jeff



-- 


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


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

end of thread, other threads:[~2004-02-11 21:32 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-26 20:35 [Bug optimization/13869] New: wrong code stefaandr at hotmail dot com
2004-01-26 20:49 ` [Bug optimization/13869] [tree-ssa] wrong code with a simple loop pinskia at gcc dot gnu dot org
2004-01-28 21:21 ` steven at gcc dot gnu dot org
2004-02-04  3:22 ` rth at gcc dot gnu dot org
2004-02-04  6:08 ` cvs-commit at gcc dot gnu dot org
2004-02-04  6:17 ` rth at gcc dot gnu dot org
2004-02-09 20:50 ` law at redhat dot com
2004-02-09 21:19 ` rth at redhat dot com
2004-02-11 21:32 ` law at redhat dot com

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