This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/32572] New: Small C++ function fails to inline with large negative badness


The code below doesn't get image::set inlined into set_test at -O3, though it's
trivial.
Is it an integer overflow problem?

> /usr/local/gcc43/bin/g++ -v
Using built-in specs.
Target: i386-apple-darwin8.10.1
Configured with: ../gcc/configure --prefix=/usr/local/gcc43 --disable-multilib
--with-arch=pentium-m --with-tune=nocona --enable-target-optspace
--disable-bootstrap --with-gmp=/sw --with-system-zlib
--enable-languages=c,c++,objc,obj-c++
Thread model: posix
gcc version 4.3.0 20070701 (experimental)
> /usr/local/gcc43/bin/g++ -O3 -c -fdump-ipa-all -fdump-tree-final_cleanup rt-inline-overflow.cpp

>From the .inline dump:
Deciding on inlining.  Starting with 39 insns.

Inlining always_inline functions:

Deciding on smaller functions:
Considering inline candidate void image::set(size_t, size_t, f_pixel, f_real).

Considering void image::set(size_t, size_t, f_pixel, f_real) with 15 insns
 to be inlined into void set_test(image*, int, int, f_pixel&, double)
 Estimated growth after inlined into all callees is -21 insns.
 Estimated badness is -2147483642, frequency 1.00.
 Not inlining into void set_test(image*, int, int, f_pixel&, double):function
not considered for inlining.

Deciding on functions called once:

Inlined 3 calls, eliminated 2 functions, 39 insns turned to 39 insns.

typedef unsigned int size_t;
typedef float f_real;

template <typename T> struct triple
{
 union {
  T val[3];
  struct {T x,y,z;};
  struct {T r,g,b;};
 };
 T pad;

 triple(const T v[3]) {for (int i = 0; i < 3; i++) val[i] = v[i];}
 triple(T a_, T b_=0., T c_=0.) {x = a_; y = b_; z = c_;}
 triple() {}

 triple(const triple<T> &t) {x=t.x;y=t.y;z=t.z;}
 triple(const triple<T> *t) {x=t->x;y=t->y;z=t->z;}

 triple<T> operator=(const triple<T> &t) {x=t.x;y=t.y;z=t.z; return *this;}
} __attribute__((aligned));

typedef triple<f_real> f_pixel;

struct image
{
 f_pixel *buf;
 f_real *depth_buf;
 f_pixel minv, maxv;
 size_t w, h;

 image(size_t w, size_t h);
 ~image();
 void write_to_bmp(const char *path);

 inline void set(size_t x, size_t y, const f_pixel p, f_real depth) {
  buf[y*w + x] = p;
  depth_buf[y*w + x] = depth;
 }

};

void set_test(image *target, int x, int y, f_pixel &c, double dist)
{
 target->set(x,y,c,dist);
}


-- 
           Summary: Small C++ function fails to inline with large negative
                    badness
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: astrange at ithinksw dot com
 GCC build triplet: i386-apple-darwin8.10.1
  GCC host triplet: i386-apple-darwin8.10.1
GCC target triplet: i386-apple-darwin8.10.1


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]