From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7426 invoked by alias); 16 Jul 2014 09:55:35 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 7311 invoked by uid 48); 16 Jul 2014 09:55:29 -0000 From: "manjian2006 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/61818] New: unused code fails to be removed after dom1, thread updated Date: Wed, 16 Jul 2014 09:55:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 4.9.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: manjian2006 at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-07/txt/msg01059.txt.bz2 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 #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 if (&nD.2229 == n2_9) goto ; else goto ; remain to the end, and get "cleverly" optimized into the following form: if (&nD.2229 == n2_5) goto ; else goto ; 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?