From patchwork Thu Feb 16 09:23:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kewen.Lin" X-Patchwork-Id: 57934 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp198222wrn; Thu, 16 Feb 2023 01:24:44 -0800 (PST) X-Google-Smtp-Source: AK7set/D7P4YEN0KgERavO5MEd+RcOJ1qDdm0cogXcfDZXhnM7CFuRJwSIwXohXbGRlm3xQGbXQb X-Received: by 2002:aa7:c6d7:0:b0:4ac:c76e:d73e with SMTP id b23-20020aa7c6d7000000b004acc76ed73emr4815529eds.21.1676539484560; Thu, 16 Feb 2023 01:24:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676539484; cv=none; d=google.com; s=arc-20160816; b=sIvk7nq0PuxnCoNEc0uhAiuAkeVn5NQIQCrT6qcaP2OWwSxN+WKWmNazjc/qE4AwYq uvZO0ZeYuja4CYo4qN2MVqVVNN6POHRraJweb2rPU69YNWtizTIi0HiefAfuzOPQEW7V TAI2hwvaRv6nCZ8WbYD0EfDeex2Oj7zXSPaEaf3o9KyWrbF1uybxPmvYz97weLJXBANA cGl01LlI9QomkGP6ffUpUy3xRhfFA/Q0bcgIaBUG1YAyPuoxUxzbynBg3g/3LTqESpvI /zd1ekBTdZQMoXZuU1tNOYWhGAS//rVR8F/oS9yxq7hflVrlh4NvQlPRx4Gzr0ixwcjJ hgag== 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:subject:cc:to:content-language:user-agent :mime-version:date:message-id:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=DmNao24Cwc7eZ15sUqubUIuvSClDgIuWpbISZeM3JD0=; b=v+vixIgHivJm370Fm0TbU3MK19MJwSm8xhiAe8L/gRWXrLSkDh9MSkBfT3hjgIlW2n Yam6Su1bNRVZgw6fMLKf09rI2Fa18quqdSIaKjH7CZwr7k1/uF6xAMs+6W8lBV06fZEu fEtgoUTbKO8ydYk+0pqdHT18gdV7nc9YIBj0zR9Yf08UoQmJ5Z+HL/nAmBO3zVDsm4NP nK6BrIEYZ9pAxZsza4TvA0+3s9Pg0F54iLw4/fM4tFMWJeOW5W5sXTeyvUZg+fCqm/CR NUGE2oJb7wT9J16eGxWAFnj9mqoAOji90akV0+sVhs+femS3UFUc3B1J3F0zhexduCIS /OwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=lIwKnZ+e; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id n25-20020aa7c699000000b004ace5e81f9csi1723605edq.571.2023.02.16.01.24.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 01:24:44 -0800 (PST) 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=lIwKnZ+e; 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 869613858C50 for ; Thu, 16 Feb 2023 09:24:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 869613858C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676539483; bh=DmNao24Cwc7eZ15sUqubUIuvSClDgIuWpbISZeM3JD0=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=lIwKnZ+eKO5WtRj4E2K+po0yqJkjAkiPvS3L2LIEjVm0Mcc/YXQWOw9Y+i3xKADg9 GfI8hIsqFL/YEf4eJ0DxPnVYMTkG/wAy7XOOVf/kFt8z0NOmkLt4/bQqXs/bIGgXbN Iupexmn8eJQ4d6LvG9QkPjhcHQNROAkWaLOwOtxQ= 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 18B973858D33 for ; Thu, 16 Feb 2023 09:23:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 18B973858D33 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 31G9L5J3001359; Thu, 16 Feb 2023 09:23:50 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3nsfvwtw0f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 16 Feb 2023 09:23:50 +0000 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 31G7UMmf023772; Thu, 16 Feb 2023 09:23:50 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 3nsfvwtvyv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 16 Feb 2023 09:23:49 +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 31G51JqR029878; Thu, 16 Feb 2023 09:23:47 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3np29fpety-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 16 Feb 2023 09:23:47 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 31G9NiNO47120882 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 16 Feb 2023 09:23:44 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0AA8B20043; Thu, 16 Feb 2023 09:23:44 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 24ECB20040; Thu, 16 Feb 2023 09:23:42 +0000 (GMT) Received: from [9.197.254.194] (unknown [9.197.254.194]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 16 Feb 2023 09:23:41 +0000 (GMT) Message-ID: Date: Thu, 16 Feb 2023 17:23:40 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Content-Language: en-US To: GCC Patches Cc: Segher Boessenkool , David Edelsohn , Peter Bergner , Michael Meissner Subject: [PATCH] rs6000: Fix vector parity support [PR108699] X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 56Sd_8JLzlcJ0UZmDqB5zY4UP1mPcdUE X-Proofpoint-ORIG-GUID: Ts3OXMNMqY77bFPU4Tm6C1G3frvvKr-5 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-16_06,2023-02-15_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 spamscore=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 clxscore=1011 mlxlogscore=999 mlxscore=0 adultscore=0 phishscore=0 suspectscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302160075 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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: "Kewen.Lin via Gcc-patches" From: "Kewen.Lin" Reply-To: "Kewen.Lin" 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?1757979066166592175?= X-GMAIL-MSGID: =?utf-8?q?1757979066166592175?= Hi, The failures on the original failed case builtin-bitops-1.c and the associated test case pr108699.c here show that the current support of parity vector mode is wrong on Power. The hardware insns vprtyb[wdq] which operate on the least significant bit of each byte per element, they doesn't match what RTL opcode parity needs, but the current implementation expands it with them wrongly. This patch is to fix the handling with one more pre-insn vpopcntb. It also fixes an oversight having V8HI in VEC_IP, replaces VParity with VEC_IP, and adjusts the existing UNSPEC_PARITY to a more meaningful name UNSPEC_PARITYB. I also noticed that we can make use of vpopcnt[bhwd] on Power8 (AND with 1 on each element), but it's next stage1 content, I plan to support it with one subsequent patch and make this patch focus on bug fixing. Bootstrapped and regtested on powerpc64-linux-gnu P{7,8,9} and powerpc64le-linux-gnu P10. Is it ok for trunk? BR, Kewen ----- PR target/108699 gcc/ChangeLog: * config/rs6000/altivec.md (*p9v_parity2): Rename to ... (p9v_parityb2): ... this. Adjust pattern with UNSPEC_PARITYB, and replace mode_iterator VParity with VEC_IP. (mode_iterator VParity): Remove. * config/rs6000/rs6000-builtins.def (VPRTYBD): Replace parityv2di2 with p9v_paritybv2di2. (VPRTYBW): Replace parityv4si2 with p9v_paritybv4si2. (VPRTYBQ): Replace parityv1ti2 with p9v_paritybv1ti2. * config/rs6000/rs6000.cc (rs6000_emit_parity): Replace gen_paritysi2_cmpb with gen_paritybsi2, and replace gen_paritydi2_cmpb with gen_paritybdi2 * config/rs6000/rs6000.md (parity2_cmpb): Rename to ... (parityb2): ... this. (UNSPEC_PARITY): Rename to ... (UNSPEC_PARITYB): ... this. * config/rs6000/vector.md (mode_iterator VEC_IP): Remove V8HI. (parity2 with VEC_IP): Expand with popcountv16qi2 and the corresponding vector parity byte p9v_parityb2. gcc/testsuite/ChangeLog: * gcc.target/powerpc/p9-vparity.c: Add scan-assembler-not for vpopcntb to distinguish parity byte from parity. * gcc.target/powerpc/pr108699.c: New test. --- gcc/config/rs6000/altivec.md | 15 +++---- gcc/config/rs6000/rs6000-builtins.def | 6 +-- gcc/config/rs6000/rs6000.cc | 4 +- gcc/config/rs6000/rs6000.md | 7 ++-- gcc/config/rs6000/vector.md | 14 +++++-- gcc/testsuite/gcc.target/powerpc/p9-vparity.c | 1 + gcc/testsuite/gcc.target/powerpc/pr108699.c | 42 +++++++++++++++++++ 7 files changed, 68 insertions(+), 21 deletions(-) create mode 100644 gcc/testsuite/gcc.target/powerpc/pr108699.c -- 2.27.0 diff --git a/gcc/config/rs6000/altivec.md b/gcc/config/rs6000/altivec.md index 30606b8ab21..87053aa69b5 100644 --- a/gcc/config/rs6000/altivec.md +++ b/gcc/config/rs6000/altivec.md @@ -215,13 +215,6 @@ (define_mode_iterator VM2 [V4SI ;; versus floating point (define_mode_attr VS_sxwsp [(V4SI "sxw") (V4SF "sp")]) -;; Specific iterator for parity which does not have a byte/half-word form, but -;; does have a quad word form -(define_mode_iterator VParity [V4SI - V2DI - V1TI - TI]) - (define_mode_attr VI_char [(V2DI "d") (V4SI "w") (V8HI "h") (V16QI "b")]) (define_mode_attr VI_scalar [(V2DI "DI") (V4SI "SI") (V8HI "HI") (V16QI "QI")]) (define_mode_attr VI_unit [(V16QI "VECTOR_UNIT_ALTIVEC_P (V16QImode)") @@ -4195,9 +4188,11 @@ (define_insn "*p8v_popcount2" [(set_attr "type" "vecsimple")]) ;; Vector parity -(define_insn "*p9v_parity2" - [(set (match_operand:VParity 0 "register_operand" "=v") - (parity:VParity (match_operand:VParity 1 "register_operand" "v")))] +(define_insn "p9v_parityb2" + [(set (match_operand:VEC_IP 0 "register_operand" "=v") + (unspec:VEC_IP + [(match_operand:VEC_IP 1 "register_operand" "v")] + UNSPEC_PARITYB))] "TARGET_P9_VECTOR" "vprtyb %0,%1" [(set_attr "type" "vecsimple")]) diff --git a/gcc/config/rs6000/rs6000-builtins.def b/gcc/config/rs6000/rs6000-builtins.def index e0d9f5adc97..182e3fc5bdc 100644 --- a/gcc/config/rs6000/rs6000-builtins.def +++ b/gcc/config/rs6000/rs6000-builtins.def @@ -2666,13 +2666,13 @@ VMSUMUDM altivec_vmsumudm {} const vsll __builtin_altivec_vprtybd (vsll); - VPRTYBD parityv2di2 {} + VPRTYBD p9v_paritybv2di2 {} const vsq __builtin_altivec_vprtybq (vsq); - VPRTYBQ parityv1ti2 {} + VPRTYBQ p9v_paritybv1ti2 {} const vsi __builtin_altivec_vprtybw (vsi); - VPRTYBW parityv4si2 {} + VPRTYBW p9v_paritybv4si2 {} const vsll __builtin_altivec_vrldmi (vsll, vsll, vsll); VRLDMI altivec_vrldmi {} diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc index 16ca3a31757..bfa1060e55a 100644 --- a/gcc/config/rs6000/rs6000.cc +++ b/gcc/config/rs6000/rs6000.cc @@ -22973,12 +22973,12 @@ rs6000_emit_parity (rtx dst, rtx src) if (mode == SImode) { emit_insn (gen_popcntbsi2 (tmp, src)); - emit_insn (gen_paritysi2_cmpb (dst, tmp)); + emit_insn (gen_paritybsi2 (dst, tmp)); } else { emit_insn (gen_popcntbdi2 (tmp, src)); - emit_insn (gen_paritydi2_cmpb (dst, tmp)); + emit_insn (gen_paritybdi2 (dst, tmp)); } return; } diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md index 4a7812fa592..100ea115c5a 100644 --- a/gcc/config/rs6000/rs6000.md +++ b/gcc/config/rs6000/rs6000.md @@ -109,7 +109,7 @@ (define_c_enum "unspec" UNSPEC_MACHOPIC_OFFSET UNSPEC_BPERM UNSPEC_COPYSIGN - UNSPEC_PARITY + UNSPEC_PARITYB UNSPEC_CMPB UNSPEC_FCTIW UNSPEC_FCTID @@ -2501,9 +2501,10 @@ (define_expand "parity2" DONE; }) -(define_insn "parity2_cmpb" +(define_insn "parityb2" [(set (match_operand:GPR 0 "gpc_reg_operand" "=r") - (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")] UNSPEC_PARITY))] + (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")] + UNSPEC_PARITYB))] "TARGET_CMPB && TARGET_POPCNTB" "prty %0,%1" [(set_attr "type" "popcnt")]) diff --git a/gcc/config/rs6000/vector.md b/gcc/config/rs6000/vector.md index 12fd5f976ed..a70c9a2043d 100644 --- a/gcc/config/rs6000/vector.md +++ b/gcc/config/rs6000/vector.md @@ -33,8 +33,7 @@ (define_mode_iterator VEC_IC [V16QI V8HI V4SI V2DI (V1TI "TARGET_POWER10")]) (define_mode_iterator VEC_TI [V1TI TI]) ;; Vector int modes for parity -(define_mode_iterator VEC_IP [V8HI - V4SI +(define_mode_iterator VEC_IP [V4SI V2DI V1TI TI]) @@ -1226,7 +1225,16 @@ (define_expand "popcount2" (define_expand "parity2" [(set (match_operand:VEC_IP 0 "register_operand") (parity:VEC_IP (match_operand:VEC_IP 1 "register_operand")))] - "TARGET_P9_VECTOR") + "TARGET_P9_VECTOR" +{ + rtx op1 = gen_lowpart (V16QImode, operands[1]); + rtx res = gen_reg_rtx (V16QImode); + emit_insn (gen_popcountv16qi2 (res, op1)); + emit_insn (gen_p9v_parityb2 (operands[0], + gen_lowpart (mode, res))); + + DONE; +}) ;; Same size conversions diff --git a/gcc/testsuite/gcc.target/powerpc/p9-vparity.c b/gcc/testsuite/gcc.target/powerpc/p9-vparity.c index f4aba1567cd..8f6f1239f7a 100644 --- a/gcc/testsuite/gcc.target/powerpc/p9-vparity.c +++ b/gcc/testsuite/gcc.target/powerpc/p9-vparity.c @@ -105,3 +105,4 @@ parity_ti_4u (__uint128_t a) /* { dg-final { scan-assembler "vprtybd" } } */ /* { dg-final { scan-assembler "vprtybq" } } */ /* { dg-final { scan-assembler "vprtybw" } } */ +/* { dg-final { scan-assembler-not "vpopcntb" } } */ diff --git a/gcc/testsuite/gcc.target/powerpc/pr108699.c b/gcc/testsuite/gcc.target/powerpc/pr108699.c new file mode 100644 index 00000000000..f02bac130cc --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr108699.c @@ -0,0 +1,42 @@ +/* { dg-run } */ +/* { dg-options "-O2 -ftree-vectorize -fno-vect-cost-model" } */ + +#define N 16 + +unsigned long long vals[N]; +unsigned int res[N]; +unsigned int expects[N] = {0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + +unsigned long long inputs[N] + = {0x0000000000000000ULL, 0x0000000000000001ULL, 0x8000000000000000ULL, + 0x0000000000000002ULL, 0x4000000000000000ULL, 0x0000000100000000ULL, + 0x0000000080000000ULL, 0xa5a5a5a5a5a5a5a5ULL, 0x5a5a5a5a5a5a5a5aULL, + 0xcafecafe00000000ULL, 0x0000cafecafe0000ULL, 0x00000000cafecafeULL, + 0x8070600000000000ULL, 0xffffffffffffffffULL}; + +__attribute__ ((noipa)) void +init () +{ + for (int i = 0; i < N; i++) + vals[i] = inputs[i]; +} + +__attribute__ ((noipa)) void +do_parity () +{ + for (int i = 0; i < N; i++) + res[i] = __builtin_parityll (vals[i]); +} + +int +main (void) +{ + init (); + do_parity (); + for (int i = 0; i < N; i++) + if (res[i] != expects[i]) + __builtin_abort(); + + return 0; +} +