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/3713] Pointers to functions or member functions are not folded or inlined



------- Comment #14 from guillaume dot melquiond at ens-lyon dot fr  2007-09-02 11:56 -------
Created an attachment (id=14150)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=14150&action=view)
Implements folding of "(&function & 1)"

I encountered the same issue with some heavy template code: GCC was generating
some really awful code, while it should have been optimized to almost anything.
It basically comes down to this kind of C++ code:

  struct A { void a(); };
  template < void (A::*f)() >
  void g(A *t) { (t->*f)(); }
  void h(A *t) { g<&A::a>(t); }

After instantiation, it is somehow transformed to:

  struct A { void a(); };
  void h(A *t) { (t->*(&A::a))(); }

And GCC is unable to optimize it. So I played a bit with the attached patch,
which does fix the issue for my template code.

Note that GCC does inline the member function for my code (just add an empty
body to A::a to test it), but it doesn't inline it in Andrew Pinski's last
testcase. I have no idea why; perhaps because the address goes through a
variable. But at least the generated code no longer contain any crap and it
directly calls the correct function, even if it doesn't inline it.

(As for why the C++ front-end generates this code in the first place, it is
because the lower bit of the pointer indicates whether an extra indirection is
needed when calling the function through the pointer to member. The C++
front-end actually assumes that functions have an alignment of 2 at least, so
that this trick can work.)


-- 


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


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