From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 102342 invoked by alias); 20 Jun 2015 00:53:47 -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 100465 invoked by uid 48); 20 Jun 2015 00:53:43 -0000 From: "dmalcolm at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/66610] New: Compound assignments prevent value-numbering optimization Date: Sat, 20 Jun 2015 00:53: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: dmalcolm 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 target_milestone attachments.created 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/msg01808.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66610 Bug ID: 66610 Summary: Compound assignments prevent value-numbering optimization Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: dmalcolm at gcc dot gnu.org Target Milestone: --- Created attachment 35818 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35818&action=edit Minimal testcase demonstrating the issue libgccjit showed poor performance relative to a LLVM backend within an experimental JIT-compiler for Lua (https://github.com/dibyendumajumdar/ravi). On investigation it appears to be due to unions and structs stopping value-numbering from working. I'm attaching a minimal reproducer for the issue. If the code copies the struct and the union within it field-wise, pass_fre (tree-ssa-pre.c) uses value numbering to eliminate the copy of the loop index through *arr, and turns loop_using_union_field_assignment into: loop_using_union_field_assignment (int num_iters, struct s * arr) { int i; : goto ; : arr_6(D)->union_field.int_field = i_1; MEM[(struct s *)arr_6(D) + 4B].union_field.int_field = i_1; i_11 = i_1 + 1; : # i_1 = PHI <0(2), i_11(3)> if (i_1 < num_iters_5(D)) goto ; else goto ; : return; } and the loop is eliminated altogether by cddce2. However, if the code does a compound copy, pass_fre doesn't eliminate the copy of the loop index and the loop can't be eliminated (with a big performance loss); in the example, functions "loop_using_struct_assignment" and "loop_using_union_assignment" fail to have their loops optimized away at -O3. Hence the libgccjit user has patched things at their end to direct copying the fields (fwiw their workaround was this commit https://github.com/dibyendumajumdar/ravi/commit/a5b192cd4f4213cd544e31b08b02eb9082142b20 ) Should compound assignments be optimizable via value-numbering? Would it make sense to split out the compound assignments field-wise internally before doing value-numbering? This is all with gcc trunk (r224625 aka e3a904dbdc78cb45b98e8b109e0e49e759315b7c) on x86_64 at -O3.