From patchwork Mon Mar 20 06:31:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kewen.Lin" X-Patchwork-Id: 72003 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1048751wrt; Sun, 19 Mar 2023 23:32:48 -0700 (PDT) X-Google-Smtp-Source: AK7set91GzUQsOHBNGPj4v7r8cUmBwJUXzzYcyRGxWo84qltli2U5v5AH2KrqhuZKEEXSCztOHRP X-Received: by 2002:a17:906:ae17:b0:930:8590:95ef with SMTP id le23-20020a170906ae1700b00930859095efmr7854046ejb.18.1679293968605; Sun, 19 Mar 2023 23:32:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679293968; cv=none; d=google.com; s=arc-20160816; b=TorUw9sZy8BQHYftYdGWB+/RuaQSM9QY+FaHqQF2Zzrno2jHuCOh9E0VdyhWHUgUJw 70sw+qa64OZcwy84sstzpRMVxkEgrx3vvIRcas9awH184HMwQfCEcn7dp1vgfhiBegC+ N5j5TbLiGOxEor9ZLS6SbWY55l9wybzH5Kj62PFlKMw8Du8zfz9Ii3i7fB8v04UEssqf 9gCElJR/95aXAkEmOBiEiXTJA/KfMk2wvnXKjTeu+ejP6EyhXy/Oza7WWBbTfqsaHj0m edGPRUPC8p2LjQTvEuqyFgAdd/JgTTvn3Awg+i10h1Ud2hL560ALgWy1Lagjei4nG5ue PcgA== 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:mime-version :content-transfer-encoding:cc:to:subject:content-language:user-agent :date:message-id:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=EfkUs3ruvyms2J/YnLQWNRvHC0gcX+JdIjVyeh1uyGk=; b=ZKL3NnrOTQiRV9GXuAonGpVvJdpQarSmwBtvEAlrFCdUx/BAdpXC7xyY2chryJqSMc GbljPr9lykq4xZKNMzOh2oSzkAChRhxtZnmG8tQjzvv0A3FAzPQP6Fk9kRFn21L7VaRJ xlKwmcZfnN8F3iJsVspzZsz0Gy2P0b3RfEHejIaMH/dnfQ97XegxaF153NIFo6eTtYzv gqDBZfH96i0ljQ9Lv+RVi9UmQ3dfDBBM/+ttGbFEUCh9biEQtg4mRYuT2MuXP2yENsMe jspuRxp5AE5RgX0jsY1RZTq0E6k+L762EIphDcsKeiHpb2iIxeImQUoJwmN8o8PTrLTB QBDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=S7A2tplV; 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 sd23-20020a1709076e1700b009326610a131si9660232ejc.154.2023.03.19.23.32.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Mar 2023 23:32:48 -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=S7A2tplV; 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 6BA9A38515D0 for ; Mon, 20 Mar 2023 06:32:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6BA9A38515D0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679293946; bh=EfkUs3ruvyms2J/YnLQWNRvHC0gcX+JdIjVyeh1uyGk=; h=Date:Subject:To:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=S7A2tplVJstm4675tYIs2oSxpQqcaJW+2Veg6G6dFhzCc6vjdhE9sdkwHWc5LNdeF tx0Awv8FhTsLgRdqut4KjozMw4k79YzgEpdXw62FxZGvTB/qWouYpb64nPRktYCL04 1KEcyEjl8+vzlxrvj4QxfsuCZtTtOpD6nsAQjtfE= 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 EC67138555A0 for ; Mon, 20 Mar 2023 06:31:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EC67138555A0 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32K4ZmVD026641; Mon, 20 Mar 2023 06:31:40 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3pdpvrqnxh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Mar 2023 06:31:40 +0000 Received: from m0098419.ppops.net (m0098419.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 32K6FPUK009796; Mon, 20 Mar 2023 06:31:39 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 3pdpvrqnx2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Mar 2023 06:31:39 +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 32K47D6K015074; Mon, 20 Mar 2023 06:31:37 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3pd4jfasx2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Mar 2023 06:31:37 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 32K6VZFg57868636 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Mar 2023 06:31:35 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5A73120043; Mon, 20 Mar 2023 06:31:35 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9CF3120040; Mon, 20 Mar 2023 06:31:33 +0000 (GMT) Received: from [9.177.11.227] (unknown [9.177.11.227]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 20 Mar 2023 06:31:33 +0000 (GMT) Message-ID: <65e0c779-7764-bd67-649f-5c225c42949c@linux.ibm.com> Date: Mon, 20 Mar 2023 14:31:31 +0800 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 Subject: [PATCH v3] rs6000: Fix vector parity support [PR108699] To: GCC Patches Cc: Segher Boessenkool , David Edelsohn , Peter Bergner X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: ndCVWBaO2USPpockZkZo134C7XkxW23x X-Proofpoint-GUID: mpvn7S5st6uHy0zZXPnOlx602NG2dRaA X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-20_02,2023-03-16_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 phishscore=0 malwarescore=0 impostorscore=0 mlxlogscore=999 lowpriorityscore=0 adultscore=0 clxscore=1015 spamscore=0 suspectscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303150002 definitions=main-2303200053 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_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: "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?1760867352196989761?= X-GMAIL-MSGID: =?utf-8?q?1760867352196989761?= 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 insn vpopcntb. Comparing to v2 [1]: - Use rs6000_vprtyb2 rather than parityb2, and adjust several places with it accordingly. Bootstrapped and regtested on powerpc64-linux-gnu P{8,9} and powerpc64le-linux-gnu P10. Is it ok for trunk? [1] https://gcc.gnu.org/pipermail/gcc-patches/2023-February/612212.html BR, Kewen ----- PR target/108699 gcc/ChangeLog: * config/rs6000/altivec.md (*p9v_parity2): Rename to ... (rs6000_vprtyb2): ... this. * config/rs6000/rs6000-builtins.def (VPRTYBD): Replace parityv2di2 with rs6000_vprtybv2di2. (VPRTYBW): Replace parityv4si2 with rs6000_vprtybv4si2. (VPRTYBQ): Replace parityv1ti2 with rs6000_vprtybv1ti2. * config/rs6000/vector.md (parity2 with VEC_IP): Expand with popcountv16qi2 and the corresponding rs6000_vprtyb2. 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 | 8 ++-- gcc/config/rs6000/rs6000-builtins.def | 6 +-- gcc/config/rs6000/vector.md | 11 ++++- gcc/testsuite/gcc.target/powerpc/p9-vparity.c | 1 + gcc/testsuite/gcc.target/powerpc/pr108699.c | 42 +++++++++++++++++++ 5 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gcc.target/powerpc/pr108699.c -- 2.39.1 diff --git a/gcc/config/rs6000/altivec.md b/gcc/config/rs6000/altivec.md index 30606b8ab21..49b0c964f4d 100644 --- a/gcc/config/rs6000/altivec.md +++ b/gcc/config/rs6000/altivec.md @@ -4195,9 +4195,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 "rs6000_vprtyb2" + [(set (match_operand:VEC_IP 0 "register_operand" "=v") + (unspec:VEC_IP + [(match_operand:VEC_IP 1 "register_operand" "v")] + UNSPEC_PARITY))] "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..03fb194b151 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 rs6000_vprtybv2di2 {} const vsq __builtin_altivec_vprtybq (vsq); - VPRTYBQ parityv1ti2 {} + VPRTYBQ rs6000_vprtybv1ti2 {} const vsi __builtin_altivec_vprtybw (vsi); - VPRTYBW parityv4si2 {} + VPRTYBW rs6000_vprtybv4si2 {} const vsll __builtin_altivec_vrldmi (vsll, vsll, vsll); VRLDMI altivec_vrldmi {} diff --git a/gcc/config/rs6000/vector.md b/gcc/config/rs6000/vector.md index 12fd5f976ed..1ae04c8e0a8 100644 --- a/gcc/config/rs6000/vector.md +++ b/gcc/config/rs6000/vector.md @@ -1226,7 +1226,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_rs6000_vprtyb2 (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; +} +