Message ID | 5c4b6c08-02ee-1052-4707-c7615f8f3147@linux.ibm.com |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CE51D3857C4D for <patchwork@sourceware.org>; Wed, 19 Jan 2022 07:13:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CE51D3857C4D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1642576384; bh=JogIGEZ5VgaA89cVE0RlhLoIscOIoUShae1VFO+Lve4=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=ct9VQnY4I524EuLrLd7ofkkDR5gTb+7a9cLJa3wWJYg9cd9UAFKUZhj4H/wbqhOlQ KTOMfrjDEyW0Mh/mSMzdyvJezFVFKasn69b//vGeX22ZSPJMhHXgASovy0/vgfMiN+ CA1GmvTfWZ4WOizmi80UG50CBVMKd8rTCG6xq/IE= 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 665EA3858032 for <gcc-patches@gcc.gnu.org>; Wed, 19 Jan 2022 07:12:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 665EA3858032 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 20J6fG9K023066; Wed, 19 Jan 2022 07:12:33 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3dp9vn48et-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Jan 2022 07:12:33 +0000 Received: from m0098393.ppops.net (m0098393.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 20J75Gsp025117; Wed, 19 Jan 2022 07:12:32 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com with ESMTP id 3dp9vn48dy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Jan 2022 07:12:32 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 20J6vkL5002035; Wed, 19 Jan 2022 07:12:30 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma06ams.nl.ibm.com with ESMTP id 3dknhjjsn2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Jan 2022 07:12:30 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 20J7CRZD44171522 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jan 2022 07:12:27 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 83A554C040; Wed, 19 Jan 2022 07:12:27 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 51CB84C044; Wed, 19 Jan 2022 07:12:26 +0000 (GMT) Received: from [9.200.100.183] (unknown [9.200.100.183]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 19 Jan 2022 07:12:26 +0000 (GMT) Message-ID: <5c4b6c08-02ee-1052-4707-c7615f8f3147@linux.ibm.com> Date: Wed, 19 Jan 2022 15:12:24 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.4.1 Content-Language: en-US To: gcc-patches <gcc-patches@gcc.gnu.org> Subject: [PATCH, rs6000] Add a combine pattern for CA minus one [PR95737] Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: KnHR411Caivfe1RvLpfvWLSqQH_Ulpum X-Proofpoint-ORIG-GUID: KMABDQ4p_pRrpGWPlC3QBBv6L6t-OKfH X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-19_05,2022-01-18_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxscore=0 lowpriorityscore=0 adultscore=0 priorityscore=1501 impostorscore=0 spamscore=0 bulkscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201190038 X-Spam-Status: No, score=-12.7 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 autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: HAO CHEN GUI via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: HAO CHEN GUI <guihaoc@linux.ibm.com> Cc: Bill Schmidt <wschmidt@linux.ibm.com>, David <dje.gcc@gmail.com>, Segher Boessenkool <segher@kernel.crashing.org> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
[rs6000] Add a combine pattern for CA minus one [PR95737]
|
|
Commit Message
HAO CHEN GUI
Jan. 19, 2022, 7:12 a.m. UTC
Hi, This patch adds a combine pattern for "CA minus one". As CA only has two values (0 or 1), we could convert following pattern (sign_extend:DI (plus:SI (reg:SI 98 ca) (const_int -1 [0xffffffffffffffff])))) to (plus:DI (reg:DI 98 ca) (const_int -1 [0xffffffffffffffff]))) With this patch, it eliminates one unnecessary sign extend. Also in rs6000, regclass of CA register is set to NO_REGS. So CA is not in hard register set and it can't match register_operand. The patch changes it to any_operand. Bootstrapped and tested on powerpc64-linux BE and LE with no regressions. Is this okay for trunk? Any recommendations? Thanks a lot. ChangeLog 2022-01-19 Haochen Gui <guihaoc@linux.ibm.com> gcc/ * config/rs6000/predicates.md (ca_operand): Match any_operand as CA register is not in hard register set. * config/rs6000/rs6000.md (extenddi_ca_minus_one): Define. gcc/testsuite/ * gcc.target/powerpc/pr95737.c: New. patch.diff
Comments
On Tue, Jan 18, 2022 at 11:13 PM HAO CHEN GUI via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > Hi, > This patch adds a combine pattern for "CA minus one". As CA only has two > values (0 or 1), we could convert following pattern > (sign_extend:DI (plus:SI (reg:SI 98 ca) > (const_int -1 [0xffffffffffffffff])))) > to > (plus:DI (reg:DI 98 ca) > (const_int -1 [0xffffffffffffffff]))) > With this patch, it eliminates one unnecessary sign extend. Also in rs6000, > regclass of CA register is set to NO_REGS. So CA is not in hard register set > and it can't match register_operand. The patch changes it to any_operand. > > Bootstrapped and tested on powerpc64-linux BE and LE with no regressions. > Is this okay for trunk? Any recommendations? Thanks a lot. > > ChangeLog > 2022-01-19 Haochen Gui <guihaoc@linux.ibm.com> > > gcc/ > * config/rs6000/predicates.md (ca_operand): Match any_operand as CA > register is not in hard register set. > * config/rs6000/rs6000.md (extenddi_ca_minus_one): Define. > > gcc/testsuite/ > * gcc.target/powerpc/pr95737.c: New. > > > patch.diff > diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md > index c65dfb91f3d..cd2ae1dc8e0 100644 > --- a/gcc/config/rs6000/predicates.md > +++ b/gcc/config/rs6000/predicates.md > @@ -188,7 +188,7 @@ (define_predicate "vlogical_operand" > > ;; Return 1 if op is the carry register. > (define_predicate "ca_operand" > - (match_operand 0 "register_operand") > + (match_operand 0 "any_operand") > { > if (SUBREG_P (op)) > op = SUBREG_REG (op); > diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md > index 6ecb0bd6142..f1b09aad3b5 100644 > --- a/gcc/config/rs6000/rs6000.md > +++ b/gcc/config/rs6000/rs6000.md > @@ -2358,6 +2358,21 @@ (define_insn "subf<mode>3_carry_in_xx" > "subfe %0,%0,%0" > [(set_attr "type" "add")]) > > +(define_insn_and_split "*extenddi_ca_minus_one" > + [(set (match_operand:DI 0 "gpc_reg_operand") > + (sign_extend:DI (plus:SI (match_operand:SI 1 "ca_operand") > + (const_int -1))))] > + "" > + "#" > + "" > + [(parallel [(set (match_dup 0) > + (plus:DI (match_dup 2) > + (const_int -1))) > + (clobber (match_dup 2))])] > +{ > + operands[2] = copy_rtx (operands[1]); > + PUT_MODE (operands[2], DImode); > +}) There are a few things missing I think for this to be correct. I think it should be: (define_insn_and_split "*extenddi_ca_minus_one" [(set (match_operand:DI 0 "gpc_reg_operand" "=r") (sign_extend:DI (plus:SI (reg:SI CA_REGNO) (const_int -1))))] "" "#" "&& reload_completed" [(parallel [(set (match_dup 0) (plus:DI (reg:DI CA_REGNO) (const_int -1))) (clobber (reg:DI CA_REGNO))])] {}) There is no reason to change ca_operand either since subf<mode>3_carry_in_xx already hard codes the CA_REGNO too; you can just use it directly like above. Sorry for the incorrect whitespace formatting though. Thanks, Andrew Pinski > > (define_insn "@neg<mode>2" > [(set (match_operand:GPR 0 "gpc_reg_operand" "=r") > diff --git a/gcc/testsuite/gcc.target/powerpc/pr95737.c b/gcc/testsuite/gcc.target/powerpc/pr95737.c > new file mode 100644 > index 00000000000..94320f23423 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/powerpc/pr95737.c > @@ -0,0 +1,10 @@ > +/* PR target/95737 */ > +/* { dg-do compile { target lp64 } } */ > +/* { dg-options "-O2 -mdejagnu-cpu=power8" } */ > +/* { dg-final { scan-assembler-not {\mextsw\M} } } */ > + > + > +unsigned long long negativeLessThan (unsigned long long a, unsigned long long b) > +{ > + return -(a < b); > +}
On Wed, Jan 19, 2022 at 2:12 AM HAO CHEN GUI <guihaoc@linux.ibm.com> wrote: > > Hi, > This patch adds a combine pattern for "CA minus one". As CA only has two > values (0 or 1), we could convert following pattern > (sign_extend:DI (plus:SI (reg:SI 98 ca) > (const_int -1 [0xffffffffffffffff])))) > to > (plus:DI (reg:DI 98 ca) > (const_int -1 [0xffffffffffffffff]))) > With this patch, it eliminates one unnecessary sign extend. Also in rs6000, > regclass of CA register is set to NO_REGS. So CA is not in hard register set > and it can't match register_operand. The patch changes it to any_operand. CA_REGNO should be in class CA_REGS, not class NO_REGS. This seems like a major, latent bug. Thanks, David > > Bootstrapped and tested on powerpc64-linux BE and LE with no regressions. > Is this okay for trunk? Any recommendations? Thanks a lot. > > ChangeLog > 2022-01-19 Haochen Gui <guihaoc@linux.ibm.com> > > gcc/ > * config/rs6000/predicates.md (ca_operand): Match any_operand as CA > register is not in hard register set. > * config/rs6000/rs6000.md (extenddi_ca_minus_one): Define. > > gcc/testsuite/ > * gcc.target/powerpc/pr95737.c: New. > > > patch.diff > diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md > index c65dfb91f3d..cd2ae1dc8e0 100644 > --- a/gcc/config/rs6000/predicates.md > +++ b/gcc/config/rs6000/predicates.md > @@ -188,7 +188,7 @@ (define_predicate "vlogical_operand" > > ;; Return 1 if op is the carry register. > (define_predicate "ca_operand" > - (match_operand 0 "register_operand") > + (match_operand 0 "any_operand") > { > if (SUBREG_P (op)) > op = SUBREG_REG (op); > diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md > index 6ecb0bd6142..f1b09aad3b5 100644 > --- a/gcc/config/rs6000/rs6000.md > +++ b/gcc/config/rs6000/rs6000.md > @@ -2358,6 +2358,21 @@ (define_insn "subf<mode>3_carry_in_xx" > "subfe %0,%0,%0" > [(set_attr "type" "add")]) > > +(define_insn_and_split "*extenddi_ca_minus_one" > + [(set (match_operand:DI 0 "gpc_reg_operand") > + (sign_extend:DI (plus:SI (match_operand:SI 1 "ca_operand") > + (const_int -1))))] > + "" > + "#" > + "" > + [(parallel [(set (match_dup 0) > + (plus:DI (match_dup 2) > + (const_int -1))) > + (clobber (match_dup 2))])] > +{ > + operands[2] = copy_rtx (operands[1]); > + PUT_MODE (operands[2], DImode); > +}) > > (define_insn "@neg<mode>2" > [(set (match_operand:GPR 0 "gpc_reg_operand" "=r") > diff --git a/gcc/testsuite/gcc.target/powerpc/pr95737.c b/gcc/testsuite/gcc.target/powerpc/pr95737.c > new file mode 100644 > index 00000000000..94320f23423 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/powerpc/pr95737.c > @@ -0,0 +1,10 @@ > +/* PR target/95737 */ > +/* { dg-do compile { target lp64 } } */ > +/* { dg-options "-O2 -mdejagnu-cpu=power8" } */ > +/* { dg-final { scan-assembler-not {\mextsw\M} } } */ > + > + > +unsigned long long negativeLessThan (unsigned long long a, unsigned long long b) > +{ > + return -(a < b); > +}
On Wed, Jan 19, 2022 at 2:12 AM HAO CHEN GUI <guihaoc@linux.ibm.com> wrote: > > Hi, > This patch adds a combine pattern for "CA minus one". As CA only has two > values (0 or 1), we could convert following pattern > (sign_extend:DI (plus:SI (reg:SI 98 ca) > (const_int -1 [0xffffffffffffffff])))) > to > (plus:DI (reg:DI 98 ca) > (const_int -1 [0xffffffffffffffff]))) > With this patch, it eliminates one unnecessary sign extend. Also in rs6000, > regclass of CA register is set to NO_REGS. So CA is not in hard register set > and it can't match register_operand. The patch changes it to any_operand. Segher changed the class in 2014. https://gcc.gnu.org/pipermail/gcc-patches/2014-September/399192.html We need to ensure that it still is the correct decision in light of these new patterns. Thanks, David > > Bootstrapped and tested on powerpc64-linux BE and LE with no regressions. > Is this okay for trunk? Any recommendations? Thanks a lot. > > ChangeLog > 2022-01-19 Haochen Gui <guihaoc@linux.ibm.com> > > gcc/ > * config/rs6000/predicates.md (ca_operand): Match any_operand as CA > register is not in hard register set. > * config/rs6000/rs6000.md (extenddi_ca_minus_one): Define. > > gcc/testsuite/ > * gcc.target/powerpc/pr95737.c: New. > > > patch.diff > diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md > index c65dfb91f3d..cd2ae1dc8e0 100644 > --- a/gcc/config/rs6000/predicates.md > +++ b/gcc/config/rs6000/predicates.md > @@ -188,7 +188,7 @@ (define_predicate "vlogical_operand" > > ;; Return 1 if op is the carry register. > (define_predicate "ca_operand" > - (match_operand 0 "register_operand") > + (match_operand 0 "any_operand") > { > if (SUBREG_P (op)) > op = SUBREG_REG (op); > diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md > index 6ecb0bd6142..f1b09aad3b5 100644 > --- a/gcc/config/rs6000/rs6000.md > +++ b/gcc/config/rs6000/rs6000.md > @@ -2358,6 +2358,21 @@ (define_insn "subf<mode>3_carry_in_xx" > "subfe %0,%0,%0" > [(set_attr "type" "add")]) > > +(define_insn_and_split "*extenddi_ca_minus_one" > + [(set (match_operand:DI 0 "gpc_reg_operand") > + (sign_extend:DI (plus:SI (match_operand:SI 1 "ca_operand") > + (const_int -1))))] > + "" > + "#" > + "" > + [(parallel [(set (match_dup 0) > + (plus:DI (match_dup 2) > + (const_int -1))) > + (clobber (match_dup 2))])] > +{ > + operands[2] = copy_rtx (operands[1]); > + PUT_MODE (operands[2], DImode); > +}) > > (define_insn "@neg<mode>2" > [(set (match_operand:GPR 0 "gpc_reg_operand" "=r") > diff --git a/gcc/testsuite/gcc.target/powerpc/pr95737.c b/gcc/testsuite/gcc.target/powerpc/pr95737.c > new file mode 100644 > index 00000000000..94320f23423 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/powerpc/pr95737.c > @@ -0,0 +1,10 @@ > +/* PR target/95737 */ > +/* { dg-do compile { target lp64 } } */ > +/* { dg-options "-O2 -mdejagnu-cpu=power8" } */ > +/* { dg-final { scan-assembler-not {\mextsw\M} } } */ > + > + > +unsigned long long negativeLessThan (unsigned long long a, unsigned long long b) > +{ > + return -(a < b); > +}
On 19/1/2022 下午 3:52, Andrew Pinski wrote: > On Tue, Jan 18, 2022 at 11:13 PM HAO CHEN GUI via Gcc-patches > <gcc-patches@gcc.gnu.org> wrote: >> >> Hi, >> This patch adds a combine pattern for "CA minus one". As CA only has two >> values (0 or 1), we could convert following pattern >> (sign_extend:DI (plus:SI (reg:SI 98 ca) >> (const_int -1 [0xffffffffffffffff])))) >> to >> (plus:DI (reg:DI 98 ca) >> (const_int -1 [0xffffffffffffffff]))) >> With this patch, it eliminates one unnecessary sign extend. Also in rs6000, >> regclass of CA register is set to NO_REGS. So CA is not in hard register set >> and it can't match register_operand. The patch changes it to any_operand. >> >> Bootstrapped and tested on powerpc64-linux BE and LE with no regressions. >> Is this okay for trunk? Any recommendations? Thanks a lot. >> >> ChangeLog >> 2022-01-19 Haochen Gui <guihaoc@linux.ibm.com> >> >> gcc/ >> * config/rs6000/predicates.md (ca_operand): Match any_operand as CA >> register is not in hard register set. >> * config/rs6000/rs6000.md (extenddi_ca_minus_one): Define. >> >> gcc/testsuite/ >> * gcc.target/powerpc/pr95737.c: New. >> >> >> patch.diff >> diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md >> index c65dfb91f3d..cd2ae1dc8e0 100644 >> --- a/gcc/config/rs6000/predicates.md >> +++ b/gcc/config/rs6000/predicates.md >> @@ -188,7 +188,7 @@ (define_predicate "vlogical_operand" >> >> ;; Return 1 if op is the carry register. >> (define_predicate "ca_operand" >> - (match_operand 0 "register_operand") >> + (match_operand 0 "any_operand") >> { >> if (SUBREG_P (op)) >> op = SUBREG_REG (op); >> diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md >> index 6ecb0bd6142..f1b09aad3b5 100644 >> --- a/gcc/config/rs6000/rs6000.md >> +++ b/gcc/config/rs6000/rs6000.md >> @@ -2358,6 +2358,21 @@ (define_insn "subf<mode>3_carry_in_xx" >> "subfe %0,%0,%0" >> [(set_attr "type" "add")]) >> >> +(define_insn_and_split "*extenddi_ca_minus_one" >> + [(set (match_operand:DI 0 "gpc_reg_operand") >> + (sign_extend:DI (plus:SI (match_operand:SI 1 "ca_operand") >> + (const_int -1))))] >> + "" >> + "#" >> + "" >> + [(parallel [(set (match_dup 0) >> + (plus:DI (match_dup 2) >> + (const_int -1))) >> + (clobber (match_dup 2))])] >> +{ >> + operands[2] = copy_rtx (operands[1]); >> + PUT_MODE (operands[2], DImode); >> +}) > > There are a few things missing I think for this to be correct. > I think it should be: > (define_insn_and_split "*extenddi_ca_minus_one" > [(set (match_operand:DI 0 "gpc_reg_operand" "=r") > (sign_extend:DI (plus:SI (reg:SI CA_REGNO) > (const_int -1))))] > "" > "#" > "&& reload_completed" > [(parallel [(set (match_dup 0) > (plus:DI (reg:DI CA_REGNO) > (const_int -1))) > (clobber (reg:DI CA_REGNO))])] > {}) > > There is no reason to change ca_operand either since > subf<mode>3_carry_in_xx already hard codes the CA_REGNO too; you can Yes, we can directly use CA_REGNO. It makes the pattern compact. But why it needs reload_completed? Could you explain it? Thanks. Gui Haochen > just use it directly like above. > > Sorry for the incorrect whitespace formatting though. > > Thanks, > Andrew Pinski > >> >> (define_insn "@neg<mode>2" >> [(set (match_operand:GPR 0 "gpc_reg_operand" "=r") >> diff --git a/gcc/testsuite/gcc.target/powerpc/pr95737.c b/gcc/testsuite/gcc.target/powerpc/pr95737.c >> new file mode 100644 >> index 00000000000..94320f23423 >> --- /dev/null >> +++ b/gcc/testsuite/gcc.target/powerpc/pr95737.c >> @@ -0,0 +1,10 @@ >> +/* PR target/95737 */ >> +/* { dg-do compile { target lp64 } } */ >> +/* { dg-options "-O2 -mdejagnu-cpu=power8" } */ >> +/* { dg-final { scan-assembler-not {\mextsw\M} } } */ >> + >> + >> +unsigned long long negativeLessThan (unsigned long long a, unsigned long long b) >> +{ >> + return -(a < b); >> +}
On Wed, Jan 19, 2022 at 6:12 PM HAO CHEN GUI <guihaoc@linux.ibm.com> wrote: > > > > On 19/1/2022 下午 3:52, Andrew Pinski wrote: > > On Tue, Jan 18, 2022 at 11:13 PM HAO CHEN GUI via Gcc-patches > > <gcc-patches@gcc.gnu.org> wrote: > >> > >> Hi, > >> This patch adds a combine pattern for "CA minus one". As CA only has two > >> values (0 or 1), we could convert following pattern > >> (sign_extend:DI (plus:SI (reg:SI 98 ca) > >> (const_int -1 [0xffffffffffffffff])))) > >> to > >> (plus:DI (reg:DI 98 ca) > >> (const_int -1 [0xffffffffffffffff]))) > >> With this patch, it eliminates one unnecessary sign extend. Also in rs6000, > >> regclass of CA register is set to NO_REGS. So CA is not in hard register set > >> and it can't match register_operand. The patch changes it to any_operand. > >> > >> Bootstrapped and tested on powerpc64-linux BE and LE with no regressions. > >> Is this okay for trunk? Any recommendations? Thanks a lot. > >> > >> ChangeLog > >> 2022-01-19 Haochen Gui <guihaoc@linux.ibm.com> > >> > >> gcc/ > >> * config/rs6000/predicates.md (ca_operand): Match any_operand as CA > >> register is not in hard register set. > >> * config/rs6000/rs6000.md (extenddi_ca_minus_one): Define. > >> > >> gcc/testsuite/ > >> * gcc.target/powerpc/pr95737.c: New. > >> > >> > >> patch.diff > >> diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md > >> index c65dfb91f3d..cd2ae1dc8e0 100644 > >> --- a/gcc/config/rs6000/predicates.md > >> +++ b/gcc/config/rs6000/predicates.md > >> @@ -188,7 +188,7 @@ (define_predicate "vlogical_operand" > >> > >> ;; Return 1 if op is the carry register. > >> (define_predicate "ca_operand" > >> - (match_operand 0 "register_operand") > >> + (match_operand 0 "any_operand") > >> { > >> if (SUBREG_P (op)) > >> op = SUBREG_REG (op); > >> diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md > >> index 6ecb0bd6142..f1b09aad3b5 100644 > >> --- a/gcc/config/rs6000/rs6000.md > >> +++ b/gcc/config/rs6000/rs6000.md > >> @@ -2358,6 +2358,21 @@ (define_insn "subf<mode>3_carry_in_xx" > >> "subfe %0,%0,%0" > >> [(set_attr "type" "add")]) > >> > >> +(define_insn_and_split "*extenddi_ca_minus_one" > >> + [(set (match_operand:DI 0 "gpc_reg_operand") > >> + (sign_extend:DI (plus:SI (match_operand:SI 1 "ca_operand") > >> + (const_int -1))))] > >> + "" > >> + "#" > >> + "" > >> + [(parallel [(set (match_dup 0) > >> + (plus:DI (match_dup 2) > >> + (const_int -1))) > >> + (clobber (match_dup 2))])] > >> +{ > >> + operands[2] = copy_rtx (operands[1]); > >> + PUT_MODE (operands[2], DImode); > >> +}) > > > > There are a few things missing I think for this to be correct. > > I think it should be: > > (define_insn_and_split "*extenddi_ca_minus_one" > > [(set (match_operand:DI 0 "gpc_reg_operand" "=r") > > (sign_extend:DI (plus:SI (reg:SI CA_REGNO) > > (const_int -1))))] > > "" > > "#" > > "&& reload_completed" > > [(parallel [(set (match_dup 0) > > (plus:DI (reg:DI CA_REGNO) > > (const_int -1))) > > (clobber (reg:DI CA_REGNO))])] > > {}) > > > > There is no reason to change ca_operand either since > > subf<mode>3_carry_in_xx already hard codes the CA_REGNO too; you can > Yes, we can directly use CA_REGNO. It makes the pattern compact. > But why it needs reload_completed? Could you explain it? Actually you are right, there is no reason for the reload_completed any more. It was definitely needed before when you were doing PUT_MODE as I didn't trust how ca_operand would have caught only the CA_REGNO register. Thanks, Andrew > > Thanks. > Gui Haochen > > > just use it directly like above. > > > > Sorry for the incorrect whitespace formatting though. > > > > Thanks, > > Andrew Pinski > > > >> > >> (define_insn "@neg<mode>2" > >> [(set (match_operand:GPR 0 "gpc_reg_operand" "=r") > >> diff --git a/gcc/testsuite/gcc.target/powerpc/pr95737.c b/gcc/testsuite/gcc.target/powerpc/pr95737.c > >> new file mode 100644 > >> index 00000000000..94320f23423 > >> --- /dev/null > >> +++ b/gcc/testsuite/gcc.target/powerpc/pr95737.c > >> @@ -0,0 +1,10 @@ > >> +/* PR target/95737 */ > >> +/* { dg-do compile { target lp64 } } */ > >> +/* { dg-options "-O2 -mdejagnu-cpu=power8" } */ > >> +/* { dg-final { scan-assembler-not {\mextsw\M} } } */ > >> + > >> + > >> +unsigned long long negativeLessThan (unsigned long long a, unsigned long long b) > >> +{ > >> + return -(a < b); > >> +}
diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md index c65dfb91f3d..cd2ae1dc8e0 100644 --- a/gcc/config/rs6000/predicates.md +++ b/gcc/config/rs6000/predicates.md @@ -188,7 +188,7 @@ (define_predicate "vlogical_operand" ;; Return 1 if op is the carry register. (define_predicate "ca_operand" - (match_operand 0 "register_operand") + (match_operand 0 "any_operand") { if (SUBREG_P (op)) op = SUBREG_REG (op); diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md index 6ecb0bd6142..f1b09aad3b5 100644 --- a/gcc/config/rs6000/rs6000.md +++ b/gcc/config/rs6000/rs6000.md @@ -2358,6 +2358,21 @@ (define_insn "subf<mode>3_carry_in_xx" "subfe %0,%0,%0" [(set_attr "type" "add")]) +(define_insn_and_split "*extenddi_ca_minus_one" + [(set (match_operand:DI 0 "gpc_reg_operand") + (sign_extend:DI (plus:SI (match_operand:SI 1 "ca_operand") + (const_int -1))))] + "" + "#" + "" + [(parallel [(set (match_dup 0) + (plus:DI (match_dup 2) + (const_int -1))) + (clobber (match_dup 2))])] +{ + operands[2] = copy_rtx (operands[1]); + PUT_MODE (operands[2], DImode); +}) (define_insn "@neg<mode>2" [(set (match_operand:GPR 0 "gpc_reg_operand" "=r") diff --git a/gcc/testsuite/gcc.target/powerpc/pr95737.c b/gcc/testsuite/gcc.target/powerpc/pr95737.c new file mode 100644 index 00000000000..94320f23423 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr95737.c @@ -0,0 +1,10 @@ +/* PR target/95737 */ +/* { dg-do compile { target lp64 } } */ +/* { dg-options "-O2 -mdejagnu-cpu=power8" } */ +/* { dg-final { scan-assembler-not {\mextsw\M} } } */ + + +unsigned long long negativeLessThan (unsigned long long a, unsigned long long b) +{ + return -(a < b); +}