From patchwork Thu Jun 8 01:55:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiufu Guo X-Patchwork-Id: 104789 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp607350vqr; Wed, 7 Jun 2023 18:57:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6IQnlPNoZvji21zYhin/IBGyQ7zRRPffggPKsQWDNwcg0Am6QQGkLkpxrhJSLfPUCA7oU9 X-Received: by 2002:aa7:c3c3:0:b0:516:3261:17d with SMTP id l3-20020aa7c3c3000000b005163261017dmr5647281edr.20.1686189445672; Wed, 07 Jun 2023 18:57:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686189445; cv=none; d=google.com; s=arc-20160816; b=HLiF+Aa8a0UaleE+SJsBXwJeflM2BrWnJkUK8psa6RyYxy8yR9DYrH2cITIAjgyAHB APdmcYkl7wN257CtkAeLIkbjd2dErCaL8sNoCRfCTxzK4S2gu3vlqXRhE0SiIWOafNpd By5i5h2XtZ5DxJrCgkL9YZDqkt6Yt6/9VLl9j+zG3K0OfLouxcFx7oh/vQQT2pStM/Tx Apw7Y2yt00yFFObRiDwS49oWxaBNBjhY1lJUC2pe1rgc/AmjxH9bApkvG+mO07Ik0KYm gA7AnUjbdcvj0WK8+1Qv0eFbZvo4QhVjetcS7DvDr664ztVPJ4LtqMUxe7niMh1dEOL5 5EZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=wNEyusIWY43fEIVP3RCwie2qZAkKAVHbIhCMS25ro3Y=; b=JrBSF++CnCcwaUyWRI+2cTE8NIGQ9245A3YgRd+PFcV0y6nz8fMONH1T+T3eq9iv3S PYtBWCSyKmlVGJm/a/MCs0OkfQDRZouE6sCrCEZoW3TVuEj3/bnFAwEwmyxxQERv50yb DeixzNTbi+QJJYo33l2r7HoTZdAezPFqiZBcAVu1SYo7T0ACjVECrCB7R/yLp9y1vEsE /polXLquwwdqQK3vF/t4D/yXBW6n1D6PVcgu0Sd2ex7SBuU9h/Ar7hLQbwCHHKYR4aFa YO+LZm5LmQVFvsrU+RMPf5oMEnu3BW5i9YXdESZLErKJlRkrsxzHmV32VvyDVuO/r7CF K8dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=RfG69tqH; 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 e8-20020a50fb88000000b00514c43cdea1si9413275edq.478.2023.06.07.18.57.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 18:57:25 -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=RfG69tqH; 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 2CE0C3855593 for ; Thu, 8 Jun 2023 01:56:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2CE0C3855593 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686189418; bh=wNEyusIWY43fEIVP3RCwie2qZAkKAVHbIhCMS25ro3Y=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=RfG69tqH5tAjEb4jvExY1NhuvwFkYZg/VpSzWV8/thgz6Ydd97iI8T+eyWitXCcYC LDK1fgfksdu7NxB56P+lUcffsGBCP7Zf0vLwW4bNLV0j7E3XyP5Mc9AT/bsbErbhPL Ckwjc36IrMjSzledCo2Xuz0IvBLW/e1XUges/WPQ= 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 A008E3857701; Thu, 8 Jun 2023 01:55:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A008E3857701 Received: from pps.filterd (m0353726.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3581lrj8026004; Thu, 8 Jun 2023 01:55:57 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3r35mm8426-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Jun 2023 01:55:57 +0000 Received: from m0353726.ppops.net (m0353726.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3581p9o9002230; Thu, 8 Jun 2023 01:55:56 GMT Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3r35mm841j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Jun 2023 01:55:56 +0000 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3580mZwS026662; Thu, 8 Jun 2023 01:55:54 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma04fra.de.ibm.com (PPS) with ESMTPS id 3r2a7a8pay-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Jun 2023 01:55:54 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3581touS9175768 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 8 Jun 2023 01:55:50 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C058420043; Thu, 8 Jun 2023 01:55:50 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A932420040; Thu, 8 Jun 2023 01:55:49 +0000 (GMT) Received: from ltcden2-lp1.aus.stglabs.ibm.com (unknown [9.3.90.43]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 8 Jun 2023 01:55:49 +0000 (GMT) To: gcc-patches@gcc.gnu.org Cc: segher@kernel.crashing.org, dje.gcc@gmail.com, linkw@gcc.gnu.org, bergner@linux.ibm.com, guojiufu@linux.ibm.com Subject: [PATCH 1/4] rs6000: build constant via li;rotldi Date: Thu, 8 Jun 2023 09:55:44 +0800 Message-Id: <20230608015547.3432691-2-guojiufu@linux.ibm.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230608015547.3432691-1-guojiufu@linux.ibm.com> References: <20230608015547.3432691-1-guojiufu@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: WZ95gYwDmqqFJLe0jrjOYnz-4PrKUjhg X-Proofpoint-GUID: n_iaWGo5hcV5f7vHcMLNr5xnkFi1o3C7 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-07_13,2023-06-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 mlxlogscore=999 priorityscore=1501 impostorscore=0 phishscore=0 mlxscore=0 spamscore=0 adultscore=0 lowpriorityscore=0 suspectscore=0 malwarescore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306080010 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, 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: Jiufu Guo via Gcc-patches From: Jiufu Guo Reply-To: Jiufu Guo 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?1768097784460051506?= X-GMAIL-MSGID: =?utf-8?q?1768097784460051506?= Hi, This patch checks if a constant is possible to be rotated to/from a positive or negative value from "li". If so, we could use "li;rotldi" to build it. Bootstrap and regtest pass on ppc64{,le}. Is this ok for trunk? BR, Jeff (Jiufu) gcc/ChangeLog: * config/rs6000/rs6000.cc (can_be_rotated_to_positive_li): New function. (can_be_rotated_to_negative_li): New function. (can_be_built_by_li_and_rotldi): New function. (rs6000_emit_set_long_const): Call can_be_built_by_li_and_rotldi. gcc/testsuite/ChangeLog: * gcc.target/powerpc/const-build.c: New test. --- gcc/config/rs6000/rs6000.cc | 64 +++++++++++++++++-- .../gcc.target/powerpc/const-build.c | 54 ++++++++++++++++ 2 files changed, 112 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.target/powerpc/const-build.c diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc index 42f49e4a56b..1dd0072350a 100644 --- a/gcc/config/rs6000/rs6000.cc +++ b/gcc/config/rs6000/rs6000.cc @@ -10258,6 +10258,48 @@ rs6000_emit_set_const (rtx dest, rtx source) return true; } +/* Check if C can be rotated to a positive value which 'li' instruction + is able to load. If so, set *ROT to the number by which C is rotated, + and return true. Return false otherwise. */ + +static bool +can_be_rotated_to_positive_li (HOST_WIDE_INT c, int *rot) +{ + /* 49 leading zeros and 15 low bits on the positive value + generated by 'li' instruction. */ + return can_be_rotated_to_lowbits (c, 15, rot); +} + +/* Like can_be_rotated_to_positive_li, but check the negative value of 'li'. */ + +static bool +can_be_rotated_to_negative_li (HOST_WIDE_INT c, int *rot) +{ + return can_be_rotated_to_lowbits (~c, 15, rot); +} + +/* Check if value C can be built by 2 instructions: one is 'li', another is + rotldi. + + If so, *SHIFT is set to the shift operand of rotldi(rldicl), and *MASK + is set to -1, and return true. Return false otherwise. */ + +static bool +can_be_built_by_li_and_rotldi (HOST_WIDE_INT c, int *shift, + HOST_WIDE_INT *mask) +{ + int n; + if (can_be_rotated_to_positive_li (c, &n) + || can_be_rotated_to_negative_li (c, &n)) + { + *mask = HOST_WIDE_INT_M1; + *shift = HOST_BITS_PER_WIDE_INT - n; + return true; + } + + return false; +} + /* Subroutine of rs6000_emit_set_const, handling PowerPC64 DImode. Output insns to set DEST equal to the constant C as a series of lis, ori and shl instructions. */ @@ -10266,15 +10308,14 @@ static void rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c) { rtx temp; + int shift; + HOST_WIDE_INT mask; HOST_WIDE_INT ud1, ud2, ud3, ud4; ud1 = c & 0xffff; - c = c >> 16; - ud2 = c & 0xffff; - c = c >> 16; - ud3 = c & 0xffff; - c = c >> 16; - ud4 = c & 0xffff; + ud2 = (c >> 16) & 0xffff; + ud3 = (c >> 32) & 0xffff; + ud4 = (c >> 48) & 0xffff; if ((ud4 == 0xffff && ud3 == 0xffff && ud2 == 0xffff && (ud1 & 0x8000)) || (ud4 == 0 && ud3 == 0 && ud2 == 0 && ! (ud1 & 0x8000))) @@ -10305,6 +10346,17 @@ rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c) emit_move_insn (dest, gen_rtx_XOR (DImode, temp, GEN_INT ((ud2 ^ 0xffff) << 16))); } + else if (can_be_built_by_li_and_rotldi (c, &shift, &mask)) + { + temp = !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode); + unsigned HOST_WIDE_INT imm = (c | ~mask); + imm = (imm >> shift) | (imm << (HOST_BITS_PER_WIDE_INT - shift)); + + emit_move_insn (temp, GEN_INT (imm)); + if (shift != 0) + temp = gen_rtx_ROTATE (DImode, temp, GEN_INT (shift)); + emit_move_insn (dest, temp); + } else if (ud3 == 0 && ud4 == 0) { temp = !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode); diff --git a/gcc/testsuite/gcc.target/powerpc/const-build.c b/gcc/testsuite/gcc.target/powerpc/const-build.c new file mode 100644 index 00000000000..70f095f6bf2 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/const-build.c @@ -0,0 +1,54 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -save-temps" } */ +/* { dg-require-effective-target has_arch_ppc64 } */ + +#define NOIPA __attribute__ ((noipa)) + +struct fun +{ + long long (*f) (void); + long long val; +}; + +long long NOIPA +li_rotldi_1 (void) +{ + return 0x7531000000000LL; +} + +long long NOIPA +li_rotldi_2 (void) +{ + return 0x2100000000000064LL; +} + +long long NOIPA +li_rotldi_3 (void) +{ + return 0xffff8531ffffffffLL; +} + +long long NOIPA +li_rotldi_4 (void) +{ + return 0x21ffffffffffff94LL; +} + +struct fun arr[] = { + {li_rotldi_1, 0x7531000000000LL}, + {li_rotldi_2, 0x2100000000000064LL}, + {li_rotldi_3, 0xffff8531ffffffffLL}, + {li_rotldi_4, 0x21ffffffffffff94LL}, +}; + +/* { dg-final { scan-assembler-times {\mrotldi\M} 4 } } */ + +int +main () +{ + for (int i = 0; i < sizeof (arr) / sizeof (arr[0]); i++) + if ((*arr[i].f) () != arr[i].val) + __builtin_abort (); + + return 0; +} From patchwork Thu Jun 8 01:55:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiufu Guo X-Patchwork-Id: 104792 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp607758vqr; Wed, 7 Jun 2023 18:58:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4O0umSXgG7sGoxqmC3SuNeo0+txdiw3zrcWHX021ys1vyHUtuTxuYW0LkxE1RJO9Rm+mFF X-Received: by 2002:aa7:c79a:0:b0:510:dd3e:86cd with SMTP id n26-20020aa7c79a000000b00510dd3e86cdmr6231886eds.20.1686189529112; Wed, 07 Jun 2023 18:58:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686189529; cv=none; d=google.com; s=arc-20160816; b=gNH2/KV4m3NJsTrjtvh3+Kr5u56JpUL1L8XzgC6PoivD70W634e99dPj+VHjd0PEsZ 46oPHxEW4vgDPvCa/waLR9gZMqL/T8yJV9qqHtKcxmXIHAttQF5BuraFhumjPDEansJN YNnIO/i+IM1cMFv/ekVzLdOLO2TelnasmHVxFBxJUS+iVd1NuhFsm/ovuDsqa/8mz/nO 74q7EgveOz/kiRYbJygDU3aOGQNsELor5/OIO2sTbG9pp3FXBp0sHAYkOfsnr16FkqTl uvDFDewsJ57FUyH6n8kXa5c96EW7Q43dvrSNEIA1gAQEeawDIWL8vT4t7+2szTFsxNP+ W1Gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=tYB9sSX8DgnVDY/qOM+dtTaVvffnzAWKgVCXy6lcMno=; b=GthLdCOG+K8kNnLgDe95xPrMJlhahsHzyPF9ki5eISmQ1iO9lq6WKAEIXxF+SnYes6 +T5R6Xe3nxUi8dPviRDId+04Q9yjacwnj3CfkLZ2PLK7R0SCvmyKetGsPM0M9sY+M3Bc wk2vsMw0dFhtJfxcr6dpK4ekJjCNcGzd6NiQmTrp2qZPO//tkNnXqewm1BTYno2Ndfx1 eVMnzgtOkywS/4sl/yW0x/y3TUKxL9MfQhBg4KtTq+yRNM58rZDNa0mZUt+8gzgTMW/V 2LQ6yH8+TYn4hDQAKecn+Ime4MJqMtW/1DI4dsKhyUBpl5SFJVIHAd5dWdsY5mu3f0PE rCJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uVQQf1L6; 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 m13-20020a056402050d00b0051640a104b8si8372813edv.223.2023.06.07.18.58.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 18:58:49 -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=uVQQf1L6; 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 B1439385588B for ; Thu, 8 Jun 2023 01:58:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B1439385588B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686189483; bh=tYB9sSX8DgnVDY/qOM+dtTaVvffnzAWKgVCXy6lcMno=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=uVQQf1L6ZemF4hvLLuYwTb0zcPw6W0x5/e2kODhXAtc0yBERYv+Mm62dsDIJcqpQ6 cdD8LZN/u3g6ISsmI9ds4N6asyDHVuPMtsPcNqBlJuwdr55/X/iYpEswGy/TB/DaME sem7oIkBTb6vqRmtvSc2bppwUqarRztdmSXfvuTw= 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 E0E9E3857B9B; Thu, 8 Jun 2023 01:55:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E0E9E3857B9B Received: from pps.filterd (m0353728.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3581kB07017091; Thu, 8 Jun 2023 01:55:59 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3r35m7g5qn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Jun 2023 01:55:58 +0000 Received: from m0353728.ppops.net (m0353728.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3581nxgO027539; Thu, 8 Jun 2023 01:55:58 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 3r35m7g5px-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Jun 2023 01:55:58 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 357NGJe8028917; Thu, 8 Jun 2023 01:55:55 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3r2a77gyp0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Jun 2023 01:55:55 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3581tqsh18678294 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 8 Jun 2023 01:55:52 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 327602004B; Thu, 8 Jun 2023 01:55:52 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0BBFA20043; Thu, 8 Jun 2023 01:55:51 +0000 (GMT) Received: from ltcden2-lp1.aus.stglabs.ibm.com (unknown [9.3.90.43]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 8 Jun 2023 01:55:50 +0000 (GMT) To: gcc-patches@gcc.gnu.org Cc: segher@kernel.crashing.org, dje.gcc@gmail.com, linkw@gcc.gnu.org, bergner@linux.ibm.com, guojiufu@linux.ibm.com Subject: [PATCH 2/4] rs6000: build constant via lis;rotldi Date: Thu, 8 Jun 2023 09:55:45 +0800 Message-Id: <20230608015547.3432691-3-guojiufu@linux.ibm.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230608015547.3432691-1-guojiufu@linux.ibm.com> References: <20230608015547.3432691-1-guojiufu@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: mAEhwF1yek56ReiTRwlFVpxz29FuGvu0 X-Proofpoint-ORIG-GUID: oOQnxutJkoY2sbM-99ia2PM434tLZD_q X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-07_13,2023-06-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 mlxlogscore=999 lowpriorityscore=0 bulkscore=0 phishscore=0 impostorscore=0 clxscore=1015 adultscore=0 spamscore=0 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306080010 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, 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: Jiufu Guo via Gcc-patches From: Jiufu Guo Reply-To: Jiufu Guo 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?1768097871866674182?= X-GMAIL-MSGID: =?utf-8?q?1768097871866674182?= Hi, This patch checks if a constant is possible to be rotated to/from a negative value from "lis". If so, we could use "lis;rotldi" to build it. The positive value of "lis" does not need to be analyzed. Because if a constant can be rotated from the positive value of "lis", it also can be rotated from a positive value of "li". Bootstrap and regtest pass on ppc64{,le}. Is this ok for trunk? BR, Jeff (Jiufu) gcc/ChangeLog: * config/rs6000/rs6000.cc (can_be_rotated_to_negative_lis): New function. (can_be_built_by_li_and_rotldi): Rename to ... (can_be_built_by_li_lis_and_rotldi): ... this function. (rs6000_emit_set_long_const): Call can_be_built_by_li_lis_and_rotldi. gcc/testsuite/ChangeLog: * gcc.target/powerpc/const-build.c: Add more tests. --- gcc/config/rs6000/rs6000.cc | 42 ++++++++++++++++--- .../gcc.target/powerpc/const-build.c | 16 ++++++- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc index 1dd0072350a..03cd9d5e952 100644 --- a/gcc/config/rs6000/rs6000.cc +++ b/gcc/config/rs6000/rs6000.cc @@ -10278,19 +10278,51 @@ can_be_rotated_to_negative_li (HOST_WIDE_INT c, int *rot) return can_be_rotated_to_lowbits (~c, 15, rot); } -/* Check if value C can be built by 2 instructions: one is 'li', another is - rotldi. +/* Check if C can be rotated to a negative value which 'lis' instruction is + able to load: 1..1xx0..0. If so, set *ROT to the number by which C is + rotated, and return true. Return false otherwise. */ + +static bool +can_be_rotated_to_negative_lis (HOST_WIDE_INT c, int *rot) +{ + /* case a. 1..1xxx0..01..1: up to 15 x's, at least 16 0's. */ + int leading_ones = clz_hwi (~c); + int tailing_ones = ctz_hwi (~c); + int middle_zeros = ctz_hwi (c >> tailing_ones); + if (middle_zeros >= 16 && leading_ones + tailing_ones >= 33) + { + *rot = HOST_BITS_PER_WIDE_INT - tailing_ones; + return true; + } + + /* case b. xx0..01..1xx: some of 15 x's (and some of 16 0's) are + rotated over the highest bit. */ + int pos_one = clz_hwi ((c << 16) >> 16); + middle_zeros = ctz_hwi (c >> (HOST_BITS_PER_WIDE_INT - pos_one)); + int middle_ones = clz_hwi (~(c << pos_one)); + if (middle_zeros >= 16 && middle_ones >= 33) + { + *rot = pos_one; + return true; + } + + return false; +} + +/* Check if value C can be built by 2 instructions: one is 'li or lis', + another is rotldi. If so, *SHIFT is set to the shift operand of rotldi(rldicl), and *MASK is set to -1, and return true. Return false otherwise. */ static bool -can_be_built_by_li_and_rotldi (HOST_WIDE_INT c, int *shift, +can_be_built_by_li_lis_and_rotldi (HOST_WIDE_INT c, int *shift, HOST_WIDE_INT *mask) { int n; if (can_be_rotated_to_positive_li (c, &n) - || can_be_rotated_to_negative_li (c, &n)) + || can_be_rotated_to_negative_li (c, &n) + || can_be_rotated_to_negative_lis (c, &n)) { *mask = HOST_WIDE_INT_M1; *shift = HOST_BITS_PER_WIDE_INT - n; @@ -10346,7 +10378,7 @@ rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c) emit_move_insn (dest, gen_rtx_XOR (DImode, temp, GEN_INT ((ud2 ^ 0xffff) << 16))); } - else if (can_be_built_by_li_and_rotldi (c, &shift, &mask)) + else if (can_be_built_by_li_lis_and_rotldi (c, &shift, &mask)) { temp = !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode); unsigned HOST_WIDE_INT imm = (c | ~mask); diff --git a/gcc/testsuite/gcc.target/powerpc/const-build.c b/gcc/testsuite/gcc.target/powerpc/const-build.c index 70f095f6bf2..c38a1dd91f2 100644 --- a/gcc/testsuite/gcc.target/powerpc/const-build.c +++ b/gcc/testsuite/gcc.target/powerpc/const-build.c @@ -34,14 +34,28 @@ li_rotldi_4 (void) return 0x21ffffffffffff94LL; } +long long NOIPA +lis_rotldi_5 (void) +{ + return 0xffff85310000ffffLL; +} + +long long NOIPA +lis_rotldi_6 (void) +{ + return 0x5310000ffffffff8LL; +} + struct fun arr[] = { {li_rotldi_1, 0x7531000000000LL}, {li_rotldi_2, 0x2100000000000064LL}, {li_rotldi_3, 0xffff8531ffffffffLL}, {li_rotldi_4, 0x21ffffffffffff94LL}, + {lis_rotldi_5, 0xffff85310000ffffLL}, + {lis_rotldi_6, 0x5310000ffffffff8LL}, }; -/* { dg-final { scan-assembler-times {\mrotldi\M} 4 } } */ +/* { dg-final { scan-assembler-times {\mrotldi\M} 6 } } */ int main () From patchwork Thu Jun 8 01:55:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiufu Guo X-Patchwork-Id: 104791 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp607723vqr; Wed, 7 Jun 2023 18:58:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4vu1YLWbvj6oZ7DSPKaeLHJ1YVIvujZm5Of6+EDlpAqWWupvmK/UaQupUgJpJh1/T75BrR X-Received: by 2002:aa7:d898:0:b0:50c:358:1eba with SMTP id u24-20020aa7d898000000b0050c03581ebamr5381686edq.35.1686189522605; Wed, 07 Jun 2023 18:58:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686189522; cv=none; d=google.com; s=arc-20160816; b=ovW9pRHpZFX+6NLt/QM3ifNWFr/RyNX1qJ31pBDNIute0Gn579/ONH3mJvuPndmKDs mBtS9o9hZ7QubVRdy1vxqluBWCcUNkEQySeO398eOWgl7Uv0K1yR9L+jHSF1C9B5M+tY toooki1MJ7BOKM91LOsRrwgvKblxiG7XCsj11mOcJdfGTcSNU02fLddQF6Y/srbkGxTr OhP0FU0zMglmUXldJGNQq4t/zD1cG5rOiM5HZUlsmq5KRJX/2g6+03EpjiUkiR6hZMDL Gr+ampawHYEgL7cmQFKcDv3kswVNNC2SvwO1/MfJexSeNjyDgExmf4yNwB6NRq8bhbq5 98EA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=1G0YrAhI+YL8i+0HRBw1u110kmh+K3JwBONcZxw/4qY=; b=SJplKs21SJ2ubvTkjeEq0iJEWixqqVMsz/n1Pqm69cA8dFlPXrSF6AF7GU+OB+J0Mc XElTFlMHN0+hsRk+cIYg7x+wo11FIUiSDoSb4cjHTjXpSGHMISfGIKqB2vHXkn3ztZIL r1bmHuF2qj/+1vtYXAKevVvJA8MKLNAwjvKUiDF6zD73n/ir1QPiez8h40rtP71ViDbV u47QsBKqyM0fMl/CJJoht23Y88WP5XDZIhmjvofRbw8jVSfHDDFRnEuilltnSr1SEo4f Ro3CBEQAnvbL7liD04Z9cDmtx0xehWZ+Ihngf2Puegz9umn81sDgqt+PYz3FyZW2JRgm hA0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pEZkK5ks; 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 h7-20020a50ed87000000b0050bd38fcecbsi8411edr.0.2023.06.07.18.58.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 18:58:42 -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=pEZkK5ks; 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 9B0FC3854E4C for ; Thu, 8 Jun 2023 01:57:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9B0FC3854E4C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686189478; bh=1G0YrAhI+YL8i+0HRBw1u110kmh+K3JwBONcZxw/4qY=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=pEZkK5ksz4EqTLlWVQn5rwHf20y8Qao8nu52m/pbpDO2HDCgIT8WaZ45TSuDmvmY0 k8KAHjgjFfaR8jo8hHzoclcJaUgbK1VbDSoxAnuSQxmwws9hPO4Wn2RYrP4SdvdFsY PYyY/6nll6CKub8CsbLRjD1JCFXCdbar7g44Z8mQ= 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 DFF4E3857354; Thu, 8 Jun 2023 01:56:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DFF4E3857354 Received: from pps.filterd (m0353727.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3581prF1025221; Thu, 8 Jun 2023 01:56:01 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3r35pwg1ds-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Jun 2023 01:56:00 +0000 Received: from m0353727.ppops.net (m0353727.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3581tt3s000936; Thu, 8 Jun 2023 01:56:00 GMT Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3r35pwg1cy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Jun 2023 01:55:59 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3581Hm3Q002884; Thu, 8 Jun 2023 01:55:57 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma06fra.de.ibm.com (PPS) with ESMTPS id 3r2a7a0p6q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Jun 2023 01:55:56 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3581trRD31982156 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 8 Jun 2023 01:55:53 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 86EEF20043; Thu, 8 Jun 2023 01:55:53 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 70C8820040; Thu, 8 Jun 2023 01:55:52 +0000 (GMT) Received: from ltcden2-lp1.aus.stglabs.ibm.com (unknown [9.3.90.43]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 8 Jun 2023 01:55:52 +0000 (GMT) To: gcc-patches@gcc.gnu.org Cc: segher@kernel.crashing.org, dje.gcc@gmail.com, linkw@gcc.gnu.org, bergner@linux.ibm.com, guojiufu@linux.ibm.com Subject: [PATCH 3/4] rs6000: build constant via li/lis;rldicl/rldicr Date: Thu, 8 Jun 2023 09:55:46 +0800 Message-Id: <20230608015547.3432691-4-guojiufu@linux.ibm.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230608015547.3432691-1-guojiufu@linux.ibm.com> References: <20230608015547.3432691-1-guojiufu@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: -g7ZwFAbQcCm6cKn0rgB0ZbyYunnQoDX X-Proofpoint-ORIG-GUID: KEwuGiux7hvg9LFRJX452w9N4ncoFir- X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-07_13,2023-06-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 lowpriorityscore=0 priorityscore=1501 adultscore=0 phishscore=0 clxscore=1015 suspectscore=0 impostorscore=0 mlxlogscore=999 spamscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306080010 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, 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: Jiufu Guo via Gcc-patches From: Jiufu Guo Reply-To: Jiufu Guo 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?1768097864986064445?= X-GMAIL-MSGID: =?utf-8?q?1768097864986064445?= Hi, This patch checks if a constant is possible left/right cleaned on a rotated value from a negative value of "li/lis". If so, we can build the constant through "li/lis ; rldicl/rldicr". Bootstrap and regtest pass on ppc64{,le}. Is this ok for trunk? BR, Jeff (Jiufu) gcc/ChangeLog: * config/rs6000/rs6000.cc (can_be_built_by_li_lis_and_rldicl): New function. (can_be_built_by_li_lis_and_rldicr): New function. (rs6000_emit_set_long_const): Call can_be_built_by_li_lis_and_rldicr and can_be_built_by_li_lis_and_rldicl. gcc/testsuite/ChangeLog: * gcc.target/powerpc/const-build.c: Add more tests. --- gcc/config/rs6000/rs6000.cc | 61 ++++++++++++++++++- .../gcc.target/powerpc/const-build.c | 44 +++++++++++++ 2 files changed, 104 insertions(+), 1 deletion(-) diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc index 03cd9d5e952..2a3fa733b45 100644 --- a/gcc/config/rs6000/rs6000.cc +++ b/gcc/config/rs6000/rs6000.cc @@ -10332,6 +10332,61 @@ can_be_built_by_li_lis_and_rotldi (HOST_WIDE_INT c, int *shift, return false; } +/* Check if value C can be built by 2 instructions: one is 'li or lis', + another is rldicl. + + If so, *SHIFT is set to the shift operand of rldicl, and *MASK is set to + the mask operand of rldicl, and return true. + Return false otherwise. */ + +static bool +can_be_built_by_li_lis_and_rldicl (HOST_WIDE_INT c, int *shift, + HOST_WIDE_INT *mask) +{ + /* Leading zeros may be cleaned by rldicl with a mask. Change leading zeros + to ones and then recheck it. */ + int lz = clz_hwi (c); + HOST_WIDE_INT unmask_c + = c | (HOST_WIDE_INT_M1U << (HOST_BITS_PER_WIDE_INT - lz)); + int n; + if (can_be_rotated_to_negative_li (unmask_c, &n) + || can_be_rotated_to_negative_lis (unmask_c, &n)) + { + *mask = HOST_WIDE_INT_M1U >> lz; + *shift = n == 0 ? 0 : HOST_BITS_PER_WIDE_INT - n; + return true; + } + + return false; +} + +/* Check if value C can be built by 2 instructions: one is 'li or lis', + another is rldicr. + + If so, *SHIFT is set to the shift operand of rldicr, and *MASK is set to + the mask operand of rldicr, and return true. + Return false otherwise. */ + +static bool +can_be_built_by_li_lis_and_rldicr (HOST_WIDE_INT c, int *shift, + HOST_WIDE_INT *mask) +{ + /* Tailing zeros may be cleaned by rldicr with a mask. Change tailing zeros + to ones and then recheck it. */ + int tz = ctz_hwi (c); + HOST_WIDE_INT unmask_c = c | ((HOST_WIDE_INT_1U << tz) - 1); + int n; + if (can_be_rotated_to_negative_li (unmask_c, &n) + || can_be_rotated_to_negative_lis (unmask_c, &n)) + { + *mask = HOST_WIDE_INT_M1U << tz; + *shift = HOST_BITS_PER_WIDE_INT - n; + return true; + } + + return false; +} + /* Subroutine of rs6000_emit_set_const, handling PowerPC64 DImode. Output insns to set DEST equal to the constant C as a series of lis, ori and shl instructions. */ @@ -10378,7 +10433,9 @@ rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c) emit_move_insn (dest, gen_rtx_XOR (DImode, temp, GEN_INT ((ud2 ^ 0xffff) << 16))); } - else if (can_be_built_by_li_lis_and_rotldi (c, &shift, &mask)) + else if (can_be_built_by_li_lis_and_rotldi (c, &shift, &mask) + || can_be_built_by_li_lis_and_rldicl (c, &shift, &mask) + || can_be_built_by_li_lis_and_rldicr (c, &shift, &mask)) { temp = !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode); unsigned HOST_WIDE_INT imm = (c | ~mask); @@ -10387,6 +10444,8 @@ rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c) emit_move_insn (temp, GEN_INT (imm)); if (shift != 0) temp = gen_rtx_ROTATE (DImode, temp, GEN_INT (shift)); + if (mask != HOST_WIDE_INT_M1) + temp = gen_rtx_AND (DImode, temp, GEN_INT (mask)); emit_move_insn (dest, temp); } else if (ud3 == 0 && ud4 == 0) diff --git a/gcc/testsuite/gcc.target/powerpc/const-build.c b/gcc/testsuite/gcc.target/powerpc/const-build.c index c38a1dd91f2..8c209921d41 100644 --- a/gcc/testsuite/gcc.target/powerpc/const-build.c +++ b/gcc/testsuite/gcc.target/powerpc/const-build.c @@ -46,6 +46,42 @@ lis_rotldi_6 (void) return 0x5310000ffffffff8LL; } +long long NOIPA +li_rldicl_7 (void) +{ + return 0x3ffffffa1LL; +} + +long long NOIPA +li_rldicl_8 (void) +{ + return 0xff8531ffffffffLL; +} + +long long NOIPA +lis_rldicl_9 (void) +{ + return 0x00ff85310000ffffLL; +} + +long long NOIPA +li_rldicr_10 (void) +{ + return 0xffff8531fff00000LL; +} + +long long NOIPA +li_rldicr_11 (void) +{ + return 0x21fffffffff00000LL; +} + +long long NOIPA +lis_rldicr_12 (void) +{ + return 0x5310000ffffffff0LL; +} + struct fun arr[] = { {li_rotldi_1, 0x7531000000000LL}, {li_rotldi_2, 0x2100000000000064LL}, @@ -53,9 +89,17 @@ struct fun arr[] = { {li_rotldi_4, 0x21ffffffffffff94LL}, {lis_rotldi_5, 0xffff85310000ffffLL}, {lis_rotldi_6, 0x5310000ffffffff8LL}, + {li_rldicl_7, 0x3ffffffa1LL}, + {li_rldicl_8, 0xff8531ffffffffLL}, + {lis_rldicl_9, 0x00ff85310000ffffLL}, + {li_rldicr_10, 0xffff8531fff00000LL}, + {li_rldicr_11, 0x21fffffffff00000LL}, + {lis_rldicr_12, 0x5310000ffffffff0LL}, }; /* { dg-final { scan-assembler-times {\mrotldi\M} 6 } } */ +/* { dg-final { scan-assembler-times {\mrldicl\M} 3 } } */ +/* { dg-final { scan-assembler-times {\mrldicr\M} 3 } } */ int main () From patchwork Thu Jun 8 01:55:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiufu Guo X-Patchwork-Id: 104790 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp607398vqr; Wed, 7 Jun 2023 18:57:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6OgI4j/84rppOply6d+Q46UuPaKLxhMr6Iv7v/zx32wPr2iNhFMgHmsd58mnz/dp/pIENQ X-Received: by 2002:a17:907:6e94:b0:96f:8ea4:a72c with SMTP id sh20-20020a1709076e9400b0096f8ea4a72cmr9103356ejc.62.1686189456536; Wed, 07 Jun 2023 18:57:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686189456; cv=none; d=google.com; s=arc-20160816; b=W9rH+bjkX7seI4zvuVd6zQm/ZeWQcHTRA0XQl1ZejOF0cDy/If/+vp5ts24fy4M7/J MugNQJnUhHEWB6u+d7K7sNL2kzELTsH9PouSUR2yl4ChGvjt50sccQvdJkrltL4qdNzA lU32f9SuUybYJE/RqXtBGrI4QMKF3WcoOKlROgQn/2L/JtlxNqB9OFlZsogTQMYog8LJ L+hn8GktjGy2hETYw1mT6S7IdR3H/ZlkVid8qBFmLPP4QkmGjtZxIaKa4AFeB2vCnCM4 VsGPN8+b2Hn/j74vaog+BSc1rWaEeHPgdtvW/AeRXZ9OTc3QKXhcYu/zN+o6DcsaSky/ JGxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=vZ8F212OIUzmgKjKuooSozxzpDKNRL3ryNkdmyubneY=; b=0rdQn+CWELUGGdjb3TgRl48rY1c7OIo8BZrMGPULpJd262C8Oxa/ZfmiZQTF+9JTkx DJujgXRQctpX3rNRo3XtxNsNCIi2OQigHas2Aev9rtAOu70qduSmfBUxfCHARn+u1g1q au3Jd7ESlUY4ZNo75o257PZX6uDSyRmbPrcPLrCfZjjhZP9KzNE1ypzwFUz2RU1hP8p3 tqvnc3PYK6R8K4penRMF0is+GXzdELhhWjhPqcLs+FM11FuVCI2BAo09brOuLS/PpskQ r9KA0RjUNDKQx/bo7zolHmehfC3fzGjIBAw5hyMghOVlqG+oQVgPj1lVtNz/C/zPTVEh HKNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=NbQDOGq6; 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 y15-20020a1709060a8f00b0096f4fc49b86si19855ejf.1029.2023.06.07.18.57.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 18:57:36 -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=NbQDOGq6; 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 D1B0C38555A3 for ; Thu, 8 Jun 2023 01:57:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D1B0C38555A3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686189423; bh=vZ8F212OIUzmgKjKuooSozxzpDKNRL3ryNkdmyubneY=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=NbQDOGq60XIrdDxP8OFtzLV+5Z8rGSjzp3+BIPGbtbv56M1te6OyxQWk7Bnm7XzMF 4DGmGN256isLUDg7oK7mqJ3hpwKlpGad8EKpJ+wAYjZbhqByJHGMcFTBNF9ietcLDk d6fDhdlBOD+kcyX5ORwARck/c0ja5+KZwUbemLDs= 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 AD49C3857014; Thu, 8 Jun 2023 01:56:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AD49C3857014 Received: from pps.filterd (m0353722.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3581lJZE001535; Thu, 8 Jun 2023 01:56:01 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3r35mhr48h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Jun 2023 01:56:00 +0000 Received: from m0353722.ppops.net (m0353722.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3581pqkG015321; Thu, 8 Jun 2023 01:56:00 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 3r35mhr484-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Jun 2023 01:56:00 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 357MWKei022262; Thu, 8 Jun 2023 01:55:58 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma03ams.nl.ibm.com (PPS) with ESMTPS id 3r2a768yxb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Jun 2023 01:55:58 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3581tscl21955242 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 8 Jun 2023 01:55:55 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DC1EF20043; Thu, 8 Jun 2023 01:55:54 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C6C4F20040; Thu, 8 Jun 2023 01:55:53 +0000 (GMT) Received: from ltcden2-lp1.aus.stglabs.ibm.com (unknown [9.3.90.43]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 8 Jun 2023 01:55:53 +0000 (GMT) To: gcc-patches@gcc.gnu.org Cc: segher@kernel.crashing.org, dje.gcc@gmail.com, linkw@gcc.gnu.org, bergner@linux.ibm.com, guojiufu@linux.ibm.com Subject: [PATCH 4/4] rs6000: build constant via li/lis;rldic Date: Thu, 8 Jun 2023 09:55:47 +0800 Message-Id: <20230608015547.3432691-5-guojiufu@linux.ibm.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230608015547.3432691-1-guojiufu@linux.ibm.com> References: <20230608015547.3432691-1-guojiufu@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 2xeAJasxACbMGn6OTsK6fz8BS5mFnwj2 X-Proofpoint-GUID: CwCrgwGMEIgJwC8G10bssfbkpZUFjd9q X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-07_13,2023-06-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 lowpriorityscore=0 priorityscore=1501 malwarescore=0 impostorscore=0 spamscore=0 adultscore=0 phishscore=0 suspectscore=0 bulkscore=0 clxscore=1015 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306080010 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, 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: Jiufu Guo via Gcc-patches From: Jiufu Guo Reply-To: Jiufu Guo 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?1768097795454928320?= X-GMAIL-MSGID: =?utf-8?q?1768097795454928320?= Hi, This patch checks if a constant is possible to be built by "li;rldic". We only need to take care of "negative li", other forms do not need to check. For example, "negative lis" is just a "negative li" with an additional shift. Bootstrap and regtest pass on ppc64{,le}. Is this ok for trunk? BR, Jeff (Jiufu) gcc/ChangeLog: * config/rs6000/rs6000.cc (can_be_built_by_li_and_rldic): New function. (rs6000_emit_set_long_const): Call can_be_built_by_li_and_rldic. gcc/testsuite/ChangeLog: * gcc.target/powerpc/const-build.c: Add more tests. --- gcc/config/rs6000/rs6000.cc | 61 ++++++++++++++++++- .../gcc.target/powerpc/const-build.c | 28 +++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc index 2a3fa733b45..cd04b6b5c82 100644 --- a/gcc/config/rs6000/rs6000.cc +++ b/gcc/config/rs6000/rs6000.cc @@ -10387,6 +10387,64 @@ can_be_built_by_li_lis_and_rldicr (HOST_WIDE_INT c, int *shift, return false; } +/* Check if value C can be built by 2 instructions: one is 'li', another is + rldic. + + If so, *SHIFT is set to the 'shift' operand of rldic; and *MASK is set + to the mask value about the 'mb' operand of rldic; and return true. + Return false otherwise. */ + +static bool +can_be_built_by_li_and_rldic (HOST_WIDE_INT c, int *shift, HOST_WIDE_INT *mask) +{ + /* There are 49 successive ones in the negative value of 'li'. */ + int ones = 49; + + /* 1..1xx1..1: negative value of li --> 0..01..1xx0..0: + right bits are shifted as 0's, and left 1's(and x's) are cleaned. */ + int tz = ctz_hwi (c); + int lz = clz_hwi (c); + int middle_ones = clz_hwi (~(c << lz)); + if (tz + lz + middle_ones >= ones) + { + *mask = ((1LL << (HOST_BITS_PER_WIDE_INT - tz - lz)) - 1LL) << tz; + *shift = tz; + return true; + } + + /* 1..1xx1..1 --> 1..1xx0..01..1: some 1's(following x's) are cleaned. */ + int leading_ones = clz_hwi (~c); + int tailing_ones = ctz_hwi (~c); + int middle_zeros = ctz_hwi (c >> tailing_ones); + if (leading_ones + tailing_ones + middle_zeros >= ones) + { + *mask = ~(((1ULL << middle_zeros) - 1ULL) << tailing_ones); + *shift = tailing_ones + middle_zeros; + return true; + } + + /* xx1..1xx: --> xx0..01..1xx: some 1's(following x's) are cleaned. */ + /* Get the position for the first bit of successive 1. + The 24th bit would be in successive 0 or 1. */ + HOST_WIDE_INT low_mask = (1LL << 24) - 1LL; + int pos_first_1 = ((c & (low_mask + 1)) == 0) + ? clz_hwi (c & low_mask) + : HOST_BITS_PER_WIDE_INT - ctz_hwi (~(c | low_mask)); + middle_ones = clz_hwi (~c << pos_first_1); + middle_zeros = ctz_hwi (c >> (HOST_BITS_PER_WIDE_INT - pos_first_1)); + if (pos_first_1 < HOST_BITS_PER_WIDE_INT + && middle_ones + middle_zeros < HOST_BITS_PER_WIDE_INT + && middle_ones + middle_zeros >= ones) + { + *mask = ~(((1ULL << middle_zeros) - 1LL) + << (HOST_BITS_PER_WIDE_INT - pos_first_1)); + *shift = HOST_BITS_PER_WIDE_INT - pos_first_1 + middle_zeros; + return true; + } + + return false; +} + /* Subroutine of rs6000_emit_set_const, handling PowerPC64 DImode. Output insns to set DEST equal to the constant C as a series of lis, ori and shl instructions. */ @@ -10435,7 +10493,8 @@ rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c) } else if (can_be_built_by_li_lis_and_rotldi (c, &shift, &mask) || can_be_built_by_li_lis_and_rldicl (c, &shift, &mask) - || can_be_built_by_li_lis_and_rldicr (c, &shift, &mask)) + || can_be_built_by_li_lis_and_rldicr (c, &shift, &mask) + || can_be_built_by_li_and_rldic (c, &shift, &mask)) { temp = !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode); unsigned HOST_WIDE_INT imm = (c | ~mask); diff --git a/gcc/testsuite/gcc.target/powerpc/const-build.c b/gcc/testsuite/gcc.target/powerpc/const-build.c index 8c209921d41..b503ee31c7c 100644 --- a/gcc/testsuite/gcc.target/powerpc/const-build.c +++ b/gcc/testsuite/gcc.target/powerpc/const-build.c @@ -82,6 +82,29 @@ lis_rldicr_12 (void) return 0x5310000ffffffff0LL; } +long long NOIPA +li_rldic_13 (void) +{ + return 0x000f853100000000LL; +} +long long NOIPA +li_rldic_14 (void) +{ + return 0xffff853100ffffffLL; +} + +long long NOIPA +li_rldic_15 (void) +{ + return 0x800000ffffffff31LL; +} + +long long NOIPA +li_rldic_16 (void) +{ + return 0x800000000fffff31LL; +} + struct fun arr[] = { {li_rotldi_1, 0x7531000000000LL}, {li_rotldi_2, 0x2100000000000064LL}, @@ -95,11 +118,16 @@ struct fun arr[] = { {li_rldicr_10, 0xffff8531fff00000LL}, {li_rldicr_11, 0x21fffffffff00000LL}, {lis_rldicr_12, 0x5310000ffffffff0LL}, + {li_rldic_13, 0x000f853100000000LL}, + {li_rldic_14, 0xffff853100ffffffLL}, + {li_rldic_15, 0x800000ffffffff31LL}, + {li_rldic_16, 0x800000000fffff31LL} }; /* { dg-final { scan-assembler-times {\mrotldi\M} 6 } } */ /* { dg-final { scan-assembler-times {\mrldicl\M} 3 } } */ /* { dg-final { scan-assembler-times {\mrldicr\M} 3 } } */ +/* { dg-final { scan-assembler-times {\mrldic\M} 4 } } */ int main ()