public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/110819] New: Missed optimization: when vector size is 0 but vector::reserve has been called.
@ 2023-07-26 16:37 hiraditya at msn dot com
2023-07-26 16:38 ` [Bug tree-optimization/110819] Missed optimization: when vector's " pinskia at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: hiraditya at msn dot com @ 2023-07-26 16:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110819
Bug ID: 110819
Summary: Missed optimization: when vector size is 0 but
vector::reserve has been called.
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: hiraditya at msn dot com
Target Milestone: ---
#include<vector>
void f(int);
void use_idx_const_size_reserve() {
std::vector<int> v;
v.reserve(100000);
auto s = v.size();
for (std::vector<int>::size_type i = 0; i < s; i++)
f(v[i]);
}
$ g++ -O3
use_idx_const_size_reserve():
sub rsp, 8
mov edi, 400000
call operator new(unsigned long)
mov esi, 400000
add rsp, 8
mov rdi, rax
jmp operator delete(void*, unsigned long)
$ clang++ -O3 -stdlib=libc++
use_idx_const_size_reserve(): # @use_idx_const_size_reserve()
ret
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/110819] Missed optimization: when vector's size is 0 but vector::reserve has been called.
2023-07-26 16:37 [Bug c++/110819] New: Missed optimization: when vector size is 0 but vector::reserve has been called hiraditya at msn dot com
@ 2023-07-26 16:38 ` pinskia at gcc dot gnu.org
2023-07-26 18:02 ` redi at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-26 16:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110819
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|c++ |tree-optimization
Keywords| |missed-optimization
Severity|normal |enhancement
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/110819] Missed optimization: when vector's size is 0 but vector::reserve has been called.
2023-07-26 16:37 [Bug c++/110819] New: Missed optimization: when vector size is 0 but vector::reserve has been called hiraditya at msn dot com
2023-07-26 16:38 ` [Bug tree-optimization/110819] Missed optimization: when vector's " pinskia at gcc dot gnu.org
@ 2023-07-26 18:02 ` redi at gcc dot gnu.org
2023-07-29 2:08 ` hiraditya at msn dot com
2023-07-29 7:15 ` xry111 at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-26 18:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110819
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=110137
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I guess gcc can't optimize this away because it doesn't know if operator new
has side effects. When compiled with clang, libstdc++'s std::vector uses
__builtin_operator_new which always has the -fassume-sane-operator-new
semantics, and so can be optimized.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/110819] Missed optimization: when vector's size is 0 but vector::reserve has been called.
2023-07-26 16:37 [Bug c++/110819] New: Missed optimization: when vector size is 0 but vector::reserve has been called hiraditya at msn dot com
2023-07-26 16:38 ` [Bug tree-optimization/110819] Missed optimization: when vector's " pinskia at gcc dot gnu.org
2023-07-26 18:02 ` redi at gcc dot gnu.org
@ 2023-07-29 2:08 ` hiraditya at msn dot com
2023-07-29 7:15 ` xry111 at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: hiraditya at msn dot com @ 2023-07-29 2:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110819
--- Comment #2 from AK <hiraditya at msn dot com> ---
> When compiled with clang, libstdc++'s std::vector uses __builtin_operator_new which always has the -fassume-sane-operator-new semantics, and so can be optimized.
yes clang optimizes with libstdc++ as well. what can be done in gcc for it to
detect that the new+delete pair can be optimized away?
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/110819] Missed optimization: when vector's size is 0 but vector::reserve has been called.
2023-07-26 16:37 [Bug c++/110819] New: Missed optimization: when vector size is 0 but vector::reserve has been called hiraditya at msn dot com
` (2 preceding siblings ...)
2023-07-29 2:08 ` hiraditya at msn dot com
@ 2023-07-29 7:15 ` xry111 at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-07-29 7:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110819
Xi Ruoyao <xry111 at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |xry111 at gcc dot gnu.org
--- Comment #3 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
(In reply to AK from comment #2)
> > When compiled with clang, libstdc++'s std::vector uses __builtin_operator_new which always has the -fassume-sane-operator-new semantics, and so can be optimized.
>
> yes clang optimizes with libstdc++ as well. what can be done in gcc for it
> to detect that the new+delete pair can be optimized away?
Basically we'll need __builtin_operator_new. See all the "see also" links.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-07-29 7:15 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-26 16:37 [Bug c++/110819] New: Missed optimization: when vector size is 0 but vector::reserve has been called hiraditya at msn dot com
2023-07-26 16:38 ` [Bug tree-optimization/110819] Missed optimization: when vector's " pinskia at gcc dot gnu.org
2023-07-26 18:02 ` redi at gcc dot gnu.org
2023-07-29 2:08 ` hiraditya at msn dot com
2023-07-29 7:15 ` xry111 at gcc dot gnu.org
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).