c++/6546: Optimization regression

Nathan Myers ncm@itasoftware.com
Thu May 2 22:26:00 GMT 2002


>Number:         6546
>Category:       c++
>Synopsis:       static const members optimization failure
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          pessimizes-code
>Submitter-Id:   net
>Arrival-Date:   Thu May 02 22:26:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Nathan Myers
>Release:        3.1 20020422 (prerelease)
>Organization:
ITA Software
>Environment:
>Description:
  The compiler fails to elide loading the value of a static const class 
  member initialized in the class definition when passing it to a function 
  that takes a const& to that type.  This is a regression from 2.95.

  In particular, it fails to generate a compare-immediate operation,
  instead loading the value from main memory.

>How-To-Repeat:
  struct Foo { static const int maxSegments = 10; };
  template< typename T > 
    inline const T& amin(const T& t1, const T& t2) { return t2 < t1 ? t2 : t1; }
  template< typename T > 
    inline T bmin(const T& t1, const T& t2) { return t2 < t1 ? t2 : t1; }
  
  int do_something(int argument)
  {
    return amin(argument, Foo::maxSegments) + bmin(argument, Foo::maxSegments);
  }
  const int Foo::maxSegments;

  $ gcc -S -O3 bug.cc 

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
 >System: Linux ipc 2.4.19-pre4 #3 SMP Fri Mar 29 02:57:10 EST 2002 i686 unknown
 >Architecture: i686
 >host: i686-pc-linux-gnu
 >build: i686-pc-linux-gnu
 >target: i686-pc-linux-gnu
 >configured with: ../gcc-3.1/configure --enable-languages=c++ --enable-threads=posix --prefix=/ncm/gnu-3.1 --enable-concept-checks



More information about the Gcc-bugs mailing list