From patchwork Wed Sep 21 05:13:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: HAO CHEN GUI X-Patchwork-Id: 1329 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp1769070wrt; Tue, 20 Sep 2022 22:14:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM42F4rme5e9r6AEJN9Qrsup4sVWUcXP1LkZ7nmnk/wJVrHq4y01HdSeFbpTdObERfziBNWN X-Received: by 2002:aa7:d3cd:0:b0:452:5457:6375 with SMTP id o13-20020aa7d3cd000000b0045254576375mr23171379edr.111.1663737280397; Tue, 20 Sep 2022 22:14:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663737280; cv=none; d=google.com; s=arc-20160816; b=LQ3i8VuJwXo0hoegQJpz8PVVHdAshl1jNDpsItvGdtNNDmFP2yq+ZAvUUxcNkvoL5/ oazN08J6qD39sD79n6C+LSJ/FwhY4BAhg/1efn1TUTEbEiIG09fjGmlCpXRXTSnEyFnh uN4cTfDJqDOFn9CYydrVfnXSoonuJEokoffThAv/ToCEmG4QpgrT09+zpoMFqOANA1hy LMcyWlKLAmDjnHnKmmHdlgr1TloHg6n0utM8vNNYtp3rTR9mlD9YDJd7QMNwHgo4M1At +rmGVvRvfmlAyfVE6/rk1DRLioFolrGsft0GyNWhl++salYK/P+wAyoX0uuqDj+scqVj t0BQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:subject:to:content-language:user-agent :mime-version:date:message-id:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=gsu0Uke/84V+a0ctPPeY5LUWXkcg2hLdqmIAGgrwmpo=; b=0HNt80e+9f5FbUa0Xaw6hu6NFzmzuke39Em6bVbEy0qmotdKDzse4f0e189GLKxbAH BxMB0sUG1tGMzTH+fSG1aJB7lBgMiW5VKcjG+byfj3xXXpQAq0/66dc8N2OALzubHYMZ Y2zCKq7z3lsqM3QsR+B7rcjFmZXxQKNUPjSfvhxeG9Nc0mVJfuvBXXi9mkduzIvdDN9D +nEywf6XEJO5iYkoEi3rzSTokyJdUHOAH0Qz+vP4U90EWVfG200qJo4wmrMqagAEFZGJ tyXKDi1u8V+WEzj1A9wbRyb+Ub46PbBKp6z3WxZtqF0ABbny4I3CsBrcohTcWGPIRFyl N07A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=kM76cl09; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id hq19-20020a1709073f1300b0077d6d63bd0dsi1926482ejc.184.2022.09.20.22.14.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Sep 2022 22:14:40 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=kM76cl09; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AFAAC3858C00 for ; Wed, 21 Sep 2022 05:14:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AFAAC3858C00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663737278; bh=gsu0Uke/84V+a0ctPPeY5LUWXkcg2hLdqmIAGgrwmpo=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=kM76cl09ILxvTd9J8nTQq+5drDKsQbtizv9TvxpJ3BYAS63UPSZWHtT0YuET3rEfl BR7aEy9dTheqknyAAE71erZhfcaP7HbZP1Sm1wX5KMaD7lIyd4lmCC/t/CaYLUXns6 hA1yn6BayH2zg98MR022foILJXWOEJHylvW/jXh8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id AD45E3858C74 for ; Wed, 21 Sep 2022 05:13:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AD45E3858C74 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28L3tqP0027461; Wed, 21 Sep 2022 05:13:54 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jqu519xnn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Sep 2022 05:13:53 +0000 Received: from m0098417.ppops.net (m0098417.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 28L5BLjd007417; Wed, 21 Sep 2022 05:13:53 GMT Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jqu519xn2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Sep 2022 05:13:53 +0000 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28L55mHa003214; Wed, 21 Sep 2022 05:13:51 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma05fra.de.ibm.com with ESMTP id 3jn5v8ugyx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Sep 2022 05:13:51 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28L5Dmbd46006550 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 21 Sep 2022 05:13:48 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1A27DA405C; Wed, 21 Sep 2022 05:13:48 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B9304A4054; Wed, 21 Sep 2022 05:13:46 +0000 (GMT) Received: from [9.200.101.101] (unknown [9.200.101.101]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 21 Sep 2022 05:13:46 +0000 (GMT) Message-ID: <3bba6092-cd88-7cfc-2c60-fb24945fdf8c@linux.ibm.com> Date: Wed, 21 Sep 2022 13:13:45 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Content-Language: en-US To: gcc-patches Subject: [PATCH, rs6000] Splat vector small V2DI constants with ISA 2.07 instructions [PR104124] X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: oio57dbtlfgKHS_G8jC_FRW8a3muXDls X-Proofpoint-GUID: UH2qJrajHz0Gll7wFvWUTUY0h444JPW2 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-21_02,2022-09-20_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 mlxscore=0 suspectscore=0 bulkscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 mlxlogscore=999 phishscore=0 malwarescore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2209210032 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: HAO CHEN GUI via Gcc-patches From: HAO CHEN GUI Reply-To: HAO CHEN GUI Cc: Peter Bergner , David , Segher Boessenkool Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1744554982233276535?= X-GMAIL-MSGID: =?utf-8?q?1744554982233276535?= Hi, This patch adds a new insn for vector splat with small V2DI constants on P8. If the value of constant is in RANGE (-16, 15) and not 0 or -1, it can be loaded with vspltisw and vupkhsw on P8. It should be efficient than loading vector from TOC. Bootstrapped and tested on powerpc64-linux BE and LE with no regressions. Is this okay for trunk? Any recommendations? Thanks a lot. ChangeLog 2022-09-21 Haochen Gui gcc/ PR target/104124 * config/rs6000/altivec.md (*altivec_vupkhs_direct): Renamed to... (altivec_vupkhs_direct): ...this. * config/rs6000/constraints.md (wT constraint): New constant for a vector constraint that can be loaded with vspltisw and vupkhsw. * config/rs6000/predicates.md (vspltisw_constant_split): New predicate for wT constraint. * config/rs6000/rs6000-protos.h (vspltisw_constant_p): Add declaration. * config/rs6000/rs6000.cc (easy_altivec_constant): Call vspltisw_constant_p to judge if a V2DI constant can be synthesized with a vspltisw and a vupkhsw. * (vspltisw_constant_p): New function to return true if OP mode is V2DI and can be synthesized with ISA 2.07 instruction vupkhsw and vspltisw. * gcc/config/rs6000/vsx.md (*vspltisw_v2di_split): New insn to load up constants with vspltisw and vupkhsw. gcc/testsuite/ PR target/104124 * gcc.target/powerpc/p8-splat.c: New. patch.diff diff --git a/gcc/config/rs6000/altivec.md b/gcc/config/rs6000/altivec.md index 2c4940f2e21..185414df021 100644 --- a/gcc/config/rs6000/altivec.md +++ b/gcc/config/rs6000/altivec.md @@ -2542,7 +2542,7 @@ (define_insn "altivec_vupkhs" } [(set_attr "type" "vecperm")]) -(define_insn "*altivec_vupkhs_direct" +(define_insn "altivec_vupkhs_direct" [(set (match_operand:VP 0 "register_operand" "=v") (unspec:VP [(match_operand: 1 "register_operand" "v")] UNSPEC_VUNPACK_HI_SIGN_DIRECT))] diff --git a/gcc/config/rs6000/constraints.md b/gcc/config/rs6000/constraints.md index 5a44a92142e..f65dea6e0c7 100644 --- a/gcc/config/rs6000/constraints.md +++ b/gcc/config/rs6000/constraints.md @@ -150,6 +150,10 @@ (define_constraint "wS" "@internal Vector constant that can be loaded with XXSPLTIB & sign extension." (match_test "xxspltib_constant_split (op, mode)")) +(define_constraint "wT" + "@internal Vector constant that can be loaded with vspltisw & vupkhsw." + (match_test "vspltisw_constant_split (op, mode)")) + ;; ISA 3.0 DS-form instruction that has the bottom 2 bits 0 and no update form. ;; Used by LXSD/STXSD/LXSSP/STXSSP. In contrast to "Y", the multiple-of-four ;; offset is enforced for 32-bit too. diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md index b1fcc69bb60..00cf60bbe58 100644 --- a/gcc/config/rs6000/predicates.md +++ b/gcc/config/rs6000/predicates.md @@ -694,6 +694,19 @@ (define_predicate "xxspltib_constant_split" return num_insns > 1; }) +;; Return true if the operand is a constant that can be loaded with a vspltisw +;; instruction and then a vupkhsw instruction. + +(define_predicate "vspltisw_constant_split" + (match_code "const_vector,vec_duplicate") +{ + int value = 32; + + if (!vspltisw_constant_p (op, mode, &value)) + return false; + + return true; +}) ;; Return 1 if the operand is constant that can loaded directly with a XXSPLTIB ;; instruction. diff --git a/gcc/config/rs6000/rs6000-protos.h b/gcc/config/rs6000/rs6000-protos.h index b3c16e7448d..45f3d044eee 100644 --- a/gcc/config/rs6000/rs6000-protos.h +++ b/gcc/config/rs6000/rs6000-protos.h @@ -32,6 +32,7 @@ extern void init_cumulative_args (CUMULATIVE_ARGS *, tree, rtx, int, int, int, extern int easy_altivec_constant (rtx, machine_mode); extern bool xxspltib_constant_p (rtx, machine_mode, int *, int *); +extern bool vspltisw_constant_p (rtx, machine_mode, int *); extern int vspltis_shifted (rtx); extern HOST_WIDE_INT const_vector_elt_as_int (rtx, unsigned int); extern bool macho_lo_sum_memory_operand (rtx, machine_mode); diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc index df491bee2ea..984624026c2 100644 --- a/gcc/config/rs6000/rs6000.cc +++ b/gcc/config/rs6000/rs6000.cc @@ -6292,6 +6292,12 @@ easy_altivec_constant (rtx op, machine_mode mode) && INTVAL (CONST_VECTOR_ELT (op, 1)) == -1) return 8; + /* If V2DI constant is within RANGE (-16, 15), it can be synthesized with + a vspltisw and a vupkhsw. */ + int value = 32; + if (vspltisw_constant_p (op, mode, &value)) + return 8; + return 0; } @@ -6494,6 +6500,69 @@ xxspltib_constant_p (rtx op, return true; } +/* Return true if OP mode is V2DI and can be synthesized with ISA 2.07 + instructions vupkhsw and vspltisw. + + Return the constant that is being split via CONSTANT_PTR. */ + +bool +vspltisw_constant_p (rtx op, machine_mode mode, int *constant_ptr) +{ + HOST_WIDE_INT value; + rtx element; + + *constant_ptr = 32; + + if (!TARGET_P8_VECTOR) + return false; + + if (mode == VOIDmode) + mode = GET_MODE (op); + else if (mode != GET_MODE (op) && GET_MODE (op) != VOIDmode) + return false; + + if (mode != V2DImode) + return false; + + if (GET_CODE (op) == VEC_DUPLICATE) + { + element = XEXP (op, 0); + + if (!CONST_INT_P (element)) + return false; + + value = INTVAL (element); + if (value == 0 || value == 1 + || !EASY_VECTOR_15 (value)) + return false; + } + + else if (GET_CODE (op) == CONST_VECTOR) + { + element = CONST_VECTOR_ELT (op, 0); + + if (!CONST_INT_P (element)) + return false; + + value = INTVAL (element); + if (value == 0 || value == 1 + || !EASY_VECTOR_15 (value)) + return false; + + element = CONST_VECTOR_ELT (op, 1); + if (!CONST_INT_P (element)) + return false; + + if (value != INTVAL (element)) + return false; + } + else + return false; + + *constant_ptr = (int) value; + return true; +} + const char * output_vec_const_move (rtx *operands) { diff --git a/gcc/config/rs6000/vsx.md b/gcc/config/rs6000/vsx.md index e226a93bbe5..6805f794848 100644 --- a/gcc/config/rs6000/vsx.md +++ b/gcc/config/rs6000/vsx.md @@ -1174,6 +1174,32 @@ (define_insn_and_split "*xxspltib__split" [(set_attr "type" "vecperm") (set_attr "length" "8")]) +(define_insn_and_split "*vspltisw_v2di_split" + [(set (match_operand:V2DI 0 "altivec_register_operand" "=v") + (match_operand:V2DI 1 "vspltisw_constant_split" "wT"))] + "TARGET_P8_VECTOR" + "#" + "&& 1" + [(const_int 0)] +{ + int value = 32; + rtx op0 = operands[0]; + rtx op1 = operands[1]; + rtx tmp = can_create_pseudo_p () + ? gen_reg_rtx (V4SImode) + : gen_lowpart (V4SImode, op0); + + if (!vspltisw_constant_p (op1, V2DImode, &value)) + gcc_unreachable (); + + emit_insn (gen_altivec_vspltisw (tmp, GEN_INT (value))); + emit_insn (gen_altivec_vupkhsw_direct (op0, tmp)); + + DONE; +} + [(set_attr "type" "vecperm") + (set_attr "length" "8")]) + ;; Prefer using vector registers over GPRs. Prefer using ISA 3.0's XXSPLTISB ;; or Altivec VSPLITW 0/-1 over XXLXOR/XXLORC to set a register to all 0's or diff --git a/gcc/testsuite/gcc.target/powerpc/p8-splat.c b/gcc/testsuite/gcc.target/powerpc/p8-splat.c new file mode 100644 index 00000000000..aec0f20edb9 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/p8-splat.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-mdejagnu-cpu=power8 -O2" } */ +/* { dg-require-effective-target powerpc_p8vector_ok } */ +/* { dg-final { scan-assembler "vspltisw" } } */ +/* { dg-final { scan-assembler "vupkhsw" } } */ +/* { dg-final { scan-assembler-not "lvx" } } */ + +#include + +vector unsigned long long +foo () +{ + return vec_splats ((unsigned long long) 12); +}