From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 053FC3952027; Thu, 20 Oct 2022 09:29:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 053FC3952027 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29K9Jbt8023895; Thu, 20 Oct 2022 09:29:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : mime-version : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=imzTYcNSEadNA2S8yIo08x18X/xgJiOAMz3go3r08Bw=; b=W6JT929kM+LnTEt2Y4tCugzk/kWvbu3AQhJNddjkc52HOWR8V3ajw4iginlh2s3+2Is8 S7Wl+9Mjpebf5BAwKCetgfIMpZ9EgCcB9v0ntq2trqUjBKJiwXt79p+s4RZoPoZJYr45 21ovV7InP5o5yQj/muo66jJGYhh0ZIfqjAkWHcTVR9vz7ZWufNrZaaV9njSsFod3W2oH Rc9CbmA4CBFnA9dr9Ev+WUUWPIGE2APhhI1fN68nWT9osd6o2XEBE8RBhe4XkeQHkgfd JEYnqDfdUssg9ptVsHsR37G9rrXJoVZ6qwidd57Q8/1DQIo9LWNw+wM/jCL3EdaBDR3u Cw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3kb3ks88b8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 20 Oct 2022 09:29:45 +0000 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 29K9JrKt024981; Thu, 20 Oct 2022 09:29:45 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3kb3ks88as-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 20 Oct 2022 09:29:45 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 29K9MQ2V028683; Thu, 20 Oct 2022 09:29:43 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma06ams.nl.ibm.com with ESMTP id 3kajmrsc32-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 20 Oct 2022 09:29:43 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 29K9OdkU44564840 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Oct 2022 09:24:39 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0E30F4C050; Thu, 20 Oct 2022 09:29:41 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3EE434C044; Thu, 20 Oct 2022 09:29:39 +0000 (GMT) Received: from [9.197.227.147] (unknown [9.197.227.147]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 20 Oct 2022 09:29:38 +0000 (GMT) Message-ID: Date: Thu, 20 Oct 2022 17:29:37 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: Re: [PATCH] rs6000: using li/lis+oris/xoris to build constants Content-Language: en-US To: Jiufu Guo Cc: dje.gcc@gmail.com, segher@kernel.crashing.org, linkw@gcc.gnu.org, gcc-patches@gcc.gnu.org References: <20220824081344.70468-1-guojiufu@linux.ibm.com> From: "Kewen.Lin" In-Reply-To: <20220824081344.70468-1-guojiufu@linux.ibm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: LX-6u96Dv5mVjcNeFbr1kLwMjHfCQi1U X-Proofpoint-GUID: arVEiuUyaEmxz93keZlqfuvJETi84R8K X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-20_02,2022-10-19_04,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=937 lowpriorityscore=0 suspectscore=0 phishscore=0 mlxscore=0 malwarescore=0 spamscore=0 clxscore=1015 priorityscore=1501 impostorscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2210200053 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,NICE_REPLY_A,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 List-Id: Hi Jeff, Sorry for late review, some comments are inline. on 2022/8/24 16:13, Jiufu Guo via Gcc-patches wrote: > Hi, > > PR106708 constaint some constants which can be support by li/lis + oris/xoris. > > For constant C: > if ((c & 0xFFFFFFFF80008000ULL) == 0x80000000ULL) or say: > 32(0)+1(1)+15(x)+1(0)+15(x), we could use li+oris to build constant 'C'. > > if ((c & 0xFFFFFFFF00008000ULL) == 0xFFFFFFFF00008000ULL) or say: > 32(1)+16(x)+1(1)+15(x), using li+xoris would be ok. > > if ((c & 0xFFFFFFFF0000FFFFULL) == 0xFFFFFFFF00000000) or say: > 32(1)+1(0)+15(x)+16(0), using lis+xoris would be ok. > Maybe it's good to add some explanation on the proposed writing "N(M)" N continuous bit M, (x for M means either 1 or 0), and not sure if it's good to use "||" for concatenation just like what ISA uses, the con is it can be mis-interpreted as logical "or". Or maybe just expand all the low 32 bits and use "1..." or "0..." for the high 32 bits. > This patch update rs6000_emit_set_long_const to support these forms. > Bootstrap and regtest pass on ppc64 and ppc64le. > > Is this ok for trunk? > > BR, > Jeff(Jiufu) > > > PR target/106708 > > gcc/ChangeLog: > > * config/rs6000/rs6000.cc (rs6000_emit_set_long_const): Using li/lis + > oris/xoris to build constants. Nit: Support constants which can be built with li + oris or li/lis + xoris? > > gcc/testsuite/ChangeLog: > > * gcc.target/powerpc/pr106708.c: New test. > * gcc.target/powerpc/pr106708.h: New file. > * gcc.target/powerpc/pr106708_1.c: New test. > > --- > gcc/config/rs6000/rs6000.cc | 22 +++++++++++++++++++ > gcc/testsuite/gcc.target/powerpc/pr106708.c | 10 +++++++++ > gcc/testsuite/gcc.target/powerpc/pr106708.h | 9 ++++++++ > gcc/testsuite/gcc.target/powerpc/pr106708_1.c | 17 ++++++++++++++ > 4 files changed, 58 insertions(+) > create mode 100644 gcc/testsuite/gcc.target/powerpc/pr106708.c > create mode 100644 gcc/testsuite/gcc.target/powerpc/pr106708.h > create mode 100644 gcc/testsuite/gcc.target/powerpc/pr106708_1.c > > diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc > index df491bee2ea..243247fb838 100644 > --- a/gcc/config/rs6000/rs6000.cc > +++ b/gcc/config/rs6000/rs6000.cc > @@ -10112,6 +10112,7 @@ rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c) > { > rtx temp; > HOST_WIDE_INT ud1, ud2, ud3, ud4; > + HOST_WIDE_INT orig_c = c; > > ud1 = c & 0xffff; > c = c >> 16; > @@ -10137,6 +10138,27 @@ rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c) > gen_rtx_IOR (DImode, copy_rtx (temp), > GEN_INT (ud1))); > } > + else if (ud4 == 0 && ud3 == 0 && (ud2 & 0x8000) && !(ud1 & 0x8000)) > + { > + temp = !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode); > + > + /* li+oris */ > + emit_move_insn (copy_rtx (temp), GEN_INT (ud1)); Nit: in previous discussion on some other patch, copy_rtx is not necessary? > + emit_move_insn (dest, gen_rtx_IOR (DImode, copy_rtx (temp), > + GEN_INT (ud2 << 16))); > + } I think this hunk above can be moved to the existing "(ud3 == 0 && ud4 == 0)" handling branch (as the diff context below), and ud2 & 0x8000 is already asserted there, it also saves check. > + else if ((ud4 == 0xffff && ud3 == 0xffff) > + && ((ud1 & 0x8000) || (ud1 == 0 && !(ud2 & 0x8000)))) > + { > + temp = !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode); > + > + HOST_WIDE_INT imm = (ud1 & 0x8000) ? ((ud1 ^ 0x8000) - 0x8000) > + : ((ud2 << 16) - 0x80000000); > + /* li/lis + xoris */ > + emit_move_insn (copy_rtx (temp), GEN_INT (imm)); > + emit_move_insn (dest, gen_rtx_XOR (DImode, copy_rtx (temp), > + GEN_INT (orig_c ^ imm))); > + } Same comment for copy_rtx. > else if (ud3 == 0 && ud4 == 0) > { > temp = !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode); > diff --git a/gcc/testsuite/gcc.target/powerpc/pr106708.c b/gcc/testsuite/gcc.target/powerpc/pr106708.c > new file mode 100644 > index 00000000000..6445fa47747 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/powerpc/pr106708.c > @@ -0,0 +1,10 @@ > +/* PR target/106708 */ > +/* { dg-options "-O2 -mdejagnu-cpu=power8" } */ > +/* { dg-do compile { target has_arch_ppc64 } } */ > + Put dg-do as the first line, if you want has_arch_ppc64 to be behind dg-options, separate it into a dg-require-effective-target. > +#include "pr106708.h" > + > +/* { dg-final { scan-assembler-times {\mli\M} 2 } } */ > +/* { dg-final { scan-assembler-times {\mlis\M} 1 } } */ > +/* { dg-final { scan-assembler-times {\moris\M} 1 } } */ > +/* { dg-final { scan-assembler-times {\mxoris\M} 2 } } */ > diff --git a/gcc/testsuite/gcc.target/powerpc/pr106708.h b/gcc/testsuite/gcc.target/powerpc/pr106708.h > new file mode 100644 > index 00000000000..ad07eb30547 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/powerpc/pr106708.h > @@ -0,0 +1,9 @@ > +/* li/lis + oris/xoris */ Nit: /* Test constants which can be built from li + oris and li/lis + xoris. */ > +void __attribute__ ((__noinline__, __noclone__)) foo (long long *arg) > +{ > + *arg++ = 0x98765432ULL; > + *arg++ = 0xffffffff7cdeab55ULL; > + *arg++ = 0xffffffff65430000ULL; > +} > + > + > diff --git a/gcc/testsuite/gcc.target/powerpc/pr106708_1.c b/gcc/testsuite/gcc.target/powerpc/pr106708_1.c > new file mode 100644 > index 00000000000..df65c321f6b > --- /dev/null > +++ b/gcc/testsuite/gcc.target/powerpc/pr106708_1.c Nit: better with name pr106708-run.c? BR, Kewen > @@ -0,0 +1,17 @@ > +/* PR target/106708 */ > +/* { dg-do run } */ > +/* { dg-options "-O2" } */ > + > +#include "pr106708.h" > + > +long long arr[] = {0x98765432ULL, 0xffffffff7cdeab55ULL, 0xffffffff65430000ULL}; > +int > +main () > +{ > + long long a[3]; > + > + foo (a); > + if (__builtin_memcmp (a, arr, sizeof (arr)) != 0) > + __builtin_abort (); > + return 0; > +}