public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/19283] New: Bad code generated in final_cleanup
@ 2005-01-05 23:49 gcc-bugzilla at gcc dot gnu dot org
  2005-01-06  0:27 ` [Bug tree-optimization/19283] [4.0 Regression] " belyshev at depni dot sinp dot msu dot ru
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: gcc-bugzilla at gcc dot gnu dot org @ 2005-01-05 23:49 UTC (permalink / raw)
  To: gcc-bugs



g++ generates bad code for the program below if -O3 is used.
If optimization is off, it works correctly.



$ g++ -o x x.cc
$ ./x
$ g++ -o x x.cc -O3
$ ./x
fail
$

Here is the generated code for main() (with exception-handling labels elided):

main:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$8, %esp
	andl	$-16, %esp
	subl	$16, %esp
	movl	$.LC0, (%esp)
	call	puts
	xorl	%eax, %eax
	leave
	ret

The test has been erroneously optimized out.

Here's main() from x.cc.t66.blocks:

int main() ()
{
<bb 0>:
  if ((short int) (short unsigned int) (int) (short unsigned int) rawdata < 0) goto <L1>; else goto <L2>;

<L1>:;
  printf (&"fail\n"[0]);

<L2>:;
  return 0;

}


This looks ok.
And here it is from x.cc.t67.final_cleanup:

;; Function int main() (main)

Merging blocks 0 and 1
Merging blocks 0 and 2
int main() ()
{
<bb 0>:
  printf (&"fail\n"[0]);
  return 0;

}

Where the test is gone.
So the problem is in this step.

This looks like it may be related to the previous bug
tree-optimization/18576.  However, that one is classified
as missed-optimization, while this is wrong code.

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 the following with -O3:

-------------------------------------------------------------------
extern "C" int printf (const char*, ...);


unsigned short int foo(unsigned int* ptr) {
  return *ptr;
};

unsigned rawdata = 0;

int main ()
{
  if ((foo(&rawdata) & 0x8000) != 0)
    printf ("fail\n");
  return 0;
}

-------------------------------------------------------------------
------- Additional Comments From snyder at fnal dot gov  2005-01-05 23:49 -------
Fix:
	<how to correct or work around the problem, if known (multiple lines)>

-- 
           Summary: Bad code generated in final_cleanup
           Product: gcc
           Version: 4.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=19283


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

* [Bug tree-optimization/19283] [4.0 Regression] Bad code generated in final_cleanup
  2005-01-05 23:49 [Bug tree-optimization/19283] New: Bad code generated in final_cleanup gcc-bugzilla at gcc dot gnu dot org
@ 2005-01-06  0:27 ` belyshev at depni dot sinp dot msu dot ru
  2005-01-06  0:28 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: belyshev at depni dot sinp dot msu dot ru @ 2005-01-06  0:27 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From belyshev at depni dot sinp dot msu dot ru  2005-01-06 00:27 -------
// C testcase, use '-O2' or '-O1 -funit-at-a-time' to reproduce:

void abort (void);

static unsigned short foo (unsigned int* p)
{
  return *p;
};

unsigned int u;

int main ()
{
  if ((foo (&u) & 0x8000) != 0)
    abort ();
  return 0;
}


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |critical
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
  GCC build triplet|i686-pc-linux-gnu           |
   GCC host triplet|i686-pc-linux-gnu           |
 GCC target triplet|i686-pc-linux-gnu           |
           Keywords|                            |wrong-code
      Known to fail|                            |4.0.0
      Known to work|                            |3.4.4
           Priority|P3                          |P1
   Last reconfirmed|0000-00-00 00:00:00         |2005-01-06 00:27:06
               date|                            |
            Summary|Bad code generated in       |[4.0 Regression] Bad code
                   |final_cleanup               |generated in final_cleanup
   Target Milestone|---                         |4.0.0


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


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

* [Bug tree-optimization/19283] [4.0 Regression] Bad code generated in final_cleanup
  2005-01-05 23:49 [Bug tree-optimization/19283] New: Bad code generated in final_cleanup gcc-bugzilla at gcc dot gnu dot org
  2005-01-06  0:27 ` [Bug tree-optimization/19283] [4.0 Regression] " belyshev at depni dot sinp dot msu dot ru
@ 2005-01-06  0:28 ` pinskia at gcc dot gnu dot org
  2005-01-06 15:52 ` jakub at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-01-06  0:28 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-01-06 00:28 -------
Hmm, this is fold f'ing up again.
Here is an example for -O1:
void abort (void);
static inline unsigned short foo (unsigned int* p)
{
  return *p;
};
unsigned int u;
int main ()
{
  if ((foo (&u) & 0x8000) != 0)
    abort ();
  return 0;
}


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


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


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

* [Bug tree-optimization/19283] [4.0 Regression] Bad code generated in final_cleanup
  2005-01-05 23:49 [Bug tree-optimization/19283] New: Bad code generated in final_cleanup gcc-bugzilla at gcc dot gnu dot org
  2005-01-06  0:27 ` [Bug tree-optimization/19283] [4.0 Regression] " belyshev at depni dot sinp dot msu dot ru
  2005-01-06  0:28 ` pinskia at gcc dot gnu dot org
@ 2005-01-06 15:52 ` jakub at gcc dot gnu dot org
  2005-01-06 16:56 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu dot org @ 2005-01-06 15:52 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jakub at gcc dot gnu dot org  2005-01-06 15:52 -------
Yeah, this is fold_widened_comparison "optimizing":
(short intD.7) (short unsigned intD.8) (intD.0) (short unsigned intD.8) uD.1124 <
0
into 1 (for unsigned int uD.1124).
get_unwidened returns (unsigned short) uD.1124 (note different sign; and that
seems to be what get_unwidened documents:
If we have not stripped any zero-extensions (uns is 0), we can strip any kind of
extension.).
But I guess fold_widened_comparison relies on shorter_type really being a shorter
type.  Will look into this further.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |jakub at gcc dot gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2005-01-06 00:27:06         |2005-01-06 15:52:31
               date|                            |


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


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

* [Bug tree-optimization/19283] [4.0 Regression] Bad code generated in final_cleanup
  2005-01-05 23:49 [Bug tree-optimization/19283] New: Bad code generated in final_cleanup gcc-bugzilla at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2005-01-06 15:52 ` jakub at gcc dot gnu dot org
@ 2005-01-06 16:56 ` pinskia at gcc dot gnu dot org
  2005-01-07  9:08 ` cvs-commit at gcc dot gnu dot org
  2005-01-07 13:49 ` pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-01-06 16:56 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-01-06 16:56 -------
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2005-01/msg00344.html>..

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


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


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

* [Bug tree-optimization/19283] [4.0 Regression] Bad code generated in final_cleanup
  2005-01-05 23:49 [Bug tree-optimization/19283] New: Bad code generated in final_cleanup gcc-bugzilla at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2005-01-06 16:56 ` pinskia at gcc dot gnu dot org
@ 2005-01-07  9:08 ` cvs-commit at gcc dot gnu dot org
  2005-01-07 13:49 ` pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-01-07  9:08 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2005-01-07 09:08 -------
Subject: Bug 19283

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	jakub@gcc.gnu.org	2005-01-07 09:08:11

Modified files:
	gcc            : ChangeLog fold-const.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.c-torture/execute: 20050106-1.c 

Log message:
	PR tree-optimization/19283
	* fold-const.c (fold_widened_comparison): Return NULL if shorter_type
	is not shorter than the original type.
	
	* gcc.c-torture/execute/20050106-1.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.7057&r2=2.7058
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fold-const.c.diff?cvsroot=gcc&r1=1.490&r2=1.491
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4862&r2=1.4863
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/20050106-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1



-- 


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


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

* [Bug tree-optimization/19283] [4.0 Regression] Bad code generated in final_cleanup
  2005-01-05 23:49 [Bug tree-optimization/19283] New: Bad code generated in final_cleanup gcc-bugzilla at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2005-01-07  9:08 ` cvs-commit at gcc dot gnu dot org
@ 2005-01-07 13:49 ` pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-01-07 13:49 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-01-07 13:49 -------
Fixed thanks Jakub.

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


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


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

end of thread, other threads:[~2005-01-07 13:49 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-05 23:49 [Bug tree-optimization/19283] New: Bad code generated in final_cleanup gcc-bugzilla at gcc dot gnu dot org
2005-01-06  0:27 ` [Bug tree-optimization/19283] [4.0 Regression] " belyshev at depni dot sinp dot msu dot ru
2005-01-06  0:28 ` pinskia at gcc dot gnu dot org
2005-01-06 15:52 ` jakub at gcc dot gnu dot org
2005-01-06 16:56 ` pinskia at gcc dot gnu dot org
2005-01-07  9:08 ` cvs-commit at gcc dot gnu dot org
2005-01-07 13:49 ` pinskia 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).