public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/18298] New: 4.0: bad code from lim ssa pass with strcmp
@ 2004-11-04 15:59 gcc-bugzilla at gcc dot gnu dot org
  2004-11-04 16:06 ` [Bug tree-optimization/18298] [4.0 Regression] " pinskia at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: gcc-bugzilla at gcc dot gnu dot org @ 2004-11-04 15:59 UTC (permalink / raw)
  To: gcc-bugs



When i build the example below with -O1 or above, it goes into an infinite
loop:

$ g++ -o x -O1 x.cc
$ ./x
... doesn't exit 

At -O0, it exits as expected:


$ g++ -o x -O0 x.cc
$ ./x
$


Here's the code that's generated (eh-related labels removed for clarity).
As you can see, there's an obvious infinite loop...


main:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$8, %esp
	andl	$-16, %esp
	subl	$16, %esp
	movzbl	s, %eax
	testb	%al, %al
	je	.L2
.L5:
	jmp	.L5     ; <-- infinite loop!
.L2:
	movb	%al, s
	movl	$0, %eax
	leave
	ret


The problem seems to be introduced in the `lim' ssa pass, where this
(from t44.loopinit):

int main() ()
{
  const unsigned char * prephitmp.3;
  const unsigned char * pretmp.2;
  const unsigned char * D.1593;
  const unsigned char D.1594;
  int D.1595;
  int D.1590;
  int D.1589;
  const char * str;
  int D.1578;
  bool D.1575;
  bool retval.0;
  int D.1588;

<bb 0>:
  pretmp.2_13 = (const unsigned char *) &s[0];
  goto <bb 2> (<L1>);

<L0>:;
  s[0] = 0;

  # prephitmp.3_14 = PHI <pretmp.2_13(0), D.1593_6(1)>;
<L1>:;
  D.1593_6 = pretmp.2_13;
  D.1594_3 = *D.1593_6;
  D.1595_12 = (int) D.1594_3;
  D.1590_4 = D.1595_12;
  if (D.1590_4 != 0) goto <L0>; else goto <L3>;

<L3>:;
  return 0;

}



gets transformed to this (from t45.lim):


int main() ()
{
  char lsm_tmp.4;
  const unsigned char * prephitmp.3;
  const unsigned char * pretmp.2;
  const unsigned char * D.1593;
  const unsigned char D.1594;
  int D.1595;
  int D.1590;
  int D.1589;
  const char * str;
  int D.1578;
  bool D.1575;
  bool retval.0;
  int D.1588;

<bb 0>:
  pretmp.2_13 = (const unsigned char *) &s[0];
  D.1593_6 = pretmp.2_13;
  D.1594_3 = *D.1593_6;
  D.1595_12 = (int) D.1594_3;
  D.1590_4 = D.1595_12;
  lsm_tmp.4_15 = s[0];
  goto <bb 2> (<L1>);

<L0>:;
  lsm_tmp.4_17 = 0;

  # lsm_tmp.4_18 = PHI <lsm_tmp.4_15(0), lsm_tmp.4_17(1)>;
  # prephitmp.3_14 = PHI <pretmp.2_13(0), D.1593_6(1)>;
<L1>:;
  if (D.1590_4 != 0) goto <L0>; else goto <L3>;

  # lsm_tmp.4_19 = PHI <lsm_tmp.4_18(2)>;
<L3>:;
  s[0] = lsm_tmp.4_19;
  return 0;

}


Note that the variable being tested at L1 (D.1590_4) never changes.


This feels like it may be related to bugs 17133/17425, but the patch
for that doesn't fix this.

Environment:
System: Linux karma 2.6.8.1 #20 Mon Sep 13 23:48:47 EDT 2004 i686 i686 i386 GNU/Linux
Architecture: i686

	<machine, os, target, libraries (multiple lines)>
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: /home/sss/gcc/gcc/configure --prefix=/usr/local/gcc --enable-threads=posix --enable-long-long --enable-languages=c,c++,f95

How-To-Repeat:

Compile and run with -O1 or above.
-------------------------------------------
extern "C" int strcmp (const char*, const char*);

char s[2048] = "a";

inline bool foo(const char *str) {
  return !strcmp(s,str);
}


int main() {
  while(!(foo(""))) {
    s[0] = '\0';
  }
  return 0;
}
-------------------------------------------
------- Additional Comments From snyder at fnal dot gov  2004-11-04 15:59 -------
Fix:
	<how to correct or work around the problem, if known (multiple lines)>

-- 
           Summary: 4.0: bad code from lim ssa pass with strcmp
           Product: gcc
           Version: 0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: snyder at fnal dot gov
                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=18298


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

* [Bug tree-optimization/18298] [4.0 Regression] bad code from lim ssa pass with strcmp
  2004-11-04 15:59 [Bug tree-optimization/18298] New: 4.0: bad code from lim ssa pass with strcmp gcc-bugzilla at gcc dot gnu dot org
@ 2004-11-04 16:06 ` pinskia at gcc dot gnu dot org
  2004-11-04 16:19 ` dberlin 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-11-04 16:06 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-11-04 16:06 -------
Confirmed, this is an aliasing problem:
  D.1589_6 = (const unsigned char *) &s[0];
  D.1590_3 = *D.1589_6;

There is no VUSE on the second statement.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |wrong-code
   Last reconfirmed|0000-00-00 00:00:00         |2004-11-04 16:06:10
               date|                            |
            Summary|4.0: bad code from lim ssa  |[4.0 Regression] bad code
                   |pass with strcmp            |from lim ssa pass with
                   |                            |strcmp
   Target Milestone|---                         |4.0.0
            Version|0.0                         |4.0.0


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


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

* [Bug tree-optimization/18298] [4.0 Regression] bad code from lim ssa pass with strcmp
  2004-11-04 15:59 [Bug tree-optimization/18298] New: 4.0: bad code from lim ssa pass with strcmp gcc-bugzilla at gcc dot gnu dot org
  2004-11-04 16:06 ` [Bug tree-optimization/18298] [4.0 Regression] " pinskia at gcc dot gnu dot org
@ 2004-11-04 16:19 ` dberlin at gcc dot gnu dot org
  2004-11-04 18:04 ` pinskia at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: dberlin at gcc dot gnu dot org @ 2004-11-04 16:19 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |dnovillo at redhat dot com
                   |dot org                     |
             Status|NEW                         |ASSIGNED


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


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

* [Bug tree-optimization/18298] [4.0 Regression] bad code from lim ssa pass with strcmp
  2004-11-04 15:59 [Bug tree-optimization/18298] New: 4.0: bad code from lim ssa pass with strcmp gcc-bugzilla at gcc dot gnu dot org
  2004-11-04 16:06 ` [Bug tree-optimization/18298] [4.0 Regression] " pinskia at gcc dot gnu dot org
  2004-11-04 16:19 ` dberlin at gcc dot gnu dot org
@ 2004-11-04 18:04 ` pinskia at gcc dot gnu dot org
  2004-11-04 20:25 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-11-04 18:04 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-11-04 18:04 -------
The problem is that fold all builtins is not creating the operands on the statement, if you write the code 
as fab would create it is right.  I am looking into fixing the problem right now.

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


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


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

* [Bug tree-optimization/18298] [4.0 Regression] bad code from lim ssa pass with strcmp
  2004-11-04 15:59 [Bug tree-optimization/18298] New: 4.0: bad code from lim ssa pass with strcmp gcc-bugzilla at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2004-11-04 18:04 ` pinskia at gcc dot gnu dot org
@ 2004-11-04 20:25 ` pinskia at gcc dot gnu dot org
  2004-11-29 23:01 ` dnovillo at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-11-04 20:25 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-11-04 20:25 -------
Adding a may_alias pass after fold all builtins makes this testcase works (I don't know if this is correct 
fix or not):
Index: tree-optimize.c
===============================================================
====
RCS file: /cvs/gcc/gcc/gcc/tree-optimize.c,v
retrieving revision 2.61
diff -u -p -r2.61 tree-optimize.c
--- tree-optimize.c	2 Nov 2004 00:23:04 -0000	2.61
+++ tree-optimize.c	4 Nov 2004 20:23:32 -0000
@@ -371,6 +371,7 @@ init_tree_optimization_passes (void)
   NEXT_PASS (pass_ccp);
   NEXT_PASS (pass_redundant_phi);
   NEXT_PASS (pass_fold_builtins);
+  NEXT_PASS (pass_may_alias);
   NEXT_PASS (pass_split_crit_edges);
   NEXT_PASS (pass_pre);
   NEXT_PASS (pass_loop);


-- 


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


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

* [Bug tree-optimization/18298] [4.0 Regression] bad code from lim ssa pass with strcmp
  2004-11-04 15:59 [Bug tree-optimization/18298] New: 4.0: bad code from lim ssa pass with strcmp gcc-bugzilla at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2004-11-04 20:25 ` pinskia at gcc dot gnu dot org
@ 2004-11-29 23:01 ` dnovillo at gcc dot gnu dot org
  2004-11-29 23:03 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: dnovillo at gcc dot gnu dot org @ 2004-11-29 23:01 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From dnovillo at gcc dot gnu dot org  2004-11-29 23:01 -------
(In reply to comment #4)
> Adding a may_alias pass after fold all builtins makes this testcase works
> (I don't know if this is correct fix or not):
>
Unfortunately, it is.  It's a bit heavy handed for my taste, but we have little
choice.  Folding builtins has the potential of introducing almost arbitrary
GIMPLE code.  We don't have much control over what it can be generated.

For 4.1, I would like to convert the may_alias pass into a TODO so that it can
be triggered by passes that knowingly introduce new aliasing.  For now, your
patch is fine (provided you test it again and add a testcase).  Please add a
FIXME comment, as well.


Diego.

-- 


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


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

* [Bug tree-optimization/18298] [4.0 Regression] bad code from lim ssa pass with strcmp
  2004-11-04 15:59 [Bug tree-optimization/18298] New: 4.0: bad code from lim ssa pass with strcmp gcc-bugzilla at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2004-11-29 23:01 ` dnovillo at gcc dot gnu dot org
@ 2004-11-29 23:03 ` pinskia at gcc dot gnu dot org
  2004-11-30 15:39 ` pinskia at gcc dot gnu dot org
  2004-11-30 15:40 ` cvs-commit at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-11-29 23:03 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-11-29 23:03 -------
Mine, as my patch fixes it.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|dnovillo at redhat dot com  |pinskia at gcc dot gnu dot
                   |                            |org


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


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

* [Bug tree-optimization/18298] [4.0 Regression] bad code from lim ssa pass with strcmp
  2004-11-04 15:59 [Bug tree-optimization/18298] New: 4.0: bad code from lim ssa pass with strcmp gcc-bugzilla at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2004-11-29 23:03 ` pinskia at gcc dot gnu dot org
@ 2004-11-30 15:39 ` pinskia at gcc dot gnu dot org
  2004-11-30 15:40 ` cvs-commit at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-11-30 15:39 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-11-30 15:38 -------
Fixed.

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


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


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

* [Bug tree-optimization/18298] [4.0 Regression] bad code from lim ssa pass with strcmp
  2004-11-04 15:59 [Bug tree-optimization/18298] New: 4.0: bad code from lim ssa pass with strcmp gcc-bugzilla at gcc dot gnu dot org
                   ` (6 preceding siblings ...)
  2004-11-30 15:39 ` pinskia at gcc dot gnu dot org
@ 2004-11-30 15:40 ` cvs-commit at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-11-30 15:40 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2004-11-30 15:39 -------
Subject: Bug 18298

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	pinskia@gcc.gnu.org	2004-11-30 15:38:45

Modified files:
	gcc            : ChangeLog tree-optimize.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.c-torture/execute: p18298.c 

Log message:
	2004-11-30  Andrew Pinski  <pinskia@physics.uc.edu>
	
	PR tree-opt/18298
	* tree-optimize.c (init_tree_optimization_passes): Add a may_alias
	pass right after fold builtins.
	2004-11-30  Andrew Pinski  <pinskia@physics.uc.edu>
	
	PR tree-opt/18298
	* gcc.c-torture/execute/p18298.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.6650&r2=2.6651
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-optimize.c.diff?cvsroot=gcc&r1=2.64&r2=2.65
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4689&r2=1.4690
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/p18298.c.diff?cvsroot=gcc&r1=NONE&r2=1.1



-- 


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


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

end of thread, other threads:[~2004-11-30 15:40 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-04 15:59 [Bug tree-optimization/18298] New: 4.0: bad code from lim ssa pass with strcmp gcc-bugzilla at gcc dot gnu dot org
2004-11-04 16:06 ` [Bug tree-optimization/18298] [4.0 Regression] " pinskia at gcc dot gnu dot org
2004-11-04 16:19 ` dberlin at gcc dot gnu dot org
2004-11-04 18:04 ` pinskia at gcc dot gnu dot org
2004-11-04 20:25 ` pinskia at gcc dot gnu dot org
2004-11-29 23:01 ` dnovillo at gcc dot gnu dot org
2004-11-29 23:03 ` pinskia at gcc dot gnu dot org
2004-11-30 15:39 ` pinskia at gcc dot gnu dot org
2004-11-30 15:40 ` cvs-commit 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).