From patchwork Fri May 13 15:08:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Meissner X-Patchwork-Id: 53957 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2B354396E828 for ; Fri, 13 May 2022 15:09:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2B354396E828 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652454564; bh=PQ7Q935Krb/z6mRWxDoNgrRZVOj+uIpy3dJObem8+d0=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=HBugRu/4OOV+5N8XyzKJZ3oUiZIovZQ2lDg2SjoBFOA5pz2mZr6WFsqL6sGICR2dh 4GKVhYiP68Z88GRAvuhTS2hLn/F34bSSZViqnGpX1VPbTsxXqM2h6ngMlVzG+AxOSy Z+vo817sn3jl0k6eBlPRe/vikD7w5MdvPQClaGyo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 2003A3856DE3 for ; Fri, 13 May 2022 15:08:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2003A3856DE3 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24DEfLLd014853; Fri, 13 May 2022 15:08:53 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3g1rvkhdv8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 May 2022 15:08:52 +0000 Received: from m0098410.ppops.net (m0098410.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 24DEfqgI016536; Fri, 13 May 2022 15:08:52 GMT Received: from ppma03dal.us.ibm.com (b.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.11]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3g1rvkhduu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 May 2022 15:08:52 +0000 Received: from pps.filterd (ppma03dal.us.ibm.com [127.0.0.1]) by ppma03dal.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 24DF8UrE014357; Fri, 13 May 2022 15:08:51 GMT Received: from b01cxnp23034.gho.pok.ibm.com (b01cxnp23034.gho.pok.ibm.com [9.57.198.29]) by ppma03dal.us.ibm.com with ESMTP id 3fwgdanqav-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 May 2022 15:08:51 +0000 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 24DF8o7h27525406 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 May 2022 15:08:50 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 38F46AE060; Fri, 13 May 2022 15:08:50 +0000 (GMT) Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DE6DBAE05C; Fri, 13 May 2022 15:08:49 +0000 (GMT) Received: from toto.the-meissners.org (unknown [9.65.255.130]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTPS; Fri, 13 May 2022 15:08:49 +0000 (GMT) Date: Fri, 13 May 2022 11:08:48 -0400 To: gcc-patches@gcc.gnu.org, Michael Meissner , Segher Boessenkool , "Kewen.Lin" , David Edelsohn , Peter Bergner , Will Schmidt Subject: [PATCH] Delay splitting addti3/subti3 until first split pass. Message-ID: Mail-Followup-To: Michael Meissner , gcc-patches@gcc.gnu.org, Segher Boessenkool , "Kewen.Lin" , David Edelsohn , Peter Bergner , Will Schmidt MIME-Version: 1.0 Content-Disposition: inline X-TM-AS-GCONF: 00 X-Proofpoint-GUID: mRt9AXXJFWsCGEpEh42MLFSfsNKD3lpF X-Proofpoint-ORIG-GUID: l_Vm75vPg380MrUDl9Vw8GEyMGf_0wRc X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-13_04,2022-05-13_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 suspectscore=0 adultscore=0 bulkscore=0 mlxlogscore=999 impostorscore=0 lowpriorityscore=0 priorityscore=1501 mlxscore=0 phishscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205130067 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_MANYTO, KAM_SHORT, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: Michael Meissner via Gcc-patches From: Michael Meissner Reply-To: Michael Meissner Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Add zero_extendditi2. Improve lxvr*x code generation. This pattern adds zero_extendditi2 so that if we are extending DImode that is in a GPR register to TImode in a vector register, the compiler can generate MTVSRDDD. In addition the patterns for generating lxvr{b,h,w,d}x were tuned to allow loading to gpr registers. This prevents needlessly doing direct moves to get the value into the vector registers if the gpr register was already selected. In updating the insn counts for two tests due to these changes, I noticed the tests were done at -O0. I changed this so that the tests are now done at the normal -O2 optimization level. This patch will be needed for an upcoming patch for PR target/103109. I have built this patch on little endian power10, little endian power9, and big endian power8 systems. There were no regressions with this patch. Can I install this on the GCC 13 trunk? 2022-05-013 Michael Meissner gcc/ * config/rs6000/vsx.md (vsx_lxvrx): Add support for loading to GPR registers. (vsx_stxvrx): Add support for storing from GPR registers. (zero_extendditi2): New insn. gcc/testsuite/ * gcc.target/powerpc/vsx-load-element-extend-int.c: Use -O2 instead of -O0 and update insn counts. * gcc.target/powerpc/vsx-load-element-extend-short.c: Likewise. * gcc.target/powerpc/zero-extend-di-ti.c: New test. --- gcc/config/rs6000/vsx.md | 82 +++++++++++++++++-- .../powerpc/vsx-load-element-extend-int.c | 36 ++++---- .../powerpc/vsx-load-element-extend-short.c | 35 ++++---- .../gcc.target/powerpc/zero-extend-di-ti.c | 62 ++++++++++++++ 4 files changed, 164 insertions(+), 51 deletions(-) create mode 100644 gcc/testsuite/gcc.target/powerpc/zero-extend-di-ti.c diff --git a/gcc/config/rs6000/vsx.md b/gcc/config/rs6000/vsx.md index c091e5e2f47..ad971e3a1de 100644 --- a/gcc/config/rs6000/vsx.md +++ b/gcc/config/rs6000/vsx.md @@ -1315,14 +1315,32 @@ (define_expand "vsx_store_" } }) -;; Load rightmost element from load_data -;; using lxvrbx, lxvrhx, lxvrwx, lxvrdx. -(define_insn "vsx_lxvrx" - [(set (match_operand:TI 0 "vsx_register_operand" "=wa") - (zero_extend:TI (match_operand:INT_ISA3 1 "memory_operand" "Z")))] - "TARGET_POWER10" - "lxvrx %x0,%y1" - [(set_attr "type" "vecload")]) +;; Load rightmost element from load_data using lxvrbx, lxvrhx, lxvrwx, lxvrdx. +;; Support TImode being in a GPR register to prevent generating lvxr{d,w,b}x +;; and then two direct moves if we ultimately need the value in a GPR register. +(define_insn_and_split "vsx_lxvrx" + [(set (match_operand:TI 0 "register_operand" "=r,wa") + (zero_extend:TI (match_operand:INT_ISA3 1 "memory_operand" "m,Z")))] + "TARGET_POWERPC64 && TARGET_POWER10" + "@ + # + lxvrx %x0,%y1" + "&& reload_completed && int_reg_operand (operands[0], TImode)" + [(set (match_dup 2) (match_dup 3)) + (set (match_dup 4) (const_int 0))] +{ + rtx op0 = operands[0]; + rtx op1 = operands[1]; + + operands[2] = gen_lowpart (DImode, op0); + operands[3] = (mode == DImode + ? op1 + : gen_rtx_ZERO_EXTEND (DImode, op1)); + + operands[4] = gen_highpart (DImode, op0); +} + [(set_attr "type" "load,vecload") + (set_attr "num_insns" "2,*")]) ;; Store rightmost element into store_data ;; using stxvrbx, stxvrhx, strvxwx, strvxdx. @@ -5019,6 +5037,54 @@ (define_expand "vsignextend_si_v2di" DONE; }) +;; Zero extend DI to TI. If we don't have the MTVSRDD instruction (and LXVRDX +;; in the case of power10), we use the machine independent code. If we are +;; loading up GPRs, we fall back to the old code. +(define_insn_and_split "zero_extendditi2" + [(set (match_operand:TI 0 "register_operand" "=r,r, wa,&wa") + (zero_extend:TI (match_operand:DI 1 "register_operand" "r,wa,r, wa")))] + "TARGET_POWERPC64 && TARGET_P9_VECTOR" + "@ + # + # + mtvsrdd %x0,0,%1 + #" + "&& reload_completed + && (int_reg_operand (operands[0], TImode) + || vsx_register_operand (operands[1], DImode))" + [(pc)] +{ + rtx dest = operands[0]; + rtx src = operands[1]; + int dest_regno = reg_or_subregno (dest); + + /* Handle conversion to GPR registers. Load up the low part and then do + zero out the upper part. */ + if (INT_REGNO_P (dest_regno)) + { + rtx dest_hi = gen_highpart (DImode, dest); + rtx dest_lo = gen_lowpart (DImode, dest); + + emit_move_insn (dest_lo, src); + emit_move_insn (dest_hi, const0_rtx); + DONE; + } + + /* For settomg a VSX register from another VSX register, clear the result + register, and use XXPERMDI to shift the value into the lower 64-bits. */ + rtx dest_v2di = gen_rtx_REG (V2DImode, dest_regno); + rtx dest_di = gen_rtx_REG (DImode, dest_regno); + + emit_move_insn (dest_v2di, CONST0_RTX (V2DImode)); + if (BYTES_BIG_ENDIAN) + emit_insn (gen_vsx_concat_v2di (dest_v2di, dest_di, src)); + else + emit_insn (gen_vsx_concat_v2di (dest_v2di, src, dest_di)); + DONE; +} + [(set_attr "type" "integer,mfvsr,vecmove,vecperm") + (set_attr "length" "8, 8, *, 8")]) + ;; Sign extend DI to TI. We provide both GPR targets and Altivec targets on ;; power10. On earlier systems, the machine independent code will generate a ;; shift left to sign extend the 64-bit value to 128-bit. diff --git a/gcc/testsuite/gcc.target/powerpc/vsx-load-element-extend-int.c b/gcc/testsuite/gcc.target/powerpc/vsx-load-element-extend-int.c index c40e1a3a0f7..1f1281d6b75 100644 --- a/gcc/testsuite/gcc.target/powerpc/vsx-load-element-extend-int.c +++ b/gcc/testsuite/gcc.target/powerpc/vsx-load-element-extend-int.c @@ -6,33 +6,25 @@ /* { dg-do compile { target { ! power10_hw } } } */ /* { dg-require-effective-target power10_ok } */ /* { dg-require-effective-target int128 } */ - -/* Deliberately set optization to zero for this test to confirm - the lxvr*x instruction is generated. At higher optimization levels - the instruction we are looking for is sometimes replaced by other - load instructions. */ -/* { dg-options "-mdejagnu-cpu=power10 -O0 -save-temps" } */ - +/* { dg-options "-mdejagnu-cpu=power10 -O2 -save-temps" } */ /* { dg-final { scan-assembler-times {\mlxvrwx\M} 2 } } */ #define NUM_VEC_ELEMS 4 #define ITERS 16 -/* -Codegen at time of writing is a single lxvrwx for the zero -extended test, and a lwax,mtvsrdd,vextsd2q for the sign -extended test. - -0000000010000c90 : - 10000c90: aa 1a 24 7d lwax r9,r4,r3 - 10000c94: 67 4b 40 7c mtvsrdd vs34,0,r9 - 10000c98: 02 16 5b 10 vextsd2q v2,v2 - 10000c9c: 20 00 80 4e blr - -0000000010000cb0 : - 10000cb0: 9b 18 44 7c lxvrwx vs34,r4,r3 - 10000cb4: 20 00 80 4e blr -*/ +/* Codegen at time of writing is a single lxvrwx for the zero extended test, + and a lxvrwx + vexts* sign extension instructions for the sign extended + test. + + 0000000000000000 : + 0: 9b 18 44 7c lxvrwx vs34,r4,r3 + 4: 02 16 5a 10 vextsw2d v2,v2 + 8: 02 16 5b 10 vextsd2q v2,v2 + c: 20 00 80 4e blr + + 0000000000000020 : + 20: 9b 18 44 7c lxvrwx vs34,r4,r3 + 24: 20 00 80 4e blr */ #include #include diff --git a/gcc/testsuite/gcc.target/powerpc/vsx-load-element-extend-short.c b/gcc/testsuite/gcc.target/powerpc/vsx-load-element-extend-short.c index 837ba79c9ab..a7721318812 100644 --- a/gcc/testsuite/gcc.target/powerpc/vsx-load-element-extend-short.c +++ b/gcc/testsuite/gcc.target/powerpc/vsx-load-element-extend-short.c @@ -6,33 +6,26 @@ /* { dg-do compile { target { ! power10_hw } } } */ /* { dg-require-effective-target power10_ok } */ /* { dg-require-effective-target int128 } */ - -/* Deliberately set optization to zero for this test to confirm - the lxvr*x instruction is generated. At higher optimization levels - the instruction we are looking for is sometimes replaced by other - load instructions. */ -/* { dg-options "-mdejagnu-cpu=power10 -O0 -save-temps" } */ +/* { dg-options "-mdejagnu-cpu=power10 -O2 -save-temps" } */ /* { dg-final { scan-assembler-times {\mlxvrhx\M} 2 } } */ #define NUM_VEC_ELEMS 8 #define ITERS 16 -/* -Codegen at time of writing uses lxvrhx for the zero -extension test and lhax,mtvsrdd,vextsd2q for the -sign extended test. - -0000000010001810 : - 10001810: ae 1a 24 7d lhax r9,r4,r3 - 10001814: 67 4b 40 7c mtvsrdd vs34,0,r9 - 10001818: 02 16 5b 10 vextsd2q v2,v2 - 1000181c: 20 00 80 4e blr - -0000000010001830 : - 10001830: 5b 18 44 7c lxvrhx vs34,r4,r3 - 10001834: 20 00 80 4e blr -*/ +/* Codegen at time of writing is a single lxvrwx for the zero extended test, + and a lxvrwx + vexts* sign extension instructions for the sign extended + test. + + 0000000000000000 : + 0: 5b 18 44 7c lxvrhx vs34,r4,r3 + 4: 02 16 59 10 vextsh2d v2,v2 + 8: 02 16 5b 10 vextsd2q v2,v2 + c: 20 00 80 4e blr + + 0000000000000020 : + 20: 5b 18 44 7c lxvrhx vs34,r4,r3 + 24: 20 00 80 4e blr */ #include #include diff --git a/gcc/testsuite/gcc.target/powerpc/zero-extend-di-ti.c b/gcc/testsuite/gcc.target/powerpc/zero-extend-di-ti.c new file mode 100644 index 00000000000..9b3b9c4dbd0 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/zero-extend-di-ti.c @@ -0,0 +1,62 @@ +/* { dg-require-effective-target int128 } */ +/* { dg-require-effective-target power10_ok } */ +/* { dg-options "-mdejagnu-cpu=power10 -O2" } */ + +/* This patch makes sure the various optimization and code paths are done for + zero extending DImode to TImode on power10. */ + +__uint128_t +gpr_to_gpr (unsigned long long a) +{ + /* li 4,0. */ + return a; +} + +__uint128_t +mem_to_gpr (unsigned long long *p) +{ + /* ld 3,0(3); li 4,0. */ + return *p; +} + +__uint128_t +vsx_to_gpr (__uint128_t *p, double d) +{ + /* fctiduz 1,1; li 4,0;mfvsrd 3,1. */ + return (unsigned long long)d; +} + +void +gpr_to_vsx (__uint128_t *p, unsigned long long a) +{ + /* mtvsrdd 0,0,4; stxv 0,0(3). */ + __uint128_t b = a; + __asm__ (" # %x0" : "+wa" (b)); + *p = b; +} + +void +mem_to_vsx (__uint128_t *p, unsigned long long *q) +{ + /* lxvrdx 0,0,4; stxv 0,0(3). */ + __uint128_t a = *q; + __asm__ (" # %x0" : "+wa" (a)); + *p = a; +} + +void +vsx_to_vsx (__uint128_t *p, double d) +{ + /* fctiduz 1,1; xxspltib 0,0; xxpermdi 0,0,1,0; stxv 0,0(3). */ + __uint128_t a = (unsigned long long)d; + __asm__ (" # %x0" : "+wa" (a)); + *p = a; +} + +/* { dg-final { scan-assembler-times {\mli\M} 3 } } */ +/* { dg-final { scan-assembler-times {\mld\M} 1 } } */ +/* { dg-final { scan-assembler-times {\mlxvrdx\M} 1 } } */ +/* { dg-final { scan-assembler-times {\mmfvsrd\M} 1 } } */ +/* { dg-final { scan-assembler-times {\mmtvsrdd\M} 1 } } */ +/* { dg-final { scan-assembler-times {\mstxv\M} 3 } } */ +/* { dg-final { scan-assembler-times {\mxxpermdi\M} 1 } } */