From patchwork Tue Sep 11 15:15:56 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Glisse X-Patchwork-Id: 183136 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id C84E62C0080 for ; Wed, 12 Sep 2012 01:16:32 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1347981393; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=zQBpn9WfYPq4iAOQ0aeHrTQgyvQ=; b=ZaNIg8/8VpM9+jb VDWr2EYSPsb/2hypyxX/lL5+0jp+Xa/lCChTnxPGlpsifLhwRfR0biF/+dm1ZXZx voP1Jlqojf/e5c+yypqPRIH7jum3Xq0NrLQ5SPhM53eotArH41gh2aYAiQ0eRl3S EBRXcutBTIatQb9VX3qCHeQHET1c= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Date:From:To:cc:Subject:In-Reply-To:Message-ID:References:User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=R4A15QvgQBQoO+Xzzid2oBk/h40CwKafGFrGj+upymWWWilKakVKPCOEzdXasL olGEJeehMG9iGK3XxPS+HAHhRiQEqYLFezM7P9EuQQzJ251Du2SGchvNg23NuXNI GIxra0POEZS+TixhKDHuX82lHGgFrctPr2svbUgjXVp1g=; Received: (qmail 27202 invoked by alias); 11 Sep 2012 15:16:24 -0000 Received: (qmail 27045 invoked by uid 22791); 11 Sep 2012 15:16:21 -0000 X-SWARE-Spam-Status: No, hits=-7.6 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_THREADED, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, TW_CF, TW_TM X-Spam-Check-By: sourceware.org Received: from mail4-relais-sop.national.inria.fr (HELO mail4-relais-sop.national.inria.fr) (192.134.164.105) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 11 Sep 2012 15:15:58 +0000 Received: from stedding.saclay.inria.fr ([193.55.250.194]) by mail4-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 11 Sep 2012 17:15:57 +0200 Received: from glisse (helo=localhost) by stedding.saclay.inria.fr with local-esmtp (Exim 4.80) (envelope-from ) id 1TBSBw-00040E-Rc; Tue, 11 Sep 2012 17:15:56 +0200 Date: Tue, 11 Sep 2012 17:15:56 +0200 (CEST) From: Marc Glisse To: Richard Guenther cc: gcc-patches@gcc.gnu.org Subject: Re: Recognize vec_perm_expr in a constructor of bit_field_ref In-Reply-To: Message-ID: References: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org On Tue, 11 Sep 2012, Richard Guenther wrote: > On Tue, Sep 11, 2012 at 1:07 PM, Marc Glisse wrote: >> Hello, >> >> here is a patch that turns {v[1],v[0]} into vec_perm_expr(v,v,{1,0}) if the >> target is ok with it. >> >> I am attaching 2 versions of the patch. p-good is the one that passes >> testing. p-bad, where I rely on fold_stmt to detect identity permutations, >> ICEs towards the end of the pass while checking a bogus gimple stmt (one >> that gimple_debug_stmt crashes on if I call it in gdb). From a performance >> point of view, p-good makes sense, but I liked the simplicity of p-bad and I >> am confused as to why it fails. > > Probably because you cannot simply increase num_ops ... > >> 2012-09-11 Marc Glisse >> >> gcc/ >> * tree-ssa-forwprop.c (simplify_vector_constructor): New function. >> (ssa_forward_propagate_and_combine): Call it. >> >> gcc/testsuite/ >> * gcc.dg/tree-ssa/forwprop-22.c: New testcase. [...] > Ok with that change. Attached is what I am testing and will commit if it passes. Index: gcc/tree-ssa-forwprop.c =================================================================== --- gcc/tree-ssa-forwprop.c (revision 191187) +++ gcc/tree-ssa-forwprop.c (working copy) @@ -26,20 +26,21 @@ along with GCC; see the file COPYING3. #include "tm_p.h" #include "basic-block.h" #include "gimple-pretty-print.h" #include "tree-flow.h" #include "tree-pass.h" #include "langhooks.h" #include "flags.h" #include "gimple.h" #include "expr.h" #include "cfgloop.h" +#include "tree-vectorizer.h" /* This pass propagates the RHS of assignment statements into use sites of the LHS of the assignment. It's basically a specialized form of tree combination. It is hoped all of this can disappear when we have a generalized tree combiner. One class of common cases we handle is forward propagating a single use variable into a COND_EXPR. bb0: @@ -2787,20 +2788,98 @@ simplify_permutation (gimple_stmt_iterat if (TREE_CODE (op0) == SSA_NAME) ret = remove_prop_source_from_use (op0); if (op0 != op1 && TREE_CODE (op1) == SSA_NAME) ret |= remove_prop_source_from_use (op1); return ret ? 2 : 1; } return 0; } +/* Recognize a VEC_PERM_EXPR. Returns true if there were any changes. */ + +static bool +simplify_vector_constructor (gimple_stmt_iterator *gsi) +{ + gimple stmt = gsi_stmt (*gsi); + gimple def_stmt; + tree op, op2, orig, type, elem_type; + unsigned elem_size, nelts, i; + enum tree_code code; + constructor_elt *elt; + unsigned char *sel; + bool maybe_ident; + + gcc_checking_assert (gimple_assign_rhs_code (stmt) == CONSTRUCTOR); + + op = gimple_assign_rhs1 (stmt); + type = TREE_TYPE (op); + gcc_checking_assert (TREE_CODE (type) == VECTOR_TYPE); + + nelts = TYPE_VECTOR_SUBPARTS (type); + elem_type = TREE_TYPE (type); + elem_size = TREE_INT_CST_LOW (TYPE_SIZE (elem_type)); + + sel = XALLOCAVEC (unsigned char, nelts); + orig = NULL; + maybe_ident = true; + FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (op), i, elt) + { + tree ref, op1; + + if (i >= nelts) + return false; + + if (TREE_CODE (elt->value) != SSA_NAME) + return false; + def_stmt = SSA_NAME_DEF_STMT (elt->value); + if (!def_stmt || !is_gimple_assign (def_stmt)) + return false; + code = gimple_assign_rhs_code (def_stmt); + if (code != BIT_FIELD_REF) + return false; + op1 = gimple_assign_rhs1 (def_stmt); + ref = TREE_OPERAND (op1, 0); + if (orig) + { + if (ref != orig) + return false; + } + else + { + if (TREE_CODE (ref) != SSA_NAME) + return false; + orig = ref; + } + if (TREE_INT_CST_LOW (TREE_OPERAND (op1, 1)) != elem_size) + return false; + sel[i] = TREE_INT_CST_LOW (TREE_OPERAND (op1, 2)) / elem_size; + if (sel[i] != i) maybe_ident = false; + } + if (i < nelts) + return false; + + if (maybe_ident) + { + gimple_assign_set_rhs_from_tree (gsi, orig); + } + else + { + op2 = vect_gen_perm_mask (type, sel); + if (!op2) + return false; + gimple_assign_set_rhs_with_ops_1 (gsi, VEC_PERM_EXPR, orig, orig, op2); + } + update_stmt (gsi_stmt (*gsi)); + return true; +} + /* Main entry point for the forward propagation and statement combine optimizer. */ static unsigned int ssa_forward_propagate_and_combine (void) { basic_block bb; unsigned int todoflags = 0; cfg_changed = false; @@ -2958,20 +3037,23 @@ ssa_forward_propagate_and_combine (void) } else if (code == VEC_PERM_EXPR) { int did_something = simplify_permutation (&gsi); if (did_something == 2) cfg_changed = true; changed = did_something != 0; } else if (code == BIT_FIELD_REF) changed = simplify_bitfield_ref (&gsi); + else if (code == CONSTRUCTOR + && TREE_CODE (TREE_TYPE (rhs1)) == VECTOR_TYPE) + changed = simplify_vector_constructor (&gsi); break; } case GIMPLE_SWITCH: changed = simplify_gimple_switch (stmt); break; case GIMPLE_COND: { int did_something; Index: gcc/testsuite/gcc.dg/tree-ssa/forwprop-22.c =================================================================== --- gcc/testsuite/gcc.dg/tree-ssa/forwprop-22.c (revision 0) +++ gcc/testsuite/gcc.dg/tree-ssa/forwprop-22.c (revision 0) @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target vect_double } */ +/* { dg-require-effective-target vect_perm } */ +/* { dg-options "-O -fdump-tree-optimized" } */ + +typedef double vec __attribute__((vector_size (2 * sizeof (double)))); +void f (vec *px, vec *y, vec *z) +{ + vec x = *px; + vec t1 = { x[1], x[0] }; + vec t2 = { x[0], x[1] }; + *y = t1; + *z = t2; +} + +/* { dg-final { scan-tree-dump-times "VEC_PERM_EXPR" 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-not "BIT_FIELD_REF" "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ Property changes on: gcc/testsuite/gcc.dg/tree-ssa/forwprop-22.c ___________________________________________________________________ Added: svn:eol-style + native Added: svn:keywords + Author Date Id Revision URL Index: gcc/Makefile.in =================================================================== --- gcc/Makefile.in (revision 191187) +++ gcc/Makefile.in (working copy) @@ -2237,21 +2237,22 @@ tree-outof-ssa.o : tree-outof-ssa.c $(TR $(TREE_H) $(DIAGNOSTIC_H) $(TM_H) coretypes.h dumpfile.h \ $(TREE_SSA_LIVE_H) $(BASIC_BLOCK_H) $(BITMAP_H) $(GGC_H) \ $(EXPR_H) $(SSAEXPAND_H) $(GIMPLE_PRETTY_PRINT_H) tree-ssa-dse.o : tree-ssa-dse.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \ $(TM_H) $(GGC_H) $(TREE_H) $(TM_P_H) $(BASIC_BLOCK_H) \ $(TREE_FLOW_H) $(TREE_PASS_H) domwalk.h $(FLAGS_H) \ $(GIMPLE_PRETTY_PRINT_H) langhooks.h tree-ssa-forwprop.o : tree-ssa-forwprop.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \ $(TM_H) $(TREE_H) $(TM_P_H) $(BASIC_BLOCK_H) $(CFGLOOP_H) \ $(TREE_FLOW_H) $(TREE_PASS_H) $(DIAGNOSTIC_H) \ - langhooks.h $(FLAGS_H) $(GIMPLE_H) $(GIMPLE_PRETTY_PRINT_H) $(EXPR_H) + langhooks.h $(FLAGS_H) $(GIMPLE_H) $(GIMPLE_PRETTY_PRINT_H) $(EXPR_H) \ + $(TREE_VECTORIZER_H) tree-ssa-phiprop.o : tree-ssa-phiprop.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \ $(TM_H) $(TREE_H) $(TM_P_H) $(BASIC_BLOCK_H) \ $(TREE_FLOW_H) $(TREE_PASS_H) $(DIAGNOSTIC_H) \ langhooks.h $(FLAGS_H) $(GIMPLE_PRETTY_PRINT_H) tree-ssa-ifcombine.o : tree-ssa-ifcombine.c $(CONFIG_H) $(SYSTEM_H) \ coretypes.h $(TM_H) $(TREE_H) $(BASIC_BLOCK_H) \ $(TREE_FLOW_H) $(TREE_PASS_H) $(DIAGNOSTIC_H) \ $(TREE_PRETTY_PRINT_H) tree-ssa-phiopt.o : tree-ssa-phiopt.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \ $(TM_H) $(GGC_H) $(TREE_H) $(TM_P_H) $(BASIC_BLOCK_H) \