public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/104316] New: Missing optimization for uninitialized local struct variable
@ 2022-01-31 22:34 roland.illig at gmx dot de
2022-01-31 22:41 ` [Bug tree-optimization/104316] RSO is not used when doing assignment rather than initialization and address taken afterwards pinskia at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: roland.illig at gmx dot de @ 2022-01-31 22:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104316
Bug ID: 104316
Summary: Missing optimization for uninitialized local struct
variable
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: roland.illig at gmx dot de
Target Milestone: ---
~~~c
#include <stdlib.h>
typedef struct Buffer {
char *buf;
size_t len;
size_t cap;
} Buffer;
Buffer Buffer_Init_Return(void);
void Buffer_Init_Ref(Buffer *buf);
void Buffer_Add(Buffer *buf, const char *);
void
Use_Buffers(void)
{
Buffer buf1 = Buffer_Init_Return();
Buffer buf2;
buf2 = Buffer_Init_Return();
Buffer_Add(&buf1, "1");
Buffer_Add(&buf2, "2");
}
~~~
https://godbolt.org/z/qTz36qP9r
The code snippets for initializing buf1 and buf2 are almost the same. From an
as-if perspective, they are identical.
GCC 12 generates several copy instructions when initializing buf2, while Clang
and ICC generate the straight-forward code.
Would it be difficult to tell GCC to optimize the above initialization for
buf2, for the case that buf2 is not accessed between the declaration and the
assignment?
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/104316] RSO is not used when doing assignment rather than initialization and address taken afterwards
2022-01-31 22:34 [Bug c/104316] New: Missing optimization for uninitialized local struct variable roland.illig at gmx dot de
@ 2022-01-31 22:41 ` pinskia at gcc dot gnu.org
2022-01-31 22:44 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-31 22:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104316
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|Missing optimization for |RSO is not used when doing
|uninitialized local struct |assignment rather than
|variable |initialization and address
| |taken afterwards
Keywords| |missed-optimization
Severity|normal |enhancement
Component|c |tree-optimization
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/104316] RSO is not used when doing assignment rather than initialization and address taken afterwards
2022-01-31 22:34 [Bug c/104316] New: Missing optimization for uninitialized local struct variable roland.illig at gmx dot de
2022-01-31 22:41 ` [Bug tree-optimization/104316] RSO is not used when doing assignment rather than initialization and address taken afterwards pinskia at gcc dot gnu.org
@ 2022-01-31 22:44 ` pinskia at gcc dot gnu.org
2022-01-31 22:48 ` pinskia at gcc dot gnu.org
2022-01-31 22:50 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-31 22:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104316
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
return slot optimization
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/104316] RSO is not used when doing assignment rather than initialization and address taken afterwards
2022-01-31 22:34 [Bug c/104316] New: Missing optimization for uninitialized local struct variable roland.illig at gmx dot de
2022-01-31 22:41 ` [Bug tree-optimization/104316] RSO is not used when doing assignment rather than initialization and address taken afterwards pinskia at gcc dot gnu.org
2022-01-31 22:44 ` pinskia at gcc dot gnu.org
@ 2022-01-31 22:48 ` pinskia at gcc dot gnu.org
2022-01-31 22:50 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-31 22:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104316
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2022-01-31
Ever confirmed|0 |1
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
NRV has:
static bool
dest_safe_for_nrv_p (gcall *call)
{
tree dest = gimple_call_lhs (call);
dest = get_base_address (dest);
if (! dest)
return false;
if (TREE_CODE (dest) == SSA_NAME)
return true;
if (call_may_clobber_ref_p (call, dest, false)
|| ref_maybe_used_by_stmt_p (call, dest, false))
return false;
return true;
}
Which is fine, the problem is the clobber list is not exactly flow senative, I
think there is another bug about that.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/104316] RSO is not used when doing assignment rather than initialization and address taken afterwards
2022-01-31 22:34 [Bug c/104316] New: Missing optimization for uninitialized local struct variable roland.illig at gmx dot de
` (2 preceding siblings ...)
2022-01-31 22:48 ` pinskia at gcc dot gnu.org
@ 2022-01-31 22:50 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-31 22:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104316
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Depends on| |23384
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Yes PR 23384.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=23384
[Bug 23384] escaped set should be flow sensitive
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-01-31 22:50 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-31 22:34 [Bug c/104316] New: Missing optimization for uninitialized local struct variable roland.illig at gmx dot de
2022-01-31 22:41 ` [Bug tree-optimization/104316] RSO is not used when doing assignment rather than initialization and address taken afterwards pinskia at gcc dot gnu.org
2022-01-31 22:44 ` pinskia at gcc dot gnu.org
2022-01-31 22:48 ` pinskia at gcc dot gnu.org
2022-01-31 22:50 ` pinskia 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).