From patchwork Mon Feb 13 02:43:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiufu Guo X-Patchwork-Id: 1741305 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=GvcQht+l; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PFTF144Z0z23qt for ; Mon, 13 Feb 2023 13:44:04 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9CCCD3858C27 for ; Mon, 13 Feb 2023 02:44:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9CCCD3858C27 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676256240; bh=emBaUCR4HxXIOiUmd7+q5s2AUS+qrbiR9d+6COOlha0=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=GvcQht+ll2QcIrDE6OheMfApYrOJP/6FBcDe2/GIalHMBQ+PZuUtY8KA5Mm0bzxH/ xyvc63MM//BGk5kLcTxFYBQYIwUkP+Wc5zkZSkQB4sJzVZ/8Qv15umneTlLRhMbn4q 05pICvAVy0ahNc2PEO/rU/hdElLhvl5ggYpr4m0c= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 6CB963858D33; Mon, 13 Feb 2023 02:43:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6CB963858D33 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 31D20TRx006247; Mon, 13 Feb 2023 02:43:39 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3npxaqbwxw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 13 Feb 2023 02:43:39 +0000 Received: from m0098416.ppops.net (m0098416.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 31D2fQqJ021518; Mon, 13 Feb 2023 02:43:38 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3npxaqbwxh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 13 Feb 2023 02:43:38 +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 31CHqjVO032710; Mon, 13 Feb 2023 02:43:37 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3np29fj32w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 13 Feb 2023 02:43:36 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 31D2hYqU42729970 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Feb 2023 02:43:34 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 56D8820043; Mon, 13 Feb 2023 02:43:34 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 557322004E; Mon, 13 Feb 2023 02:43:33 +0000 (GMT) Received: from ltcden2-lp1.aus.stglabs.ibm.com (unknown [9.3.90.43]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 13 Feb 2023 02:43:33 +0000 (GMT) To: gcc-patches@gcc.gnu.org Cc: segher@kernel.crashing.org, dje.gcc@gmail.com, linkw@gcc.gnu.org, guojiufu@linux.ibm.com Subject: [PATCH V2] rs6000: Add new patterns rlwinm with mask Date: Mon, 13 Feb 2023 10:43:32 +0800 Message-Id: <20230213024332.2614540-1-guojiufu@linux.ibm.com> X-Mailer: git-send-email 2.31.1 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: bIyQQgsRGK2n5yQktzP80yrxYA5_XqG7 X-Proofpoint-GUID: nyX9kwrlEVgslC1hCEy-fE2Gbsz3lbGi X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.170.22 definitions=2023-02-12_12,2023-02-09_03,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 impostorscore=0 spamscore=0 malwarescore=0 mlxscore=0 adultscore=0 priorityscore=1501 suspectscore=0 clxscore=1015 mlxlogscore=585 lowpriorityscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302130021 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 Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, Compare with previous version: https://gcc.gnu.org/pipermail/gcc-patches/2023-February/611513.html This patch remove un-needed lowpart_subreg_operand. For code: ``` u64 test_rlwinm_lowpart_mask (u32 v) { u32 v1 = ((v << N) | (v >> (32 - N))) & 0xfffff00; return (u64)v1; } ``` We generate "rlwinm 3,3,4,4,23; rldicl 3,3,0,32" instead of "rlwinm 3,3,4,4,23". Here the "rlwinm" cleans high32 bits already, so "rldicl" is reductant. Similarly, for the below code which is the functionality of "rlwinm". ``` u64 test_rlwinm_mask (u32 v) { u32 v1 = ((v << N) | (v >> (32 - N))); u64 v2 = (u64) v1 | ((u64) v1 << 32); return v2 & 0xffffffffe0000003ULL; } ``` We generate "rotlwi 3,3,4; sldi 9,3,32; add 3,9,3; rldicl 3,3,35,27; rldicl 3,3,29,0" instead of "rlwinm 3,3,4,30,2". This patch optimizes these two kinds of code to use just one "rlwinm" insn. Bootstrap and regtests pass on ppc64{,le}. Is this patch ok for trunk (or next stage1)? BR, Jeff (Jiufu) gcc/ChangeLog: * config/rs6000/rs6000.md (rlwinm_lowpart_mask): New define_insn. (rlwinm_mask_): New define_insn. gcc/testsuite/ChangeLog: * gcc.target/powerpc/rlwinm-0.c: Reduce instruction number. * gcc.target/powerpc/rlwinm_3.c: New test. --- gcc/config/rs6000/rs6000.md | 34 +++++++++++++++ gcc/testsuite/gcc.target/powerpc/rlwinm-0.c | 6 +-- gcc/testsuite/gcc.target/powerpc/rlwinm_3.c | 47 +++++++++++++++++++++ 3 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.target/powerpc/rlwinm_3.c diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md index 4a7812fa592..a7bf80da32e 100644 --- a/gcc/config/rs6000/rs6000.md +++ b/gcc/config/rs6000/rs6000.md @@ -4325,6 +4325,40 @@ (define_insn "*rotldi3_insert_7" [(set_attr "type" "insert") (set_attr "size" "64")]) +(define_insn "rlwinm_lowpart_mask" + [(set (match_operand:DI 0 "gpc_reg_operand" "=r") + (and:DI + (subreg:DI + (match_operator:SI 4 "rotate_mask_operator" + [(match_operand:SI 1 "gpc_reg_operand" "r") + (match_operand:SI 2 "const_int_operand" "n")]) 0) + (match_operand:DI 3 "const_int_operand" "n")))] + "TARGET_POWERPC64 && (UINTVAL (operands[3]) >> 32) == 0 + && rs6000_is_valid_shift_mask (operands[3], operands[4], SImode)" +{ + return rs6000_insn_for_shift_mask (SImode, operands, false); +} + [(set_attr "type" "shift")]) + +(define_insn "rlwinm_mask_" + [(set (match_operand:DI 0 "gpc_reg_operand" "=r") + (and:DI + (plus_ior_xor:DI + (ashift:DI + (subreg:DI + (match_operator:SI 4 "rotate_mask_operator" + [(match_operand:SI 1 "gpc_reg_operand" "r") + (match_operand:SI 2 "const_int_operand" "n")]) 0) + (const_int 32)) + (zero_extend:DI (match_dup 4))) + (match_operand:DI 3 "const_int_operand" "n")))] + "TARGET_POWERPC64 + && (UINTVAL (operands[3]) & 0xffffffff80000001ULL) == 0xffffffff80000001ULL + && rs6000_is_valid_mask (operands[3], NULL, NULL, SImode)" +{ + return rs6000_insn_for_shift_mask (SImode, operands, false); +} + [(set_attr "type" "shift")]) ; This handles the important case of multiple-precision shifts. There is ; no canonicalization rule for ASHIFT vs. LSHIFTRT, so two patterns. diff --git a/gcc/testsuite/gcc.target/powerpc/rlwinm-0.c b/gcc/testsuite/gcc.target/powerpc/rlwinm-0.c index 4f4fca2d8ef..50ff01e1925 100644 --- a/gcc/testsuite/gcc.target/powerpc/rlwinm-0.c +++ b/gcc/testsuite/gcc.target/powerpc/rlwinm-0.c @@ -2,12 +2,12 @@ /* { dg-options "-O2" } */ /* { dg-final { scan-assembler-times {(?n)^\s+[a-z]} 6739 { target ilp32 } } } */ -/* { dg-final { scan-assembler-times {(?n)^\s+[a-z]} 9716 { target lp64 } } } */ +/* { dg-final { scan-assembler-times {(?n)^\s+[a-z]} 8164 { target lp64 } } } */ /* { dg-final { scan-assembler-times {(?n)^\s+blr} 3375 } } */ -/* { dg-final { scan-assembler-times {(?n)^\s+rldicl} 3081 { target lp64 } } } */ +/* { dg-final { scan-assembler-times {(?n)^\s+rldicl} 1538 { target lp64 } } } */ /* { dg-final { scan-assembler-times {(?n)^\s+rlwinm} 3197 { target ilp32 } } } */ -/* { dg-final { scan-assembler-times {(?n)^\s+rlwinm} 3093 { target lp64 } } } */ +/* { dg-final { scan-assembler-times {(?n)^\s+rlwinm} 3084 { target lp64 } } } */ /* { dg-final { scan-assembler-times {(?n)^\s+rotlwi} 154 } } */ /* { dg-final { scan-assembler-times {(?n)^\s+srwi} 13 { target ilp32 } } } */ /* { dg-final { scan-assembler-times {(?n)^\s+srdi} 13 { target lp64 } } } */ diff --git a/gcc/testsuite/gcc.target/powerpc/rlwinm_3.c b/gcc/testsuite/gcc.target/powerpc/rlwinm_3.c new file mode 100644 index 00000000000..65dcd69ace2 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/rlwinm_3.c @@ -0,0 +1,47 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -save-temps" } */ + +typedef unsigned long long u64; +typedef unsigned int u32; +#define NOINLE __attribute__ ((noinline)) +#define V (0x9753) + +#define MASK 0xffffffffe0000003ULL +#define N 4 +#define LMASK 0xfffff00 + +u64 NOINLE +test_rlwinm_lowpart_mask (u32 v) +{ + u32 v1 = ((v << N) | (v >> (32 - N))) & LMASK; + return (u64)v1; +} + +u64 NOINLE +test_rlwinm_mask (u32 v) +{ + u32 v1 = ((v << N) | (v >> (32 - N))); + u64 v2 = (u64) v1 | ((u64) v1 << 32); + return v2 & MASK; +} + +/* { dg-final { scan-assembler-times {\mrlwinm\M} 2 { target has_arch_ppc64 } } } */ + +#define RLWINM_L(v, n) \ + ((((v & 0xffffffffLL) << n) | ((v & 0xffffffffLL) >> (32 - n))) \ + & 0xffffffffLL) +#define RLWINM_MASK(v, n, m) (((RLWINM_L (v, n) << 32) | (RLWINM_L (v, n))) & m) + +u64 v_low_mask = RLWINM_MASK (V, N, LMASK); +u64 v_mask = RLWINM_MASK (V, N, MASK); + +int +main () +{ + u64 v = V; + if (test_rlwinm_lowpart_mask (v) != v_low_mask + || test_rlwinm_mask (v) != v_mask) + __builtin_abort (); + + return 0; +}