public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/66355] New: defining a constructor inhibits optimization
@ 2015-05-31 22:01 kalmquist1 at hotmail dot com
  2015-06-01  8:43 ` [Bug c++/66355] " redi at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: kalmquist1 at hotmail dot com @ 2015-05-31 22:01 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66355

            Bug ID: 66355
           Summary: defining a constructor inhibits optimization
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kalmquist1 at hotmail dot com
  Target Milestone: ---

Created attachment 35659
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35659&action=edit
Archive contains wrap-int-[012].cxx and makefile

Ideally, replacing the type "int" with a wrapper class that contains a single
"int" value as a member should not impose any performance penalty. 
Unfortunately, that is not the case if the wrapper class has a non-default
constructor, which it almost certainly will.

The attached archive contains three programs, which can be compiled to assembly
language using the included makefile.

wrap-int-0.cxx contains a very simple integer computation.

wrap-int-1.cxx does the same thing, but the "int" type has been replaced by a
wrapper class.  The generated assembly instructions are same, so there is no
performance penalty for using the wrapper class.

wrap-int-2.cxx is the same as wrap-int-1.cxx except that a constructor has been
added to the wrapper class.  One would expect a good optimizer to generate the
same code for this program as for the other two programs, but in fact the
generated code is a good deal larger.

I'm guessing that what is happening is that if a type has a non-default
constructor, the C++ front end treats constants of that type as variables
rather than as contstants, so that even simple optimizations like constant
folding are no longer performed by that back end.


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

* [Bug c++/66355] defining a constructor inhibits optimization
  2015-05-31 22:01 [Bug c++/66355] New: defining a constructor inhibits optimization kalmquist1 at hotmail dot com
@ 2015-06-01  8:43 ` redi at gcc dot gnu.org
  2015-06-06  8:19 ` glisse at gcc dot gnu.org
  2015-06-10  1:04 ` kalmquist1 at hotmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2015-06-01  8:43 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66355

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
If you make the constructors and operator+ constexpr and compile with
-std=gnu++14 then you remove the overhead.


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

* [Bug c++/66355] defining a constructor inhibits optimization
  2015-05-31 22:01 [Bug c++/66355] New: defining a constructor inhibits optimization kalmquist1 at hotmail dot com
  2015-06-01  8:43 ` [Bug c++/66355] " redi at gcc dot gnu.org
@ 2015-06-06  8:19 ` glisse at gcc dot gnu.org
  2015-06-10  1:04 ` kalmquist1 at hotmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: glisse at gcc dot gnu.org @ 2015-06-06  8:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66355

--- Comment #2 from Marc Glisse <glisse at gcc dot gnu.org> ---
PR 65197 has links to a number of related PRs. The middle-end has no code to
handle the case where we detect "late" (i.e. not in the front-end) that the
initialization is constant.


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

* [Bug c++/66355] defining a constructor inhibits optimization
  2015-05-31 22:01 [Bug c++/66355] New: defining a constructor inhibits optimization kalmquist1 at hotmail dot com
  2015-06-01  8:43 ` [Bug c++/66355] " redi at gcc dot gnu.org
  2015-06-06  8:19 ` glisse at gcc dot gnu.org
@ 2015-06-10  1:04 ` kalmquist1 at hotmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: kalmquist1 at hotmail dot com @ 2015-06-10  1:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66355

kalmquist1 at hotmail dot com <kalmquist1 at hotmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #3 from kalmquist1 at hotmail dot com <kalmquist1 at hotmail dot com> ---
Thanks to the pointer provided by Marc Glisse, I found that this issue was
reported back in 2001, in PR 4131.

*** This bug has been marked as a duplicate of bug 4131 ***


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

end of thread, other threads:[~2015-06-10  1:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-31 22:01 [Bug c++/66355] New: defining a constructor inhibits optimization kalmquist1 at hotmail dot com
2015-06-01  8:43 ` [Bug c++/66355] " redi at gcc dot gnu.org
2015-06-06  8:19 ` glisse at gcc dot gnu.org
2015-06-10  1:04 ` kalmquist1 at hotmail dot com

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).