From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 69692 invoked by alias); 2 Jun 2015 13:31:12 -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 69628 invoked by uid 48); 2 Jun 2015 13:31:08 -0000 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/66379] New: SCCVN doesn't handle aggregate array element accesses very well Date: Tue, 02 Jun 2015 13:31: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: 6.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: 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 blocked target_milestone 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: 2015-06/txt/msg00168.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66379 Bug ID: 66379 Summary: SCCVN doesn't handle aggregate array element accesses very well Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: rguenth at gcc dot gnu.org Blocks: 66142 Target Milestone: --- struct X { int i; int j; }; struct X a[128]; int foo (int i) { struct X x; x.i = i; x.j = 0; a[i] = x; return a[i].i; } should ideally optimize to return i; But first, FRE is confused by SRA: : _4 = &a[i_2(D)]; MEM[(struct X *)_4] = i_2(D); MEM[(struct X *)_4 + 4B] = 0; _6 = a[i_2(D)].i; return _6; and second (if SRA is disabled), : x.i = i_2(D); x.j = 0; a[i_2(D)] = x; _6 = a[i_2(D)].i; x ={v} {CLOBBER}; return _6; the aggregate copy lookthrough code is too simple here (offset-based stuff just bails out with variable indexes). Using stmt_kills_ref_p helps for this case but it does not for the testcase in PR66142. @@ -1879,7 +1895,7 @@ vn_reference_lookup_3 (ao_ref *ref, tree || handled_component_p (gimple_assign_rhs1 (def_stmt)))) { tree base2; - HOST_WIDE_INT offset2, size2, maxsize2; + HOST_WIDE_INT maxsize2; int i, j; auto_vec rhs; vn_reference_op_t vro; @@ -1890,8 +1906,6 @@ vn_reference_lookup_3 (ao_ref *ref, tree /* See if the assignment kills REF. */ base2 = ao_ref_base (&lhs_ref); - offset2 = lhs_ref.offset; - size2 = lhs_ref.size; maxsize2 = lhs_ref.max_size; if (maxsize2 == -1 || (base != base2 @@ -1900,8 +1914,7 @@ vn_reference_lookup_3 (ao_ref *ref, tree || TREE_OPERAND (base, 0) != TREE_OPERAND (base2, 0) || !tree_int_cst_equal (TREE_OPERAND (base, 1), TREE_OPERAND (base2, 1)))) - || offset2 > offset - || offset2 + size2 < offset + maxsize) + || !stmt_kills_ref_p (def_stmt, ref)) return (void *)-1; /* Find the common base of ref and the lhs. lhs_ops already Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66142 [Bug 66142] Loop is not vectorized because not sufficient support for GOMP_SIMD_LANE