From patchwork Thu Sep 18 12:42:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Lawrence X-Patchwork-Id: 390800 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 07512140077 for ; Thu, 18 Sep 2014 22:43:13 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=DcoGQb6Yt11DZmR/r 8He1zLaMDyDdTZ9gujf/QYckjY9S2f2oSHe2ylxCItsDqnuE47IKiWdcmAsR14Jl gnZJFx3pFf9tT1rpesQ8MOPn5X8AuBxPJ9k+bBRH3E6t4mFHKWR+8fFxOONCbOBO xCCoorM4o7ib2YekkhUu4pleVE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=lX86UCyKIsLByoLXRwUZtTk wZ04=; b=b1NKByH50X/Cat3eMr9No3QgIQlyLt5pCr5EVybvGxR1gwMm4cutki4 GoaC+A02RIuSdTMbK9lftaNBufuOVhOnZyBwPTV56Vex9uHoCDVPDXpY0bHYdEBo tmQRjdSmMC58dMrIyV0dNBFTzNlE4VM52w+7kI90o55N3l4BJRtA= Received: (qmail 4362 invoked by alias); 18 Sep 2014 12:43:06 -0000 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 Received: (qmail 4352 invoked by uid 89); 18 Sep 2014 12:43:06 -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, SPF_PASS autolearn=ham version=3.3.2 X-HELO: service87.mimecast.com Received: from service87.mimecast.com (HELO service87.mimecast.com) (91.220.42.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 18 Sep 2014 12:43:04 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Thu, 18 Sep 2014 13:43:01 +0100 Received: from [10.1.209.51] ([10.1.255.212]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 18 Sep 2014 13:43:00 +0100 Message-ID: <541AD353.6020405@arm.com> Date: Thu, 18 Sep 2014 13:42:59 +0100 From: Alan Lawrence User-Agent: Thunderbird 2.0.0.24 (X11/20101213) MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: David Edelsohn , Aldy Hernandez , Steve Ellcey , Eric Christopher Subject: [PATCH 12/14][Vectorizer] Redefine VEC_RSHIFT_EXPR and vec_shr_optab as endianness-neutral References: <541AC4D2.9040901@arm.com> In-Reply-To: <541AC4D2.9040901@arm.com> X-MC-Unique: 114091813430112601 X-IsSubscribed: yes The direction of VEC_RSHIFT_EXPR has been endian-dependent, contrary to the general principles of tree. This patch updates fold-const and the vectorizer (the only place where such expressions are created), such that VEC_RSHIFT_EXPR always shifts towards element 0. The tree code still maps directly onto the vec_shr_optab, and so this patch *will break any bigendian platform defining the vec_shr optab*. --> For AArch64_be, patch follows next in series; --> For PowerPC, I think patch/rfc 15 should fix, please inspect; --> For MIPS, I think patch/rfc 16 should fix, please inspect. gcc/ChangeLog: * fold-const.c (const_binop): VEC_RSHIFT_EXPR always shifts towards element 0. * tree-vect-loop.c (vect_create_epilog_for_reduction): always extract the result of a reduction with vector shifts from element 0. * tree.def (VEC_RSHIFT_EXPR, VEC_LSHIFT_EXPR): Comment shift direction. * doc/md.texi (vec_shr_m, vec_shl_m): Document shift direction. Testing Done: Bootstrap and check-gcc on x86_64-none-linux-gnu; check-gcc on aarch64-none-elf. diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi index f94e0f62c622d43e2df0d0619fb1eba74c415165..a2e8f297fbdd69dfec23e6e0769a21917b06b5c7 100644 --- a/gcc/doc/md.texi +++ b/gcc/doc/md.texi @@ -4885,7 +4885,7 @@ of a wider mode.) @cindex @code{vec_shr_@var{m}} instruction pattern @item @samp{vec_shr_@var{m}} -Whole vector right shift in bits. +Whole vector right shift in bits, i.e. towards element 0. Operand 1 is a vector to be shifted. Operand 2 is an integer shift amount in bits, which must be a multiple of the element size. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index bd4ba5f0c64c710df9fa36d4059f7b08e949fae0..2a4fafa1b0634edd7a56f2484dec3a51a4699222 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -1418,15 +1418,10 @@ const_binop (enum tree_code code, tree arg1, tree arg2) if (shiftc >= outerc || (shiftc % innerc) != 0) return NULL_TREE; int offset = shiftc / innerc; - /* The direction of VEC_RSHIFT_EXPR is endian dependent. - For reductions, if !BYTES_BIG_ENDIAN then compiler picks first - vector element, but last element if BYTES_BIG_ENDIAN. */ - if (BYTES_BIG_ENDIAN) - offset = -offset; tree zero = build_zero_cst (TREE_TYPE (type)); for (i = 0; i < count; i++) { - if (i + offset < 0 || i + offset >= count) + if (i + offset >= count) elts[i] = zero; else elts[i] = VECTOR_CST_ELT (arg1, i + offset); diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c index d0a29d312bfd9a7eb552d937e3c64cf9b30d558a..016e2c1fc839fc4d1c97caaa38064fb8bbb510d8 100644 --- a/gcc/tree-vect-loop.c +++ b/gcc/tree-vect-loop.c @@ -3860,7 +3860,7 @@ vect_create_epilog_for_reduction (vec vect_defs, gimple stmt, gimple epilog_stmt = NULL; enum tree_code code = gimple_assign_rhs_code (stmt); gimple exit_phi; - tree bitsize, bitpos; + tree bitsize; tree adjustment_def = NULL; tree vec_initial_def = NULL; tree reduction_op, expr, def; @@ -4371,14 +4371,8 @@ vect_create_epilog_for_reduction (vec vect_defs, gimple stmt, dump_printf_loc (MSG_NOTE, vect_location, "extract scalar result\n"); - if (BYTES_BIG_ENDIAN) - bitpos = size_binop (MULT_EXPR, - bitsize_int (TYPE_VECTOR_SUBPARTS (vectype) - 1), - TYPE_SIZE (scalar_type)); - else - bitpos = bitsize_zero_node; - - rhs = build3 (BIT_FIELD_REF, scalar_type, new_temp, bitsize, bitpos); + rhs = build3 (BIT_FIELD_REF, scalar_type, + new_temp, bitsize, bitsize_zero_node); epilog_stmt = gimple_build_assign (new_scalar_dest, rhs); new_temp = make_ssa_name (new_scalar_dest, epilog_stmt); gimple_assign_set_lhs (epilog_stmt, new_temp); diff --git a/gcc/tree.def b/gcc/tree.def index ff56bfc18bc00e8dac2dfc072fd4fa878a0f2a04..90bc27fde303e1606baac858738a7a86a517573b 100644 --- a/gcc/tree.def +++ b/gcc/tree.def @@ -1238,7 +1238,7 @@ DEFTREECODE (WIDEN_LSHIFT_EXPR, "widen_lshift_expr", tcc_binary, 2) before adding operand three. */ DEFTREECODE (FMA_EXPR, "fma_expr", tcc_expression, 3) -/* Whole vector right shift in bits. +/* Whole vector right shift in bits, i.e. towards element 0. Operand 0 is a vector to be shifted. Operand 1 is an integer shift amount in bits, which must be a multiple of the element size. */