From patchwork Fri Feb 17 09:55:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kewen.Lin" X-Patchwork-Id: 58458 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp797597wrn; Fri, 17 Feb 2023 01:56:03 -0800 (PST) X-Google-Smtp-Source: AK7set8O/18DGhewDlEH9ngRltm6h3/yE5KTmTefmKzqtl/1kt3g6KV7D8KJGsrO0OYAqWkoIaC+ X-Received: by 2002:aa7:cd17:0:b0:4a0:e305:a0de with SMTP id b23-20020aa7cd17000000b004a0e305a0demr633039edw.19.1676627763317; Fri, 17 Feb 2023 01:56:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676627763; cv=none; d=google.com; s=arc-20160816; b=F7DhYaroL7UfKlSB4amc4V9Aoub/C+OBnQvF3nyWzOW/KaYL0bQA5XsZPSp4pM2b9s XbZeFtVkGfEMErY+NS03yfvwaY1zv2ZcclwiIUQn26Wdp+gPlu1ZnJlAV+BSMS27gc8K j7OIAl+hbh8mD8ISH4Mty2iowLZ/9t4h2Bb6wBk+/dS67FVxaDUs9CAU6l3NASBh02nm RkYCqdIJ4qzpGd9OL9Ou/Nt7kwFpUfuGhUmtJY07LPNGVfR3LXXA27P3Lf1NFDeuwkxL +yorHWF+XOLIXxbKwizD8tn0cKAW++NtJR92O9dpUUq5DPEAHHvlumoX6HZhi0IsfbQU 1c2g== 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=RGXCfFpdCphNKcYhGdX7lZTk7w5k94mpjxqdLFKdBGM=; b=INQnF+i1kRGwJUWY37fKk3L3e6Ajjg1FvTYK4G0+sxcSKLeXXELEiwMyPW/FbFKSBr fz9jQKDXeTf3Irwg8ABxI2Nde9g4NCLJGlfcYc9B2KewTXZ18PcLaF9Vg7gOXmYTvp8b lUu3XY1zxiPCrzHDNsZlV4lh09kRiODMEj0GiIi8JvDQsfvJ++HCo2EJoeoEP74snNq8 Ktaa0DjRwI1BQ5hi+DiuE+5Luzd3RvuNrcnxmJybHZh4k7hhnSGXLEpiqU+Wd4zrATNy 4hwHkuALqX4athsyFBcThOLrkhD41TOLTpsBmY0HbbtE/ja89WsSgAm9X++r1vE6k3sh A8uA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=AXaFabw3; 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 n7-20020aa7c687000000b004ad4c4b5ab2si4642876edq.392.2023.02.17.01.56.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Feb 2023 01:56:03 -0800 (PST) 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=AXaFabw3; 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 7AE18385417E for ; Fri, 17 Feb 2023 09:55:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7AE18385417E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676627758; bh=RGXCfFpdCphNKcYhGdX7lZTk7w5k94mpjxqdLFKdBGM=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=AXaFabw3qLgfvDJFX+xPiI7FoodeqZDkTYh9qe9F4yn9xBYHCR+KAWlx7knTMS26K OVzOq6Naiom+1AFcGgXRgdBouQId2oeYm4KpPkIiJNSJsvbt1vzT+Pz7rS1D7dU44c 9n4WXz9Q/4tKo76MOGxCd3MBoYvLPe+l3+QXsIVo= 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 02B80385781F for ; Fri, 17 Feb 2023 09:55:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 02B80385781F 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 31H7bU0p007200; Fri, 17 Feb 2023 09:55:12 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3nt2tfp966-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 17 Feb 2023 09:55:12 +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 31H9bOml002345; Fri, 17 Feb 2023 09:55:12 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 3nt2tfp95j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 17 Feb 2023 09:55:11 +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 31GJinTg031193; Fri, 17 Feb 2023 09:55:10 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3np29fqunr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 17 Feb 2023 09:55:10 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 31H9t7af53346660 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 Feb 2023 09:55:07 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B58CF2004B; Fri, 17 Feb 2023 09:55:07 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 056022004E; Fri, 17 Feb 2023 09:55:06 +0000 (GMT) Received: from [9.197.240.245] (unknown [9.197.240.245]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 17 Feb 2023 09:55:05 +0000 (GMT) Message-ID: <737a5392-29f8-763c-8dc7-b48c36edb1a7@linux.ibm.com> Date: Fri, 17 Feb 2023 17:55:04 +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 Subject: [PATCH] rs6000: Fix vector_set_var_p9 by considering BE [PR108807] X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: McXcTO4s_Htz4qCoEQb7vc1GW-PM2Cu5 X-Proofpoint-GUID: J0ObgaVTfGmMRI4pZH_ggHrJbiWidncn 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-17_05,2023-02-16_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=999 bulkscore=0 suspectscore=0 clxscore=1015 priorityscore=1501 spamscore=0 adultscore=0 lowpriorityscore=0 malwarescore=0 mlxscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302170086 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?1758071633855588224?= X-GMAIL-MSGID: =?utf-8?q?1758071633855588224?= Hi, As PR108807 exposes, the current handling in function rs6000_expand_vector_set_var_p9 doesn't take care of big endianness. Currently the function is to rotate the target vector by moving element to-be-set to element 0, set element 0 with the given val, then rotate back. To get the permutation control vector for the rotation, it makes use of lvsr and lvsl, but the element ordering is different for BE and LE (like element 0 is the most significant one on BE while the least significant one on LE), this patch is to add consideration for BE and make sure permutation control vectors for rotations are expected. As tested, it helped to fix the below failures: FAIL: gcc.target/powerpc/pr79251-run.p9.c execution test FAIL: gcc.target/powerpc/pr89765-mc.c execution test FAIL: gcc.target/powerpc/vsx-builtin-10d.c execution test FAIL: gcc.target/powerpc/vsx-builtin-11d.c execution test FAIL: gcc.target/powerpc/vsx-builtin-14d.c execution test FAIL: gcc.target/powerpc/vsx-builtin-16d.c execution test FAIL: gcc.target/powerpc/vsx-builtin-18d.c execution test FAIL: gcc.target/powerpc/vsx-builtin-9d.c execution test Bootstrapped and regtested on powerpc64-linux-gnu P{8,9} and powerpc64le-linux-gnu P10. Is it ok for trunk? BR, Kewen ----- PR target/108807 gcc/ChangeLog: * config/rs6000/rs6000.cc (rs6000_expand_vector_set_var_p9): Fix gen function for permutation control vector by considering big endianness. --- gcc/config/rs6000/rs6000.cc | 48 +++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 20 deletions(-) -- 2.39.1 diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc index 16ca3a31757..774eb2963d9 100644 --- a/gcc/config/rs6000/rs6000.cc +++ b/gcc/config/rs6000/rs6000.cc @@ -7235,22 +7235,26 @@ rs6000_expand_vector_set_var_p9 (rtx target, rtx val, rtx idx) machine_mode shift_mode; rtx (*gen_ashl)(rtx, rtx, rtx); - rtx (*gen_lvsl)(rtx, rtx); - rtx (*gen_lvsr)(rtx, rtx); + rtx (*gen_pcvr1)(rtx, rtx); + rtx (*gen_pcvr2)(rtx, rtx); if (TARGET_POWERPC64) { shift_mode = DImode; gen_ashl = gen_ashldi3; - gen_lvsl = gen_altivec_lvsl_reg_di; - gen_lvsr = gen_altivec_lvsr_reg_di; + gen_pcvr1 = BYTES_BIG_ENDIAN ? gen_altivec_lvsl_reg_di + : gen_altivec_lvsr_reg_di; + gen_pcvr2 = BYTES_BIG_ENDIAN ? gen_altivec_lvsr_reg_di + : gen_altivec_lvsl_reg_di; } else { shift_mode = SImode; gen_ashl = gen_ashlsi3; - gen_lvsl = gen_altivec_lvsl_reg_si; - gen_lvsr = gen_altivec_lvsr_reg_si; + gen_pcvr1 = BYTES_BIG_ENDIAN ? gen_altivec_lvsl_reg_si + : gen_altivec_lvsr_reg_si; + gen_pcvr2 = BYTES_BIG_ENDIAN ? gen_altivec_lvsr_reg_si + : gen_altivec_lvsl_reg_si; } /* Generate the IDX for permute shift, width is the vector element size. idx = idx * width. */ @@ -7259,25 +7263,29 @@ rs6000_expand_vector_set_var_p9 (rtx target, rtx val, rtx idx) emit_insn (gen_ashl (tmp, idx, GEN_INT (shift))); - /* lvsr v1,0,idx. */ - rtx pcvr = gen_reg_rtx (V16QImode); - emit_insn (gen_lvsr (pcvr, tmp)); - - /* lvsl v2,0,idx. */ - rtx pcvl = gen_reg_rtx (V16QImode); - emit_insn (gen_lvsl (pcvl, tmp)); + /* Generate one permutation control vector used for rotating the element + at to-insert position to element zero in target vector. lvsl is + used for big endianness while lvsr is used for little endianness: + lvs[lr] v1,0,idx. */ + rtx pcvr1 = gen_reg_rtx (V16QImode); + emit_insn (gen_pcvr1 (pcvr1, tmp)); rtx sub_target = simplify_gen_subreg (V16QImode, target, mode, 0); + rtx perm1 = gen_altivec_vperm_v8hiv16qi (sub_target, sub_target, sub_target, + pcvr1); + emit_insn (perm1); - rtx permr - = gen_altivec_vperm_v8hiv16qi (sub_target, sub_target, sub_target, pcvr); - emit_insn (permr); - + /* Insert val into element 0 of target vector. */ rs6000_expand_vector_set (target, val, const0_rtx); - rtx perml - = gen_altivec_vperm_v8hiv16qi (sub_target, sub_target, sub_target, pcvl); - emit_insn (perml); + /* Rotate back with a reversed permutation control vector generated from: + lvs[rl] v2,0,idx. */ + rtx pcvr2 = gen_reg_rtx (V16QImode); + emit_insn (gen_pcvr2 (pcvr2, tmp)); + + rtx perm2 = gen_altivec_vperm_v8hiv16qi (sub_target, sub_target, sub_target, + pcvr2); + emit_insn (perm2); } /* Insert VAL into IDX of TARGET, VAL size is same of the vector element, IDX