From patchwork Wed Jun 13 11:46:37 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Matz X-Patchwork-Id: 164638 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 C21421007D1 for ; Wed, 13 Jun 2012 21:47:00 +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=1340192821; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Date: From:To:Cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=rhsm0PWxblEN8gyAK/m9gpnIjRw=; b=PI8y6DJI6iN/jO5 t7YA+yWNw7R7YsamNO8fv9j7fgNsfFhqzkC4z1Dx5dfYXP2Zs2QTgi9ym4OFzlPo Vkr5I9F1mCtIygXQvjDKpv1b79IdTDuLC4xwbBadwNofyz9uQUCu9SV0lEk70JO9 HZWVU9cbi+4G4UY5gfOsNFdbVJnU= 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:Date:From:To:Cc:Subject:In-Reply-To:Message-ID:References:MIME-Version:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=si5Bc5fKDEsH0HNS5inyYuV8DLP0uQm/HU/YYO8lAtLG3DZ0ylkbtOmZQXweCX Dr8ycJC6NiyjQeocLVqZyzaD+40NhuZ/jRwOzpAbmgDueuaeO6yRQvrU5Z/0YHuu tObIdF3tAYhvKgWfipSONdVHC4kcDRMVqml4y/pUqrbe8=; Received: (qmail 2046 invoked by alias); 13 Jun 2012 11:46:53 -0000 Received: (qmail 2037 invoked by uid 22791); 13 Jun 2012 11:46:52 -0000 X-SWARE-Spam-Status: No, hits=-5.9 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_THREADED, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 13 Jun 2012 11:46:38 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 73A758FE69; Wed, 13 Jun 2012 13:46:37 +0200 (CEST) Date: Wed, 13 Jun 2012 13:46:37 +0200 (CEST) From: Michael Matz To: gcc-patches@gcc.gnu.org Cc: Richard Guenther Subject: RFA: better gimplification of compound literals In-Reply-To: Message-ID: References: <20120612102238.1960075f@octopus> MIME-Version: 1.0 X-IsSubscribed: yes 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 Hi, On Tue, 12 Jun 2012, Richard Guenther wrote: > > Ok, I see the C frontend hands us this as > > > >  return  VEC_PERM_EXPR < a , b , <<< Unknown tree: compound_literal_expr > >    v4si D.1712 = { 0, 4, 1, 5 }; >>> > ; > > > > and gimplification in some way fails to gimplify it to { 0, 4, 1, 5 }. Was a non-implemented optimization. If the compound literal value isn't used as lvalue and doesn't have its address taken (and generally fits the current predicate) we can as well subst it in place instead of going over an intermediate statement. Regstrapping on x86_64-linux in progress. Okay if that passes? Ciao, Michael. --------------------- * gimplify.c (gimplify_compound_literal_expr): Take gimple_test_f argument, don't emit assign statement if value is directly usable. (gimplify_expr): Adjust. testsuite/ * gcc.dg/tree-ssa/vector-4.c: New test. Index: gimplify.c =================================================================== --- gimplify.c (revision 188500) +++ gimplify.c (working copy) @@ -3796,15 +3796,29 @@ rhs_predicate_for (tree lhs) static enum gimplify_status gimplify_compound_literal_expr (tree *expr_p, gimple_seq *pre_p, + bool (*gimple_test_f) (tree), fallback_t fallback) { tree decl_s = COMPOUND_LITERAL_EXPR_DECL_EXPR (*expr_p); tree decl = DECL_EXPR_DECL (decl_s); + tree init = DECL_INITIAL (decl); /* Mark the decl as addressable if the compound literal expression is addressable now, otherwise it is marked too late after we gimplify the initialization expression. */ if (TREE_ADDRESSABLE (*expr_p)) TREE_ADDRESSABLE (decl) = 1; + /* Otherwise, if we don't need an lvalue and have a literal directly + substitute it. Check if it matches the gimple predicate, as + otherwise we'd generate a new temporary, and we can as well just + use the decl we already have. */ + else if (!TREE_ADDRESSABLE (decl) + && init + && (fallback & fb_lvalue) == 0 + && gimple_test_f (init)) + { + *expr_p = init; + return GS_OK; + } /* Preliminarily mark non-addressed complex variables as eligible for promotion to gimple registers. We'll transform their uses @@ -7118,7 +7132,8 @@ gimplify_expr (tree *expr_p, gimple_seq break; case COMPOUND_LITERAL_EXPR: - ret = gimplify_compound_literal_expr (expr_p, pre_p, fallback); + ret = gimplify_compound_literal_expr (expr_p, pre_p, + gimple_test_f, fallback); break; case MODIFY_EXPR: Index: testsuite/gcc.dg/tree-ssa/vector-4.c =================================================================== --- testsuite/gcc.dg/tree-ssa/vector-4.c (revision 0) +++ testsuite/gcc.dg/tree-ssa/vector-4.c (revision 0) @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-w -O1 -fdump-tree-gimple" } */ + +typedef int v4si __attribute__ ((vector_size (16))); + +v4si vs (v4si a, v4si b) +{ + return __builtin_shuffle (a, b, (v4si) {0, 4, 1, 5}); +} + +/* The compound literal should be placed directly in the vec_perm. */ +/* { dg-final { scan-tree-dump-times "VEC_PERM_EXPR ;" 1 "gimple"} } */ + +/* { dg-final { cleanup-tree-dump "gimple" } } */