public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/61818] New: unused code fails to be removed after dom1, thread updated
@ 2014-07-16 9:55 manjian2006 at gmail dot com
2014-07-16 11:22 ` [Bug tree-optimization/61818] " rguenth at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: manjian2006 at gmail dot com @ 2014-07-16 9:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61818
Bug ID: 61818
Summary: unused code fails to be removed after dom1, thread
updated
Product: gcc
Version: 4.9.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: manjian2006 at gmail dot com
I found the following code:
#include <stddef.h>
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
struct Node
{
Node* m_next;
int m_val;
};
void setLast(Node* n, int val)
{
Node** ppnode = &n;
while (*ppnode) {
ppnode = &(*ppnode)->m_next;
}
// This if statement should be removed
if (ppnode == &n)
return;
Node* n2 = container_of(ppnode, Node, m_next);
n2->m_val = val;
}
generates wired assembly codes:
_Z7setLastP4Nodei:
.LFB0:
.cfi_startproc
testq %rdi, %rdi
movq %rdi, -8(%rsp)
jne .L3
jmp .L9
.p2align 4,,10
.p2align 3
.L4:
movq %rax, %rdi
.L3:
movq (%rdi), %rax
testq %rax, %rax
jne .L4
=> leaq -8(%rsp), %rax
=> cmpq %rax, %rdi
=> je .L1
movl %esi, 8(%rdi)
.L1:
rep ret
.L9:
rep ret
note that the marked assembly codes should not even exist. The value stored in
-8(%rsp) remains not used.
After further debugging. I find
.cfi_startproc
testq %rdi, %rdi
movq %rdi, -8(%rsp)
jne .L3
jmp .L9
is generated by "ch" pass (copy_loop_headers). That makes sense.
And that jump to the exist block is threaded in dom1 pass, and it makes sense
too.
But gimpl codes:
# n2_9 = PHI <n2_5(4)>
if (&nD.2229 == n2_9)
goto <bb 7>;
else
goto <bb 6>;
remain to the end, and get "cleverly" optimized into the following form:
if (&nD.2229 == n2_5)
goto <bb 7>;
else
goto <bb 6>;
That does not make any sense.
GCC should have a pass to remove this code.
Is that because currently pointer analysis is not flow-aware?
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/61818] unused code fails to be removed after dom1, thread updated
2014-07-16 9:55 [Bug tree-optimization/61818] New: unused code fails to be removed after dom1, thread updated manjian2006 at gmail dot com
@ 2014-07-16 11:22 ` rguenth at gcc dot gnu.org
2021-12-26 21:28 ` pinskia at gcc dot gnu.org
2024-05-16 12:47 ` rguenth at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-07-16 11:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61818
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |missed-optimization
Status|UNCONFIRMED |NEW
Last reconfirmed| |2014-07-16
Depends on| |13962
Ever confirmed|0 |1
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
No, because there isn't any transform I am aware of that would do this. You
suggest sth similar suggested in PR13962.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/61818] unused code fails to be removed after dom1, thread updated
2014-07-16 9:55 [Bug tree-optimization/61818] New: unused code fails to be removed after dom1, thread updated manjian2006 at gmail dot com
2014-07-16 11:22 ` [Bug tree-optimization/61818] " rguenth at gcc dot gnu.org
@ 2021-12-26 21:28 ` pinskia at gcc dot gnu.org
2024-05-16 12:47 ` rguenth at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-26 21:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61818
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Known to work| |7.1.0
Resolution|--- |FIXED
Known to fail| |5.1.0, 6.1.0
Target Milestone|--- |7.0
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed in GCC 7.
What was missing was not optimizing:
ppnode.1_5 = &_15->m_next;
if (&n == ppnode.1_5)
Even though n never escaped.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/61818] unused code fails to be removed after dom1, thread updated
2014-07-16 9:55 [Bug tree-optimization/61818] New: unused code fails to be removed after dom1, thread updated manjian2006 at gmail dot com
2014-07-16 11:22 ` [Bug tree-optimization/61818] " rguenth at gcc dot gnu.org
2021-12-26 21:28 ` pinskia at gcc dot gnu.org
@ 2024-05-16 12:47 ` rguenth at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-05-16 12:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61818
Bug 61818 depends on bug 13962, which changed state.
Bug 13962 Summary: [tree-ssa] make "fold" use alias information to optimize pointer comparisons
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=13962
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-05-16 12:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-16 9:55 [Bug tree-optimization/61818] New: unused code fails to be removed after dom1, thread updated manjian2006 at gmail dot com
2014-07-16 11:22 ` [Bug tree-optimization/61818] " rguenth at gcc dot gnu.org
2021-12-26 21:28 ` pinskia at gcc dot gnu.org
2024-05-16 12:47 ` rguenth 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).