public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/102829] New: Redundant null check after atomic load from that address
@ 2021-10-19 8:17 laurynas.biveinis at gmail dot com
2021-10-19 8:31 ` [Bug tree-optimization/102829] " rguenth at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: laurynas.biveinis at gmail dot com @ 2021-10-19 8:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102829
Bug ID: 102829
Summary: Redundant null check after atomic load from that
address
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: laurynas.biveinis at gmail dot com
Target Milestone: ---
The following source code
----
struct d {
long b;
d *e() {
__atomic_load_n(&b, 0);
return this;
}
};
d *j;
void i();
void k() {
auto l = j->e();
if (l)
i();
}
----
produces the following bit of assembly with -O3 on x86_64
(https://godbolt.org/z/G1ThvnMWP):
...
mov rdx, QWORD PTR [rax]
test rax, rax
je .L1
...
It first dereferences the address at RAX, and later checks whether RAX == 0.
Since we already tried accessing memory at that address, the nullptr check
seems redundant. Moreover, since the address happens to be of 'this' of
variable j, it being equal to nullptr is UB anyway and may be assumed to be !=
nullptr?
Clang tests show the redundant test being present up to version 11 inclusive
(https://godbolt.org/z/rT3ha4enb) and absent from version 12 onwards
(https://godbolt.org/z/Gfb9EWMfq)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/102829] Redundant null check after atomic load from that address
2021-10-19 8:17 [Bug middle-end/102829] New: Redundant null check after atomic load from that address laurynas.biveinis at gmail dot com
@ 2021-10-19 8:31 ` rguenth at gcc dot gnu.org
2021-10-19 14:03 ` laurynas.biveinis at gmail dot com
2021-10-22 21:46 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-10-19 8:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102829
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|middle-end |tree-optimization
Ever confirmed|0 |1
Blocks| |85316
Status|UNCONFIRMED |NEW
Keywords| |missed-optimization
Last reconfirmed| |2021-10-19
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
We don't derive non-nullness for the pointer dereferenced by the atomic
builtins yet.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85316
[Bug 85316] [meta-bug] VRP range propagation missed cases
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/102829] Redundant null check after atomic load from that address
2021-10-19 8:17 [Bug middle-end/102829] New: Redundant null check after atomic load from that address laurynas.biveinis at gmail dot com
2021-10-19 8:31 ` [Bug tree-optimization/102829] " rguenth at gcc dot gnu.org
@ 2021-10-19 14:03 ` laurynas.biveinis at gmail dot com
2021-10-22 21:46 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: laurynas.biveinis at gmail dot com @ 2021-10-19 14:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102829
--- Comment #2 from Laurynas Biveinis <laurynas.biveinis at gmail dot com> ---
FWIW adding "if (this == nullptr) __builtin_unreachable();" between
__atomic_load_n and return fails to workaround this issue
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/102829] Redundant null check after atomic load from that address
2021-10-19 8:17 [Bug middle-end/102829] New: Redundant null check after atomic load from that address laurynas.biveinis at gmail dot com
2021-10-19 8:31 ` [Bug tree-optimization/102829] " rguenth at gcc dot gnu.org
2021-10-19 14:03 ` laurynas.biveinis at gmail dot com
@ 2021-10-22 21:46 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-22 21:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102829
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-10-22 21:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-19 8:17 [Bug middle-end/102829] New: Redundant null check after atomic load from that address laurynas.biveinis at gmail dot com
2021-10-19 8:31 ` [Bug tree-optimization/102829] " rguenth at gcc dot gnu.org
2021-10-19 14:03 ` laurynas.biveinis at gmail dot com
2021-10-22 21:46 ` 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).