From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 105875 invoked by alias); 19 Apr 2016 14:05:08 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 105804 invoked by uid 89); 19 Apr 2016 14:05:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,KAM_ASCII_DIVIDERS,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=no version=3.3.2 spammy=rebootstrapped, re-bootstrapped, gsi_for_stmt, sk:is_gim X-HELO: mail-wm0-f49.google.com Received: from mail-wm0-f49.google.com (HELO mail-wm0-f49.google.com) (74.125.82.49) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 19 Apr 2016 14:04:44 +0000 Received: by mail-wm0-f49.google.com with SMTP id v188so163642161wme.1 for ; Tue, 19 Apr 2016 07:04:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to; bh=ZgndM+w+EviclB9v/d2nW/B+fxUDK9XmCxlq2uZso6E=; b=FNdgQDHNgHb3qRRnd/n11O1QDE8wMUAGps9w9Z5jWM/gKWLvSypYgc36Ewbn3b5Gjf Zs7oZdQlkM8SeFihDjOyH678oGyZVwMhHPTJIW1VvVIVHnjdX8qvy4qSL6/FWNGhKtJB UdMzHUP27WzHndlrH79u+ANAHC4HpjpgHvropP7id5pK5wQtG0iJzFdpyCrVb90ltwtk 1KxJbyUF4P+FqqXBfGOs21TgfdFitiZa5Bpi07HNx0kkRCnMQPhecHA0UX1i7/qiK8wF T0+XwRZdCgfRbAyGGcB5G2Kh/XZuHk2FJTmy5wPQAvqgaC04CNNYV4RZ88Ocn8pnh61d lAAw== X-Gm-Message-State: AOPr4FXiHE7faQwjuxcb8IPDBiJP6ZZ501iPp/bDn67MWVoSkVRgslKyuo6KJ3CtK1udx56o479NB/7ypMNRBA== MIME-Version: 1.0 X-Received: by 10.194.134.170 with SMTP id pl10mr3264125wjb.88.1461074680441; Tue, 19 Apr 2016 07:04:40 -0700 (PDT) Received: by 10.194.113.102 with HTTP; Tue, 19 Apr 2016 07:04:40 -0700 (PDT) In-Reply-To: References: Date: Tue, 19 Apr 2016 14:05:00 -0000 Message-ID: Subject: Re: [PATCH][GCC 7] Fix PR70171 From: Richard Biener To: GCC Patches Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2016-04/txt/msg00939.txt.bz2 On Fri, Mar 11, 2016 at 3:01 PM, Richard Biener wrote: > > The following teaches phiprop to handle the case of aggregate copies > where the aggregate has non-BLKmode which means it is very likely > expanded as reg-reg moves (any better test for that apart from > checking for non-BLKmode?). This improves code for the testcase > from > > _Z14struct_ternary1SS_b: > .LFB2: > .cfi_startproc > leaq -40(%rsp), %rcx > leaq -24(%rsp), %rax > testb %dl, %dl > movl %edi, -24(%rsp) > movl %esi, -40(%rsp) > cmove %rcx, %rax > movl (%rax), %eax > ret > > to > > _Z14struct_ternary1SS_b: > .LFB2: > .cfi_startproc > testb %dl, %dl > movl %edi, %eax > cmove %esi, %eax > ret > > Bootstrapped and tested on x86_64-unknown-linux-gnu, queued for stage1. Re-bootstrapped and tested on x86_64-unknown-linux-gnu, applied as r235208. Richard. > Richard. > > 2016-03-11 Richard Biener > > PR tree-optimization/70171 > * tree-ssa-phiprop.c: Include stor-layout.h. > (phiprop_insert_phi): Handle the aggregate copy case. > (propagate_with_phi): Likewise. > > * g++.dg/tree-ssa/pr70171.C: New testcase. > > Index: gcc/tree-ssa-phiprop.c > =================================================================== > *** gcc/tree-ssa-phiprop.c (revision 234134) > --- gcc/tree-ssa-phiprop.c (working copy) > *************** along with GCC; see the file COPYING3. > *** 31,36 **** > --- 31,37 ---- > #include "tree-eh.h" > #include "gimplify.h" > #include "gimple-iterator.h" > + #include "stor-layout.h" > > /* This pass propagates indirect loads through the PHI node for its > address to make the load source possibly non-addressable and to > *************** phiprop_insert_phi (basic_block bb, gphi > *** 132,138 **** > struct phiprop_d *phivn, size_t n) > { > tree res; > ! gphi *new_phi; > edge_iterator ei; > edge e; > > --- 133,139 ---- > struct phiprop_d *phivn, size_t n) > { > tree res; > ! gphi *new_phi = NULL; > edge_iterator ei; > edge e; > > *************** phiprop_insert_phi (basic_block bb, gphi > *** 142,148 **** > /* Build a new PHI node to replace the definition of > the indirect reference lhs. */ > res = gimple_assign_lhs (use_stmt); > ! new_phi = create_phi_node (res, bb); > > if (dump_file && (dump_flags & TDF_DETAILS)) > { > --- 143,150 ---- > /* Build a new PHI node to replace the definition of > the indirect reference lhs. */ > res = gimple_assign_lhs (use_stmt); > ! if (TREE_CODE (res) == SSA_NAME) > ! new_phi = create_phi_node (res, bb); > > if (dump_file && (dump_flags & TDF_DETAILS)) > { > *************** phiprop_insert_phi (basic_block bb, gphi > *** 187,193 **** > { > tree rhs = gimple_assign_rhs1 (use_stmt); > gcc_assert (TREE_CODE (old_arg) == ADDR_EXPR); > ! new_var = make_ssa_name (TREE_TYPE (rhs)); > if (!is_gimple_min_invariant (old_arg)) > old_arg = PHI_ARG_DEF_FROM_EDGE (phi, e); > else > --- 189,198 ---- > { > tree rhs = gimple_assign_rhs1 (use_stmt); > gcc_assert (TREE_CODE (old_arg) == ADDR_EXPR); > ! if (TREE_CODE (res) == SSA_NAME) > ! new_var = make_ssa_name (TREE_TYPE (rhs)); > ! else > ! new_var = unshare_expr (res); > if (!is_gimple_min_invariant (old_arg)) > old_arg = PHI_ARG_DEF_FROM_EDGE (phi, e); > else > *************** phiprop_insert_phi (basic_block bb, gphi > *** 210,222 **** > } > } > > ! add_phi_arg (new_phi, new_var, e, locus); > } > > ! update_stmt (new_phi); > > ! if (dump_file && (dump_flags & TDF_DETAILS)) > ! print_gimple_stmt (dump_file, new_phi, 0, 0); > > return res; > } > --- 215,231 ---- > } > } > > ! if (new_phi) > ! add_phi_arg (new_phi, new_var, e, locus); > } > > ! if (new_phi) > ! { > ! update_stmt (new_phi); > > ! if (dump_file && (dump_flags & TDF_DETAILS)) > ! print_gimple_stmt (dump_file, new_phi, 0, 0); > ! } > > return res; > } > *************** propagate_with_phi (basic_block bb, gphi > *** 250,256 **** > tree type = NULL_TREE; > > if (!POINTER_TYPE_P (TREE_TYPE (ptr)) > ! || !is_gimple_reg_type (TREE_TYPE (TREE_TYPE (ptr)))) > return false; > > /* Check if we can "cheaply" dereference all phi arguments. */ > --- 259,266 ---- > tree type = NULL_TREE; > > if (!POINTER_TYPE_P (TREE_TYPE (ptr)) > ! || (!is_gimple_reg_type (TREE_TYPE (TREE_TYPE (ptr))) > ! && TYPE_MODE (TREE_TYPE (TREE_TYPE (ptr))) == BLKmode)) > return false; > > /* Check if we can "cheaply" dereference all phi arguments. */ > *************** propagate_with_phi (basic_block bb, gphi > *** 306,312 **** > > /* Check whether this is a load of *ptr. */ > if (!(is_gimple_assign (use_stmt) > - && TREE_CODE (gimple_assign_lhs (use_stmt)) == SSA_NAME > && gimple_assign_rhs_code (use_stmt) == MEM_REF > && TREE_OPERAND (gimple_assign_rhs1 (use_stmt), 0) == ptr > && integer_zerop (TREE_OPERAND (gimple_assign_rhs1 (use_stmt), 1)) > --- 316,321 ---- > *************** propagate_with_phi (basic_block bb, gphi > *** 327,335 **** > bb, gimple_bb (def_stmt)))) > goto next; > > /* Found a proper dereference. Insert a phi node if this > is the first load transformation. */ > ! if (!phi_inserted) > { > res = phiprop_insert_phi (bb, phi, use_stmt, phivn, n); > type = TREE_TYPE (res); > --- 336,366 ---- > bb, gimple_bb (def_stmt)))) > goto next; > > + /* Found a proper dereference with an aggregate copy. Just > + insert aggregate copies on the edges instead. */ > + if (!is_gimple_reg_type (TREE_TYPE (TREE_TYPE (ptr)))) > + { > + phiprop_insert_phi (bb, phi, use_stmt, phivn, n); > + > + /* Remove old stmt. The phi is taken care of by DCE. */ > + gsi = gsi_for_stmt (use_stmt); > + /* Unlinking the VDEF here is fine as we are sure that we process > + stmts in execution order due to aggregate copies having VDEFs > + and we emit loads on the edges in the very same order. > + We get multiple copies (or intermediate register loads) handled > + only by walking PHIs or immediate uses in a lucky order though, > + so we could signal the caller to re-start iterating over PHIs > + when we come here which would make it quadratic in the number > + of PHIs. */ > + unlink_stmt_vdef (use_stmt); > + gsi_remove (&gsi, true); > + > + phi_inserted = true; > + } > + > /* Found a proper dereference. Insert a phi node if this > is the first load transformation. */ > ! else if (!phi_inserted) > { > res = phiprop_insert_phi (bb, phi, use_stmt, phivn, n); > type = TREE_TYPE (res); > Index: gcc/testsuite/g++.dg/tree-ssa/pr70171.C > =================================================================== > *** gcc/testsuite/g++.dg/tree-ssa/pr70171.C (revision 0) > --- gcc/testsuite/g++.dg/tree-ssa/pr70171.C (working copy) > *************** > *** 0 **** > --- 1,8 ---- > + /* { dg-do compile } */ > + /* { dg-options "-O2 -fdump-tree-optimized" } */ > + > + struct S { int i; }; > + S struct_ternary (S a, S b, bool select) { return select ? a : b; } > + > + /* { dg-final { scan-tree-dump-not "&\[ab\]" "optimized" } } */ > + /* { dg-final { scan-assembler-not "\[er\]sp" { target { { i?86-*-* x86_64-*-* } && { ! ia32 } } } } } */