public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/65143] New: [C++11] missing devirtualization for virtual base in "final" classes
@ 2015-02-20 17:52 balakrishnan.erode at gmail dot com
2015-02-20 18:06 ` [Bug c++/65143] " balakrishnan.erode at gmail dot com
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: balakrishnan.erode at gmail dot com @ 2015-02-20 17:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65143
Bug ID: 65143
Summary: [C++11] missing devirtualization for virtual base in
"final" classes
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: balakrishnan.erode at gmail dot com
When a class is marked final, it can devirtualize access to all base classes as
its layout is known. This is missing in gcc.
struct A
{
int i();
};
struct B : public virtual A
{
int get()
{
return A::i() + 1;
}
};
struct C final : public B
{
int get()
{
return A::i() + 2;
}
};
int foo(C& c)
{
return c.get(); // Need not go via vtable pointer as class C is final
}
int foo(B& b2)
{
return b2.get(); // This has to go via vtable as most derived class can
change the location of A
}
Assembly: Both do virtual dispatch
foo(C&):
subq $8, %rsp
movq (%rdi), %rax
addq -24(%rax), %rdi
call one::A::i()
addq $8, %rsp
addl $2, %eax
ret
foo(B&):
subq $8, %rsp
movq (%rdi), %rax
addq -24(%rax), %rdi
call one::A::i()
addq $8, %rsp
addl $1, %eax
ret
Complete example:
gcc: http://goo.gl/U4KEvj
clang: http://goo.gl/PpQCkd -- Clang does this optimization
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/65143] [C++11] missing devirtualization for virtual base in "final" classes
2015-02-20 17:52 [Bug c++/65143] New: [C++11] missing devirtualization for virtual base in "final" classes balakrishnan.erode at gmail dot com
@ 2015-02-20 18:06 ` balakrishnan.erode at gmail dot com
2015-03-13 16:12 ` balakrishnan.erode at gmail dot com
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: balakrishnan.erode at gmail dot com @ 2015-02-20 18:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65143
Balakrishnan B <balakrishnan.erode at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |balakrishnan.erode at gmail dot co
| |m
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=49488
--- Comment #1 from Balakrishnan B <balakrishnan.erode at gmail dot com> ---
I mean access to A::i() can be devirtualized in C::get().
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/65143] [C++11] missing devirtualization for virtual base in "final" classes
2015-02-20 17:52 [Bug c++/65143] New: [C++11] missing devirtualization for virtual base in "final" classes balakrishnan.erode at gmail dot com
2015-02-20 18:06 ` [Bug c++/65143] " balakrishnan.erode at gmail dot com
@ 2015-03-13 16:12 ` balakrishnan.erode at gmail dot com
2015-03-15 6:45 ` maltsevm at gmail dot com
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: balakrishnan.erode at gmail dot com @ 2015-03-13 16:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65143
--- Comment #2 from Balakrishnan B <balakrishnan.erode at gmail dot com> ---
Can someone please confirm the bug?
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/65143] [C++11] missing devirtualization for virtual base in "final" classes
2015-02-20 17:52 [Bug c++/65143] New: [C++11] missing devirtualization for virtual base in "final" classes balakrishnan.erode at gmail dot com
2015-02-20 18:06 ` [Bug c++/65143] " balakrishnan.erode at gmail dot com
2015-03-13 16:12 ` balakrishnan.erode at gmail dot com
@ 2015-03-15 6:45 ` maltsevm at gmail dot com
2015-03-17 14:48 ` balakrishnan.erode at gmail dot com
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: maltsevm at gmail dot com @ 2015-03-15 6:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65143
Mikhail Maltsev <maltsevm at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |maltsevm at gmail dot com
--- Comment #3 from Mikhail Maltsev <maltsevm at gmail dot com> ---
This optimization is still missing in current trunk:
$ cat ./test.cc
struct A
{
int j;
};
struct B : public virtual A
{
};
struct C final : public B
{
int get();
};
int C::get()
{
return A::j;
}
$ /opt/gcc-5.0.0/bin/g++ -O -std=c++11 -c -S ./test.cc -o test_gcc.s && cat
./test_gcc.s
.file "test.cc"
.text
.align 2
.globl _ZN1C3getEv
.type _ZN1C3getEv, @function
_ZN1C3getEv:
.LFB0:
.cfi_startproc
movq (%rdi), %rax
movq -24(%rax), %rax
movl (%rdi,%rax), %eax
ret
.cfi_endproc
.LFE0:
.size _ZN1C3getEv, .-_ZN1C3getEv
.ident "GCC: (GNU) 5.0.0 20150315 (experimental)"
.section .note.GNU-stack,"",@progbits
(Note: optimization flags like -O3 and -fdevirtualize-speculatively don't
affect this behavior; neither method calls nor data member accesses get
devirtualized)
$ clang++ -O -std=c++11 -c -S ./test.cc -o test_clang.s && cat ./test_clang.s
.text
.file "./test.cc"
.globl _ZN1C3getEv
.align 16, 0x90
.type _ZN1C3getEv,@function
_ZN1C3getEv: # @_ZN1C3getEv
.cfi_startproc
# BB#0: # %entry
movl 8(%rdi), %eax
retq
.Ltmp0:
.size _ZN1C3getEv, .Ltmp0-_ZN1C3getEv
.cfi_endproc
.ident "clang version 3.7.0 (trunk 228487)"
.section ".note.GNU-stack","",@progbits
So, I can confirm it in sense "reproduce" (I don't have a right to change the
status of PR)
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/65143] [C++11] missing devirtualization for virtual base in "final" classes
2015-02-20 17:52 [Bug c++/65143] New: [C++11] missing devirtualization for virtual base in "final" classes balakrishnan.erode at gmail dot com
` (2 preceding siblings ...)
2015-03-15 6:45 ` maltsevm at gmail dot com
@ 2015-03-17 14:48 ` balakrishnan.erode at gmail dot com
2015-08-12 10:30 ` trippels at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: balakrishnan.erode at gmail dot com @ 2015-03-17 14:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65143
--- Comment #4 from Balakrishnan B <balakrishnan.erode at gmail dot com> ---
Thanks for confirming!
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/65143] [C++11] missing devirtualization for virtual base in "final" classes
2015-02-20 17:52 [Bug c++/65143] New: [C++11] missing devirtualization for virtual base in "final" classes balakrishnan.erode at gmail dot com
` (3 preceding siblings ...)
2015-03-17 14:48 ` balakrishnan.erode at gmail dot com
@ 2015-08-12 10:30 ` trippels at gcc dot gnu.org
2015-08-12 10:37 ` trippels at gcc dot gnu.org
2015-08-13 10:42 ` paolo.carlini at oracle dot com
6 siblings, 0 replies; 8+ messages in thread
From: trippels at gcc dot gnu.org @ 2015-08-12 10:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65143
Markus Trippelsdorf <trippels at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |gpderetta at gmail dot com
--- Comment #5 from Markus Trippelsdorf <trippels at gcc dot gnu.org> ---
*** Bug 67184 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/65143] [C++11] missing devirtualization for virtual base in "final" classes
2015-02-20 17:52 [Bug c++/65143] New: [C++11] missing devirtualization for virtual base in "final" classes balakrishnan.erode at gmail dot com
` (4 preceding siblings ...)
2015-08-12 10:30 ` trippels at gcc dot gnu.org
@ 2015-08-12 10:37 ` trippels at gcc dot gnu.org
2015-08-13 10:42 ` paolo.carlini at oracle dot com
6 siblings, 0 replies; 8+ messages in thread
From: trippels at gcc dot gnu.org @ 2015-08-12 10:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65143
Markus Trippelsdorf <trippels at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |trippels at gcc dot gnu.org
--- Comment #6 from Markus Trippelsdorf <trippels at gcc dot gnu.org> ---
Testcase from PR67184:
markus@x4 tmp % cat test.ii
struct V {
virtual void foo();
};
struct wV final : V {};
struct oV final : V {
void foo();
};
void call(V &x) { x.foo(); }
void call(wV &x) { x.foo(); }
void call(oV &x) { x.foo(); }
markus@x4 tmp % clang++ -std=c++14 -c -O3 -S test.ii -o -
...
_Z4callR2wV: # @_Z4callR2wV
.cfi_startproc
# BB#0: # %entry
jmp _ZN1V3fooEv # TAILCALL
...
markus@x4 tmp % g++ -std=c++14 -O3 -c -S test.ii -o -
...
_Z4callR2wV:
.LFB1:
.cfi_startproc
movq (%rdi), %rax
jmp *(%rax)
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/65143] [C++11] missing devirtualization for virtual base in "final" classes
2015-02-20 17:52 [Bug c++/65143] New: [C++11] missing devirtualization for virtual base in "final" classes balakrishnan.erode at gmail dot com
` (5 preceding siblings ...)
2015-08-12 10:37 ` trippels at gcc dot gnu.org
@ 2015-08-13 10:42 ` paolo.carlini at oracle dot com
6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-08-13 10:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65143
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2015-08-13
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=63164
Ever confirmed|0 |1
--- Comment #7 from Paolo Carlini <paolo.carlini at oracle dot com> ---
I'm not sure the two bugs are exactly equivalent. Anyway, when working on these
optimization issues, let' remember c++/63164 too.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2015-08-13 10:42 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-20 17:52 [Bug c++/65143] New: [C++11] missing devirtualization for virtual base in "final" classes balakrishnan.erode at gmail dot com
2015-02-20 18:06 ` [Bug c++/65143] " balakrishnan.erode at gmail dot com
2015-03-13 16:12 ` balakrishnan.erode at gmail dot com
2015-03-15 6:45 ` maltsevm at gmail dot com
2015-03-17 14:48 ` balakrishnan.erode at gmail dot com
2015-08-12 10:30 ` trippels at gcc dot gnu.org
2015-08-12 10:37 ` trippels at gcc dot gnu.org
2015-08-13 10:42 ` paolo.carlini at oracle 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).