From patchwork Tue Aug 7 19:25:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: will schmidt X-Patchwork-Id: 954645 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-483345-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=vnet.ibm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="u05p5x75"; dkim-atps=neutral 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 41lPcl3VdCz9s4V for ; Wed, 8 Aug 2018 05:25:43 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:from:reply-to:to:cc:content-type:date:mime-version :content-transfer-encoding:message-id; q=dns; s=default; b=FKw0w AyGhmMRxsud9RuVkmSH6XbARXXOnmc/wbYWth49seImtfvpBXv4E307pKYnoHBlJ duUyK2wo+U5ktU+zXl9quwROvque+DOskkDklOKD5vtTItxbiuSJb1QgOUe2ptZj HhyQA1+t497y1M4SyRcIvOtlKfGurleUpL+upw= 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 :subject:from:reply-to:to:cc:content-type:date:mime-version :content-transfer-encoding:message-id; s=default; bh=g9y2+7HbBw+ AEec07KXnHOQsx7k=; b=u05p5x75HBaRUNKYzPMcm0i5A5g1jSHwFeFKxyiXaNq LI/XGgemQiLD58tXRGL2JAAhOHHCfEaoqX1GwZFzR/Qmh9u+jN0i213XlP+zeHo/ dOmD8zQ7+/xE5VLvV+zFroAbnf1gn3Teej4XFPO3afQ3Jb+GTYFuSPWlngxFzQWg = Received: (qmail 127115 invoked by alias); 7 Aug 2018 19:25:36 -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 127101 invoked by uid 89); 7 Aug 2018 19:25:35 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-27.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0a-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.156.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 07 Aug 2018 19:25:34 +0000 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w77JNiJi048412 for ; Tue, 7 Aug 2018 15:25:32 -0400 Received: from e31.co.us.ibm.com (e31.co.us.ibm.com [32.97.110.149]) by mx0a-001b2d01.pphosted.com with ESMTP id 2kqdtthkhf-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 07 Aug 2018 15:25:32 -0400 Received: from localhost by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 7 Aug 2018 13:25:31 -0600 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 7 Aug 2018 13:25:29 -0600 Received: from b03ledav001.gho.boulder.ibm.com (b03ledav001.gho.boulder.ibm.com [9.17.130.232]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w77JPSPB8061242 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 7 Aug 2018 12:25:28 -0700 Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4FDEC6E04E; Tue, 7 Aug 2018 13:25:28 -0600 (MDT) Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D88656E04C; Tue, 7 Aug 2018 13:25:27 -0600 (MDT) Received: from [9.10.86.107] (unknown [9.10.86.107]) by b03ledav001.gho.boulder.ibm.com (Postfix) with ESMTP; Tue, 7 Aug 2018 13:25:27 -0600 (MDT) Subject: [PATCH, RFC, rs6000] enable GIMPLE folding of vec_splat From: Will Schmidt Reply-To: will_schmidt@vnet.ibm.com To: Richard Biener , Segher Boessenkool , Bill Schmidt , David Edelsohn Cc: GCC Patches Date: Tue, 07 Aug 2018 14:25:27 -0500 Mime-Version: 1.0 x-cbid: 18080719-8235-0000-0000-00000DE2ED8B X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009502; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000266; SDB=6.01070725; UDB=6.00551144; IPR=6.00850128; MB=3.00022568; MTD=3.00000008; XFM=3.00000015; UTC=2018-08-07 19:25:30 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18080719-8236-0000-0000-000042301197 Message-Id: <1533669927.4452.14.camel@brimstone.rchland.ibm.com> X-IsSubscribed: yes Hi Enable GIMPLE folding of the vec_splat() intrinsic. For review.. feedback is expected. :-) I came up with the following after spending some time poking around at the tree_vec_extract() and vector_element() functions as seen in tree-vect-generic.c looking for insights. Some of this seems a bit clunky to me yet, but this is functional as far as make-check can tell, and is as far as I can get without additional input. This uses the tree_vec_extract() function out of tree-vect-generic.c to retrieve the splat value, which is a BIT_FIELD_REF. That function is made non-static as part of this change. In review of the .gimple output, this folding takes a sample testcase of vector bool int testb_0 (vector bool int x) { return vec_splat (x, 0b00000); } from: testb_0 (__vector __bool int x) { __vector __bool intD.1486 D.2855; _1 = VIEW_CONVERT_EXPR<__vector signed intD.1468>(xD.2778); _2 = __builtin_altivec_vspltwD.1919 (_1, 0); D.2855 = VIEW_CONVERT_EXPR<__vector __bool intD.1486>(_2); return D.2855; } to: testb_0 (__vector __bool int x) { __vector __bool intD.1486 D.2855; _1 = VIEW_CONVERT_EXPR<__vector signed intD.1468>(xD.2778); D.2856 = BIT_FIELD_REF <_1, 32, 0>; _2 = {D.2856, D.2856, D.2856, D.2856}; D.2855 = VIEW_CONVERT_EXPR<__vector __bool intD.1486>(_2); return D.2855; } Testcases are being posted as a separate patch. OK for trunk? Thanks, -Will [gcc] 2018-08-07 Will Schmidt * config/rs6000/rs6000.c (rs6000_gimple_fold_builtin): Add support for early gimple folding of vec_splat(). * tree-vect-generic.c: Remove static from tree_vec_extract() definition. * gimple-fold.h: Add an extern define for tree_vec_extract(). diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 35c32be..acc6b49 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -15764,10 +15764,56 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi) tree splat_tree = build_vector_from_val (TREE_TYPE (lhs), splat_value); g = gimple_build_assign (lhs, splat_tree); gimple_set_location (g, gimple_location (stmt)); gsi_replace (gsi, g, true); return true; + } + + /* Flavors of vec_splat. */ + // a = vec_splat (b, 0x3) ; // a = { b[3],b[3],b[3],...}; + case ALTIVEC_BUILTIN_VSPLTB: + case ALTIVEC_BUILTIN_VSPLTH: + case ALTIVEC_BUILTIN_VSPLTW: + case VSX_BUILTIN_XXSPLTD_V2DI: + case VSX_BUILTIN_XXSPLTD_V2DF: + { + arg0 = gimple_call_arg (stmt, 0); /* input vector. */ + arg1 = gimple_call_arg (stmt, 1); /* index into arg0. */ + /* Only fold the vec_splat_*() if arg1 is a constant + 5-bit unsigned literal. */ + if (TREE_CODE (arg1) != INTEGER_CST || TREE_INT_CST_LOW (arg1) > 0x1f) + return false; + + lhs = gimple_call_lhs (stmt); + tree lhs_type = TREE_TYPE (lhs); + + tree splat; + if (TREE_CODE (arg0) == VECTOR_CST) + splat = VECTOR_CST_ELT (arg0, TREE_INT_CST_LOW (arg1)); + else + { + /* Determine (in bits) the length and start location of the + splat value for a call to the tree_vec_extract helper. */ + int tree_size_in_bits = TREE_INT_CST_LOW (size_in_bytes (lhs_type)) + * BITS_PER_UNIT; + int splat_elem_size = tree_size_in_bits / VECTOR_CST_NELTS (arg0); + int splat_start_bit = TREE_INT_CST_LOW (arg1) * splat_elem_size; + /* Do not attempt to early-fold if the size + specified offset into + the vector would touch outside of the source vector. */ + if ((splat_start_bit + splat_elem_size) > tree_size_in_bits) + return false; + tree len = build_int_cst (bitsizetype, splat_elem_size); + tree start = build_int_cst (bitsizetype, splat_start_bit); + splat = tree_vec_extract (gsi, TREE_TYPE (lhs_type), arg0, + len, start); + } + /* And finally, build the new vector. */ + tree splat_tree = build_vector_from_val (lhs_type, splat); + g = gimple_build_assign (lhs, splat_tree); + gimple_set_location (g, gimple_location (stmt)); + gsi_replace (gsi, g, true); + return true; } /* vec_mergel (integrals). */ case ALTIVEC_BUILTIN_VMRGLH: case ALTIVEC_BUILTIN_VMRGLW: diff --git a/gcc/gimple-fold.h b/gcc/gimple-fold.h index 04e9bfa..e634180 100644 --- a/gcc/gimple-fold.h +++ b/gcc/gimple-fold.h @@ -59,10 +59,11 @@ extern tree gimple_fold_indirect_ref (tree); extern bool gimple_fold_builtin_sprintf (gimple_stmt_iterator *); extern bool gimple_fold_builtin_snprintf (gimple_stmt_iterator *); extern bool arith_code_with_undefined_signed_overflow (tree_code); extern gimple_seq rewrite_to_defined_overflow (gimple *); extern void replace_call_with_value (gimple_stmt_iterator *, tree); +extern tree tree_vec_extract (gimple_stmt_iterator *, tree, tree, tree, tree); /* gimple_build, functionally matching fold_buildN, outputs stmts int the provided sequence, matching and simplifying them on-the-fly. Supposed to replace force_gimple_operand (fold_buildN (...), ...). */ extern tree gimple_build (gimple_seq *, location_t, diff --git a/gcc/tree-vect-generic.c b/gcc/tree-vect-generic.c index 909f790..1c9701d 100644 --- a/gcc/tree-vect-generic.c +++ b/gcc/tree-vect-generic.c @@ -118,11 +118,11 @@ build_word_mode_vector_type (int nunits) typedef tree (*elem_op_func) (gimple_stmt_iterator *, tree, tree, tree, tree, tree, enum tree_code, tree); -static inline tree +tree tree_vec_extract (gimple_stmt_iterator *gsi, tree type, tree t, tree bitsize, tree bitpos) { if (TREE_CODE (t) == SSA_NAME) {