From patchwork Wed Oct 26 11:40:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiufu Guo X-Patchwork-Id: 11207 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp210828wru; Wed, 26 Oct 2022 04:41:50 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5QYEmpeOwxTiEkAH0LoluRoO7sz/UwmumValJW+PgYig4o0uVEELviImq7kuviLklIruDx X-Received: by 2002:a17:906:ef8c:b0:78d:4a00:7c7b with SMTP id ze12-20020a170906ef8c00b0078d4a007c7bmr37716453ejb.187.1666784510094; Wed, 26 Oct 2022 04:41:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666784510; cv=none; d=google.com; s=arc-20160816; b=fr5IuV48T7rrCwI1YJ3/6UxY/b+WpECN4/BJlAXKVEFGX7f95bIYaQh2Ez4K0C2XP6 S9NaEA0LVSyBjThWPr0VNQepT/hGB5oFnZe0t17G5dCCkjScCdRCadne+taieXhXAi1z RZlKcDA38Elz7grJ10V+UeTGrWMyyWJ0J1XRp5h9EzS6hUrMOhuW1lJfDHzOY+kn72/h c1Ej5ZGYoA7GUDCA10kV7vQqvJHRwcjeadGTa6FrriXdpy58v1TFkAETVNKkgbgtpisH HRUaXGF6VtDIIRjRcCXzcw1bYkXTkTneVxNZaBOTcnRep9DG4+CVuIT5Vq1MzXhnxtiU a1jw== 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=/zagFz9GWNh48zCK0l8ume/419+nZ1bEL2K66kmTjT0=; b=y5R7Ab/LLfjKVUlRyGQRjvjajfBjZMQkIIWWpchUmSmEazSCVq0nu9kFidzX3UEhVf McjKmpfa/awZXYqXMkHeJ0YIbRpLOevH39GunGKmsS8b8BcuyVcE4zo7rqH6cMfT4xVq y+0m+MX+FeioQaNXkCjQBU3m5enFCdF7JFh6UQG1ZaBx4l45JHR/obazUakpj/rdk17s v8zYD3itmPU+BFX8/FQ1S3+EfBwAktlSjhHagthvxwnzwH6Q7rTqKhlcPKfMKR01Ebu5 KrClBBi9eqFtUSSb10ciQs7JanwNGb68dZSTIfg3zvLY4HocF5IHlKv1bx59r3ARzEwu m3Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=INfj3FH5; 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 f14-20020a0564021e8e00b00451d5c11293si6589813edf.496.2022.10.26.04.41.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 04:41:50 -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=INfj3FH5; 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 D3611385D0C1 for ; Wed, 26 Oct 2022 11:41:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D3611385D0C1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666784508; bh=/zagFz9GWNh48zCK0l8ume/419+nZ1bEL2K66kmTjT0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=INfj3FH5RpYcu/qIEpORCm2kFKcqR6UikZx+gNWR1X8dQiyHTKszudD51ySZv2uhl ocQyoCrDbd8HhnMF0QgR4c48c45YRkqW0NSBtUyrVgvgOWvA7/9pCSMacpggfX59/6 nYgukpIRcIybaAbMtMxO7AsfnGz0bDALDCgvi3PA= 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 E5CB13857370; Wed, 26 Oct 2022 11:40:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E5CB13857370 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 29QAd0ru001728; Wed, 26 Oct 2022 11:40:59 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3kf09fg6jv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 Oct 2022 11:40:58 +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 29Q9tcJx013784; Wed, 26 Oct 2022 11:40:58 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 3kf09fg6j2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 Oct 2022 11:40:57 +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 29QBaFek007449; Wed, 26 Oct 2022 11:40:56 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma05fra.de.ibm.com with ESMTP id 3kc85965uj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 Oct 2022 11:40:56 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 29QBfSKi52429304 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 Oct 2022 11:41:28 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AED23A405C; Wed, 26 Oct 2022 11:40:53 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E41E8A4054; Wed, 26 Oct 2022 11:40:52 +0000 (GMT) Received: from pike.rch.stglabs.ibm.com (unknown [9.5.12.127]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 26 Oct 2022 11:40:52 +0000 (GMT) To: gcc-patches@gcc.gnu.org Subject: [PATCH V2] rs6000: Support to build constants by li/lis+oris/xoris Date: Wed, 26 Oct 2022 19:40:52 +0800 Message-Id: <20221026114052.17713-1-guojiufu@linux.ibm.com> X-Mailer: git-send-email 2.17.1 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: qV7v3jyf2TNFJ_etPkQmg_Vptc91bHsh X-Proofpoint-ORIG-GUID: CUPIQTeb_7DhjypUJwyDI7JPf0gKnfcA 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-26_05,2022-10-26_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 priorityscore=1501 adultscore=0 mlxscore=0 clxscore=1015 spamscore=0 lowpriorityscore=0 suspectscore=0 bulkscore=0 phishscore=0 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2210260064 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 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: Jiufu Guo via Gcc-patches From: Jiufu Guo Reply-To: Jiufu Guo 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" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747750234567760493?= X-GMAIL-MSGID: =?utf-8?q?1747750234567760493?= 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'. Here N(M) means N continuous bit M, x for M means it is ok for either 1 or 0; '||' means concatenation. 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): Support constants which can be built with li + oris or li/lis + xoris. gcc/testsuite/ChangeLog: * gcc.target/powerpc/pr106708-run.c: New test. * gcc.target/powerpc/pr106708.c: New test. * gcc.target/powerpc/pr106708.h: New file. --- gcc/config/rs6000/rs6000.cc | 41 ++++++++++++++----- .../gcc.target/powerpc/pr106708-run.c | 17 ++++++++ gcc/testsuite/gcc.target/powerpc/pr106708.c | 12 ++++++ gcc/testsuite/gcc.target/powerpc/pr106708.h | 9 ++++ 4 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/gcc.target/powerpc/pr106708-run.c create mode 100644 gcc/testsuite/gcc.target/powerpc/pr106708.c create mode 100644 gcc/testsuite/gcc.target/powerpc/pr106708.h diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc index d2743f7bce6..9b7a51f052d 100644 --- a/gcc/config/rs6000/rs6000.cc +++ b/gcc/config/rs6000/rs6000.cc @@ -10228,6 +10228,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; @@ -10253,21 +10254,41 @@ rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c) gen_rtx_IOR (DImode, copy_rtx (temp), GEN_INT (ud1))); } + 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 (temp, GEN_INT (imm)); + emit_move_insn (dest, gen_rtx_XOR (DImode, temp, + GEN_INT (orig_c ^ imm))); + } else if (ud3 == 0 && ud4 == 0) { temp = !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode); gcc_assert (ud2 & 0x8000); - emit_move_insn (copy_rtx (temp), - GEN_INT (((ud2 << 16) ^ 0x80000000) - 0x80000000)); - if (ud1 != 0) - emit_move_insn (copy_rtx (temp), - gen_rtx_IOR (DImode, copy_rtx (temp), - GEN_INT (ud1))); - emit_move_insn (dest, - gen_rtx_ZERO_EXTEND (DImode, - gen_lowpart (SImode, - copy_rtx (temp)))); + + if (!(ud1 & 0x8000)) + { + /* li+oris */ + emit_move_insn (temp, GEN_INT (ud1)); + emit_move_insn (dest, + gen_rtx_IOR (DImode, temp, GEN_INT (ud2 << 16))); + } + else + { + emit_move_insn (temp, + GEN_INT (((ud2 << 16) ^ 0x80000000) - 0x80000000)); + if (ud1 != 0) + emit_move_insn (temp, gen_rtx_IOR (DImode, temp, GEN_INT (ud1))); + emit_move_insn (dest, + gen_rtx_ZERO_EXTEND (DImode, + gen_lowpart (SImode, temp))); + } } else if (ud1 == ud3 && ud2 == ud4) { diff --git a/gcc/testsuite/gcc.target/powerpc/pr106708-run.c b/gcc/testsuite/gcc.target/powerpc/pr106708-run.c new file mode 100644 index 00000000000..df65c321f6b --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr106708-run.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; +} diff --git a/gcc/testsuite/gcc.target/powerpc/pr106708.c b/gcc/testsuite/gcc.target/powerpc/pr106708.c new file mode 100644 index 00000000000..ebd9ea88993 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr106708.c @@ -0,0 +1,12 @@ +/* PR target/106708 */ +/* { dg-do compile } } */ +/* { dg-options "-O2 -mdejagnu-cpu=power8" } */ +/* { dg-require-effective-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..42526a70892 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr106708.h @@ -0,0 +1,9 @@ +/* Test constants which can be built by li/lis + oris/xoris */ +void __attribute__ ((__noinline__, __noclone__)) foo (long long *arg) +{ + *arg++ = 0x98765432ULL; + *arg++ = 0xffffffff7cdeab55ULL; + *arg++ = 0xffffffff65430000ULL; +} + +