Message ID | 20220824081344.70468-1-guojiufu@linux.ibm.com |
---|---|
State | New, archived |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp1310243wro; Wed, 24 Aug 2022 01:14:37 -0700 (PDT) X-Google-Smtp-Source: AA6agR7R2pht6E+FaKQr/aVMmAh6kbAiWRjpLAGB8N9aj6LLSh+wY1QIkWZgDX3QhbNdbamm8v1F X-Received: by 2002:a17:906:dc92:b0:73d:8ed8:a894 with SMTP id cs18-20020a170906dc9200b0073d8ed8a894mr2045765ejc.497.1661328877383; Wed, 24 Aug 2022 01:14:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661328877; cv=none; d=google.com; s=arc-20160816; b=l4+By3Bg1wip/+v3jiTligMiCkH+pOcYxAJ5EuqShIbIWcSjSTCUc+CU8WOp/c0Fac +dOK8BwWINJdUZ6JqMzx5+on2WQBTXMkjU5/dpYHZkB0pq5SWZf3iupUz1ND8hxpr59n JZiHlYK8o1BQQX5a6ifwOng2BqU3ND/q1hbzCk6cC8uiUcl+/62WQIuEePmgXwTNg75g fpj85YwxlfkW0OO4Dn2auZiCrDsnId9UM6dzRt1ZGsySMrNDMN40l02BnMd1jiaddltL m92Rps7NJzrwt1iG/q+x89o+iissEUF10cLSf0tWqV6zOEYNxWE6wtXE256orQt0/cQP roJg== 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 :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=rsZUhCqOgnamQl7VD6DZTmpT0RFN+UimQXsLgsbvkVw=; b=VMxDuNqJQ9ouTu8Jk0mkzGv0iQH6N0w8vQRqH2rcEvWEBN0o8Qd7VQbDjwBf+etMLN PMubL66yElZ9aN5Iow3ODhukja0eolvxz+aRociNQyu6k9hY/Z5OZRUf+6EiJ4Fd4dfb CGrcy6vwKA973DmjokHjJM5T+4U0BQPcQw68qJGx5ITLOz1UBYggAkStWFGQWkwfumVL Rc270cdgAr4gH75NeGz5xFasmN7UW2aqwkwk1D0lkWl5psuTff0LVTbNMdGvSj6y1tth dtICKKDpThgYUfuqbIQiFFH/6wnvb3tPnmYcBsoKHLV3nLD+zZ1u+Bqh9H774Pj6Bngi LdIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=xt2z7rfu; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id gs24-20020a170906f19800b0073d9b010076si1139139ejb.822.2022.08.24.01.14.37 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 01:14:37 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=xt2z7rfu; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 0DF0D3856DCA for <ouuuleilei@gmail.com>; Wed, 24 Aug 2022 08:14:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0DF0D3856DCA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661328876; bh=rsZUhCqOgnamQl7VD6DZTmpT0RFN+UimQXsLgsbvkVw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=xt2z7rfuPtcYGaLAPbUQdjMuMiWLcpztrkUaqvEdZOXSROA/cV4g80R49kmbQZCnW r/puHAG+gQ6sL9sis8Y/qPH/kdou+zUbO8BTWFMnY14fhT3q08sLzSXd07VCHXnqxl I9t+GXS2uyx2lnb5KTGf0yZEYcwS4wDX3DAfCrRQ= 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 0EADA38582BE; Wed, 24 Aug 2022 08:13:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0EADA38582BE Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27O7Uj9D027518; Wed, 24 Aug 2022 08:13:51 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3j5fnr9cd7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 24 Aug 2022 08:13:50 +0000 Received: from m0187473.ppops.net (m0187473.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 27O7Uwod027923; Wed, 24 Aug 2022 08:13:50 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3j5fnr9cc5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 24 Aug 2022 08:13:50 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 27O85N4i019228; Wed, 24 Aug 2022 08:13:47 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma03ams.nl.ibm.com with ESMTP id 3j2q88vtv9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 24 Aug 2022 08:13:47 +0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 27O8E5aa36634962 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Aug 2022 08:14:06 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7F798AE045; Wed, 24 Aug 2022 08:13:45 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B3649AE04D; Wed, 24 Aug 2022 08:13:44 +0000 (GMT) Received: from pike.rch.stglabs.ibm.com (unknown [9.5.12.127]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 24 Aug 2022 08:13:44 +0000 (GMT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] rs6000: using li/lis+oris/xoris to build constants Date: Wed, 24 Aug 2022 16:13:44 +0800 Message-Id: <20220824081344.70468-1-guojiufu@linux.ibm.com> X-Mailer: git-send-email 2.17.1 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 9Abg-WwY5eNLeLwm2kiT4sth4OeDljw6 X-Proofpoint-GUID: PLIClu_JxSxXFClY0mj095PmcUQAsGV0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-24_04,2022-08-22_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1011 malwarescore=0 bulkscore=0 lowpriorityscore=0 mlxlogscore=999 phishscore=0 impostorscore=0 suspectscore=0 mlxscore=0 priorityscore=1501 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208240032 X-Spam-Status: No, score=-12.1 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, 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Jiufu Guo via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Jiufu Guo <guojiufu@linux.ibm.com> Cc: dje.gcc@gmail.com, segher@kernel.crashing.org, linkw@gcc.gnu.org Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1742029588797762338?= X-GMAIL-MSGID: =?utf-8?q?1742029588797762338?= |
Series |
rs6000: using li/lis+oris/xoris to build constants
|
|
Commit Message
Jiufu Guo
Aug. 24, 2022, 8:13 a.m. UTC
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. 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. 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
Comments
Jiufu Guo <guojiufu@linux.ibm.com> writes: Gentle ping: https://gcc.gnu.org/pipermail/gcc-patches/2022-August/600189.html BR, Jeff(Jiufu) > 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. > > 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. > > 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)); > + emit_move_insn (dest, gen_rtx_IOR (DImode, copy_rtx (temp), > + GEN_INT (ud2 << 16))); > + } > + 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))); > + } > 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 } } */ > + > +#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 */ > +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 > @@ -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; > +}
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; > +}
"Kewen.Lin" <linkw@linux.ibm.com> writes: > 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. > Great, thanks for sugguestions! >> 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? Thanks. > >> >> 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? Yeap, thanks! > >> + 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. Great, thanks for point out this. You are right, this would save some checking. > >> + 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. OK, thanks! > >> +#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. */ > OK, thanks. >> +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? Ok, thanks! > > 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; >> +}
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)); + emit_move_insn (dest, gen_rtx_IOR (DImode, copy_rtx (temp), + GEN_INT (ud2 << 16))); + } + 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))); + } 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 } } */ + +#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 */ +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 @@ -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; +}