From patchwork Fri Mar 16 12:44:37 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 147200 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 F134DB6FAB for ; Fri, 16 Mar 2012 23:44:59 +1100 (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=1332506700; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Date: From:To:Subject:Message-ID:User-Agent:MIME-Version:Content-Type: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=I/f1D/bBrjP28AuUZsC8 i0oUlFE=; b=RgBACmXMTGh/1+KXolsLPHs+SlRyGzjdpARq6RVgEFqgNUmbeE1J wxxjk+xT7bvC/vgpSwYgWbg7N9fXX4rPsJIN+nRS9flRQOE1f37d4l8yhJQU78qv hkkmRVjN6C/3Xja3vDk6ecCQrPQZuiZc7DSNW8d3zwiGCC4L+bjzS50= 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:Subject:Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=uZ2jSiW/LSNE9e5H1Uvo8HZg2srVWoMcdY38OGqvJ0d3yqdSM3M28uLHC9oI3x vHo1UYgHtmczC110+iBrjQ0xWRV0LPbS5l77/0doxRohXx1W/XEzoJl56heQQ3Y2 QbUTOr80D7OsWXZyoqPagFsLxfHc9pBJ4EzuGbJPtiVSo=; Received: (qmail 18245 invoked by alias); 16 Mar 2012 12:44:54 -0000 Received: (qmail 18235 invoked by uid 22791); 16 Mar 2012 12:44:52 -0000 X-SWARE-Spam-Status: No, hits=-5.8 required=5.0 tests=AWL, BAYES_00, 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; Fri, 16 Mar 2012 12:44:39 +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 A34258BB22 for ; Fri, 16 Mar 2012 13:44:37 +0100 (CET) Date: Fri, 16 Mar 2012 13:44:37 +0100 (CET) From: Richard Guenther To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR52584, fold sub-vector selects with BIT_FIELD_REF Message-ID: User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) 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 At least generic vector lowering can end up using BIT_FIELD_REF to generate sub-vector selects such as low/high part of vector constants/constructors. We do not fold these currently, leading to quite absymal code. Thus the following patch which teaches fold to do this. Bootstrap and regtest pending on x86_64-unknown-linux-gnu. Richard. 2012-03-16 Richard Guenther PR middle-end/52584 * fold-const.c (fold_ternary_loc): Fold vector typed BIT_FIELD_REFs of vector constants and constructors. Index: gcc/fold-const.c =================================================================== --- gcc/fold-const.c (revision 185465) +++ gcc/fold-const.c (working copy) @@ -13920,22 +13946,55 @@ fold_ternary_loc (location_t loc, enum t case BIT_FIELD_REF: if ((TREE_CODE (arg0) == VECTOR_CST || TREE_CODE (arg0) == CONSTRUCTOR) - && type == TREE_TYPE (TREE_TYPE (arg0))) - { - unsigned HOST_WIDE_INT width = tree_low_cst (arg1, 1); + && (type == TREE_TYPE (TREE_TYPE (arg0)))) + || (TREE_CODE (type) == VECTOR_TYPE + && TREE_TYPE (type) == TREE_TYPE (TREE_TYPE (arg0))))) + { + tree eltype = TREE_TYPE (TREE_TYPE (arg0)); + unsigned HOST_WIDE_INT width = tree_low_cst (TYPE_SIZE (eltype), 1); + unsigned HOST_WIDE_INT n = tree_low_cst (arg1, 1); unsigned HOST_WIDE_INT idx = tree_low_cst (op2, 1); - if (width != 0 - && simple_cst_equal (arg1, TYPE_SIZE (type)) == 1 + if (n != 0 && (idx % width) == 0 - && (idx = idx / width) - < TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0))) + && (n % width) == 0 + && ((idx + n) / width) <= TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0))) { - if (TREE_CODE (arg0) == VECTOR_CST) - return VECTOR_CST_ELT (arg0, idx); - else if (idx < CONSTRUCTOR_NELTS (arg0)) - return CONSTRUCTOR_ELT (arg0, idx)->value; - return build_zero_cst (type); + idx = idx / width; + n = n / width; + if (TREE_CODE (type) == VECTOR_TYPE) + { + if (TREE_CODE (arg0) == VECTOR_CST) + { + tree *vals = XALLOCAVEC (tree, n); + unsigned i; + for (i = 0; i < n; ++i) + vals[i] = VECTOR_CST_ELT (arg0, idx + i); + return build_vector (type, vals); + } + else + { + VEC(constructor_elt, gc) *vals; + unsigned i; + if (CONSTRUCTOR_NELTS (arg0) == 0) + return build_constructor (type, NULL); + vals = VEC_alloc (constructor_elt, gc, n); + for (i = 0; i < n && idx + i < CONSTRUCTOR_NELTS (arg0); + ++i) + CONSTRUCTOR_APPEND_ELT (vals, NULL_TREE, + CONSTRUCTOR_ELT + (arg0, idx + i)->value); + return build_constructor (type, vals); + } + } + else if (n == 1) + { + if (TREE_CODE (arg0) == VECTOR_CST) + return VECTOR_CST_ELT (arg0, idx); + else if (idx < CONSTRUCTOR_NELTS (arg0)) + return CONSTRUCTOR_ELT (arg0, idx)->value; + return build_zero_cst (type); + } } }