public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/13566] New: bad code with -O3 -fno-strict-aliasing
@ 2004-01-05  3:26 gcc-bugzilla at gcc dot gnu dot org
  2004-01-05  4:14 ` [Bug optimization/13566] [3.4 Regression] " pinskia at gcc dot gnu dot org
  2004-01-10 16:30 ` hubicka at gcc dot gnu dot org
  0 siblings, 2 replies; 3+ messages in thread
From: gcc-bugzilla at gcc dot gnu dot org @ 2004-01-05  3:26 UTC (permalink / raw)
  To: gcc-bugs


I've run into a case where bad code is being generated on ia86 when
i use -O2 -fno-strict-aliasing.

The test case is below; i apologize that i haven't been able to reduce
it much further.  I expect that this program will print `2' when
executed, and it does in fact do so when compiled without
optimization, or without -fno-strict-aliasing:

$ g++ -o x x.cc
$ ./x
2
$ g++ -O2 -o x x.cc
$ ./x
2
$

However, when -O2 is combined with -fno-strict-aliasing, it prints `1':

$ g++ -O2 -fno-strict-aliasing -o x x.cc
$ ./x
1
$


Here is the generated code for the add_bool_list() function, when
compiled with -O2 -fno-strict-aliasing:


-------------------------------------
.globl _Z13add_bool_listv
	.type	_Z13add_bool_listv, @function
_Z13add_bool_listv:
.LFB26:
.L6:
.L18:
.L23:
.L26:
	pushl	%ebp
.LCFI0:
	xorl	%eax, %eax
	movl	%esp, %ebp
.LCFI1:
	subl	$200, %esp
.LCFI2:
	movl	%eax, -188(%ebp)
	xorl	%eax, %eax
	xorl	%edx, %edx
	movl	%eax, -168(%ebp)
	xorl	%eax, %eax
	xorl	%ecx, %ecx
	movl	%eax, -164(%ebp)
	xorl	%eax, %eax
	movl	%eax, -152(%ebp)
	xorl	%eax, %eax
	movl	%edx, -132(%ebp)
	xorl	%edx, %edx
	testl	%edx, %edx
	movl	%eax, -148(%ebp)
	leal	-192(%ebp), %eax
	movl	$0, -72(%ebp)
	movl	$0, -68(%ebp)
	movl	$0, -56(%ebp)
	movl	$0, -52(%ebp)
	movl	$0, -40(%ebp)
	movl	$0, -36(%ebp)
	movl	$0, -24(%ebp)
	movl	$0, -20(%ebp)
	movl	%ecx, -192(%ebp)
	movl	%eax, -136(%ebp)
	movl	%eax, -104(%ebp)
	movl	$0, -100(%ebp)
	jle	.L36
.L45:
	orl	$1, (%eax)   ; This can't be right!
.L37:
	incl	-100(%ebp)
	incl	%edx
	cmpl	$1, %edx
	jle	.L43
	movl	-192(%ebp), %eax
	leave
	ret
	.p2align 4,,7
.L43:
	testl	%edx, %edx
	movl	-104(%ebp), %eax
	jg	.L45
.L36:
	andl	$-2, (%eax)
	jmp	.L37
-------------------------------------

[Besides the codegen problem being reported here, it looks like there is
useless code which the compiler is not removing.]

Environment:
System: Linux karma 2.6.0 #9 Sun Dec 28 19:12:01 EST 2003 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: ../gcc/configure --prefix=/usr/local/gcc --enable-threads=posix --enable-long-long --enable-languages=c,c++,f77

How-To-Repeat:

Compile the below with -O2 -fno-strict-aliasing.

----------------------------------------------------------

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


struct xbasic_string
{
  ~xbasic_string() {}
};


class foo{};
struct _Bit_iterator_base : public foo
{
  unsigned long * _M_p;
  unsigned int _M_offset;
};
struct Bit_iterator : public _Bit_iterator_base { };


inline
Bit_iterator
copy (Bit_iterator result)
{
  for (int n = 0; n < 2; ++n) 
  {
    if (n>0)
      *result._M_p |= (1<<result._M_offset);
    else
      *result._M_p &= ~(1<<result._M_offset);
    result._M_offset++;
  }
  return result;
}


inline
Bit_iterator
copya (Bit_iterator result=Bit_iterator())
{
  return result;
}


struct BoolList
{
  Bit_iterator _M_start;

  BoolList() { }

  BoolList(const BoolList&) {
    unsigned long bb = 0;
    this->_M_start._M_p = &bb;
    copya();
  }
};


static
int foofoo(int,
           Bit_iterator first = Bit_iterator(),
           Bit_iterator last = Bit_iterator(),
           Bit_iterator a = Bit_iterator(),
           Bit_iterator b = Bit_iterator(),
           Bit_iterator c = Bit_iterator(),
           Bit_iterator d = Bit_iterator()
           )
{
  unsigned long bb = 0;
  Bit_iterator i;
  i._M_p = &bb;
  i._M_offset = 0;
  copy(i);
  return bb;
}


struct bvalue_type {
  xbasic_string first;
  BoolList second;
  bvalue_type(const BoolList& b=BoolList()) : second(b) {}
};


struct biterator
{
  biterator() {}
  biterator(const biterator& __it)  {}
};

inline bool xxx (biterator = biterator()) { return true; }


inline
biterator
insertfoo(biterator position=biterator(),
          const xbasic_string& s = xbasic_string())
{ return biterator(); }

inline
biterator
insertbar(biterator position=biterator(),
          const bvalue_type& __x=bvalue_type())
{  return biterator (); }

int add_bool_list()
{
  {
    biterator i;
    i = insertfoo();
    if (xxx ())
      insertbar();
  }
  return foofoo(1);
}

int main( )
{
  int b = add_bool_list();
  printf ("%d\n", b);
}

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

-- 
           Summary: bad code with -O3 -fno-strict-aliasing
           Product: gcc
           Version: 3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        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=13566


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

* [Bug optimization/13566] [3.4 Regression] bad code with -O3 -fno-strict-aliasing
  2004-01-05  3:26 [Bug c++/13566] New: bad code with -O3 -fno-strict-aliasing gcc-bugzilla at gcc dot gnu dot org
@ 2004-01-05  4:14 ` pinskia at gcc dot gnu dot org
  2004-01-10 16:30 ` hubicka at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-01-05  4:14 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-01-05 04:14 -------
Confirmed with -O1 -fgcse -finline-limit=20000 -finline-functions or -O1 -fgcse -funit-at-a-
time.  A regressions from 3.3.1, note this is most is not an inliner bug.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |critical
             Status|UNCONFIRMED                 |NEW
          Component|c++                         |optimization
     Ever Confirmed|                            |1
           Keywords|                            |wrong-code
   Last reconfirmed|0000-00-00 00:00:00         |2004-01-05 04:14:54
               date|                            |
            Summary|bad code with -O3 -fno-     |[3.4 Regression] bad code
                   |strict-aliasing             |with -O3 -fno-strict-
                   |                            |aliasing
   Target Milestone|---                         |3.4.0
            Version|3.4                         |3.4.0


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


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

* [Bug optimization/13566] [3.4 Regression] bad code with -O3 -fno-strict-aliasing
  2004-01-05  3:26 [Bug c++/13566] New: bad code with -O3 -fno-strict-aliasing gcc-bugzilla at gcc dot gnu dot org
  2004-01-05  4:14 ` [Bug optimization/13566] [3.4 Regression] " pinskia at gcc dot gnu dot org
@ 2004-01-10 16:30 ` hubicka at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: hubicka at gcc dot gnu dot org @ 2004-01-10 16:30 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From hubicka at gcc dot gnu dot org  2004-01-10 16:30 -------
 Apparently no longer reproduce on current CVS.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WORKSFORME


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


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

end of thread, other threads:[~2004-01-10 16:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-05  3:26 [Bug c++/13566] New: bad code with -O3 -fno-strict-aliasing gcc-bugzilla at gcc dot gnu dot org
2004-01-05  4:14 ` [Bug optimization/13566] [3.4 Regression] " pinskia at gcc dot gnu dot org
2004-01-10 16:30 ` hubicka 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).