From patchwork Mon Mar 27 08:09:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kewen.Lin" X-Patchwork-Id: 75250 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1346206vqo; Mon, 27 Mar 2023 01:11:23 -0700 (PDT) X-Google-Smtp-Source: AKy350ZY382Ut0lPgCXOu2z2KWIwRjRS5yVv/ULlfyj4AZtcpV1eDfvHYO1IBg6LxT1xb2SQSWkl X-Received: by 2002:a17:906:c003:b0:92f:7c42:8637 with SMTP id e3-20020a170906c00300b0092f7c428637mr11929660ejz.30.1679904683647; Mon, 27 Mar 2023 01:11:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679904683; cv=none; d=google.com; s=arc-20160816; b=nWK572iNPLjMMfF8roJRHZo8TQMR87xsWcYx5ktPk6mbmGenw+Ct+95Z+fkTZdmcNF TxpsmWOs7aYCdRRsg09o+pc5vG20RpJOTZGbAmbtc2mtbc9MNs4gaR9YdF0D5qy2uv1M kHVaUeg3JD9Aq8Q3gPjtDODs5L0W2GuFkbaQ43vAPyLm0BSRYydTdV9QBiNXHmhJ2oRI JlyPPZyjMAWISKCWMGZO8t42xh8gkEjyVelSZkXxm2LhuuPaUIr0jfe5HJxi2KAjgcXw ij2QAXUX1wtt9SyDFLCeM6C4PuircRjw0hm4ZhQ73+XcxDLHXh33pp8YYoCmW+6WNd4M B0+g== 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=LtGdjk2cjzRib0dBMEoA2AVDCr2bQiGjVFeci/fDmpo=; b=0CKL4o/zw6BvNz00IxgxkMKcmrYxuakjPnFqLSi2/QO1GhB7S6TmcdnhGko6gvopZV WxGjz0fGDGCa9gKifILL/48YWCVwp2RuYEhhLwr2/YxQP4CCc8RHI0Qc4qF/9lDQK92a Z0xhCBgzFGkR0XkxSdSdeqXoXhcqWL8D0ogZAEm/nRmHypTRT5jrkigCbHR/VW36U/AL mzrDTfW0J9s7v+KOtVKQVWHrPcYXkfjUzIkPPa96E3suqHO/up5qF5pF2YI3NIcCh642 r74OYajz+u0/5OgdDDjreT5Q84atF/xqujdUxV/M3GlWgbysC0GoMBbvT9Dp9lHYCLVr 6AZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=RJ7pGEOS; 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 fx11-20020a170906b74b00b008d10fe78243si26772708ejb.878.2023.03.27.01.11.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 01:11:23 -0700 (PDT) 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=RJ7pGEOS; 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 892433850216 for ; Mon, 27 Mar 2023 08:10:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 892433850216 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679904654; bh=LtGdjk2cjzRib0dBMEoA2AVDCr2bQiGjVFeci/fDmpo=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=RJ7pGEOSuBxbG/yJrDZtOMfgDPCcPLAnL72exsEev49Xfhqq5VPF40BuBYzZjVcV6 MC0DXZ1Iw9KCg5aik3IzHg4OSnoqfQQ88yO1WYoUjQFsFHcoI8n/eHzeh+0gT8ZA5a tZHERROaeD266irkTkyGz4I6nerSBBchb9EXrLqw= 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 5551F3858288 for ; Mon, 27 Mar 2023 08:10:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5551F3858288 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32R7Nd07010380; Mon, 27 Mar 2023 08:10:02 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3pjasr946e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Mar 2023 08:10:01 +0000 Received: from m0098396.ppops.net (m0098396.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 32R8139l026091; Mon, 27 Mar 2023 08:09:58 GMT Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3pjasr941b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Mar 2023 08:09:57 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 32R2GIRG007719; Mon, 27 Mar 2023 08:09:47 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma06fra.de.ibm.com (PPS) with ESMTPS id 3phr7ft6nx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 27 Mar 2023 08:09:47 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 32R89hdM39977282 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Mar 2023 08:09:43 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8B36720040; Mon, 27 Mar 2023 08:09:43 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7977D2004E; Mon, 27 Mar 2023 08:09:41 +0000 (GMT) Received: from [9.177.0.115] (unknown [9.177.0.115]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 27 Mar 2023 08:09:41 +0000 (GMT) Message-ID: <61d8cd78-e20f-e545-5a22-188794168e7f@linux.ibm.com> Date: Mon, 27 Mar 2023 16:09:39 +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 predicate for const vector in sldoi_to_mov [PR109069] X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: xQjp2weuzLWZePe3DpAnFRAOhdPIiEAB X-Proofpoint-GUID: ZZTc2DCks8lC_ULiS-7GVwU2L7Fm7r61 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-24_11,2023-03-24_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 lowpriorityscore=0 suspectscore=0 bulkscore=0 phishscore=0 impostorscore=0 adultscore=0 mlxscore=0 priorityscore=1501 spamscore=0 clxscore=1015 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2303270065 X-Spam-Status: No, score=-11.4 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?1761507733583384168?= X-GMAIL-MSGID: =?utf-8?q?1761507733583384168?= Hi, As PR109069 shows, commit r12-6537-g080a06fcb076b3 which introduces define_insn_and_split sldoi_to_mov adopts easy_vector_constant for const vector of interest, but it's wrong since predicate easy_vector_constant doesn't guarantee each byte in the const vector is the same. One counter example is the const vector in pr109069-1.c. This patch is to introduce new predicate const_vector_each_byte_same to ensure all bytes in the given const vector are the same by considering both int and float, meanwhile for the constants which don't meet easy_vector_constant we need to gen a move instead of just a set, and uses VECTOR_MEM_ALTIVEC_OR_VSX_P rather than VECTOR_UNIT_ALTIVEC_OR_VSX_P for V2DImode support under VSX since vector long long type of vec_sld is guarded under stanza vsx. Bootstrapped and regtested on powerpc64-linux-gnu P7/P8/P9 and powerpc64le-linux-gnu P9 and P10. Is it ok for trunk? BR, Kewen ----- PR target/109069 gcc/ChangeLog: * config/rs6000/altivec.md (sldoi_to_mov): Replace predicate easy_vector_constant with const_vector_each_byte_same, add handlings in preparation for !easy_vector_constant, and update VECTOR_UNIT_ALTIVEC_OR_VSX_P with VECTOR_MEM_ALTIVEC_OR_VSX_P. * config/rs6000/predicates.md (const_vector_each_byte_same): New predicate. gcc/testsuite/ChangeLog: * gcc.target/powerpc/pr109069-1.c: New test. * gcc.target/powerpc/pr109069-2-run.c: New test. * gcc.target/powerpc/pr109069-2.c: New test. * gcc.target/powerpc/pr109069-2.h: New test. --- gcc/config/rs6000/altivec.md | 14 +++- gcc/config/rs6000/predicates.md | 37 +++++++++ gcc/testsuite/gcc.target/powerpc/pr109069-1.c | 25 ++++++ .../gcc.target/powerpc/pr109069-2-run.c | 50 +++++++++++ gcc/testsuite/gcc.target/powerpc/pr109069-2.c | 12 +++ gcc/testsuite/gcc.target/powerpc/pr109069-2.h | 83 +++++++++++++++++++ 6 files changed, 218 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.target/powerpc/pr109069-1.c create mode 100644 gcc/testsuite/gcc.target/powerpc/pr109069-2-run.c create mode 100644 gcc/testsuite/gcc.target/powerpc/pr109069-2.c create mode 100644 gcc/testsuite/gcc.target/powerpc/pr109069-2.h -- 2.31.1 diff --git a/gcc/config/rs6000/altivec.md b/gcc/config/rs6000/altivec.md index 30606b8ab21..183c3005694 100644 --- a/gcc/config/rs6000/altivec.md +++ b/gcc/config/rs6000/altivec.md @@ -385,14 +385,22 @@ (define_split (define_insn_and_split "sldoi_to_mov" [(set (match_operand:VM 0 "altivec_register_operand") - (unspec:VM [(match_operand:VM 1 "easy_vector_constant") + (unspec:VM [(match_operand:VM 1 "const_vector_each_byte_same") (match_dup 1) (match_operand:QI 2 "u5bit_cint_operand")] UNSPEC_VSLDOI))] - "VECTOR_UNIT_ALTIVEC_OR_VSX_P (mode) && can_create_pseudo_p ()" + "VECTOR_MEM_ALTIVEC_OR_VSX_P (mode) && can_create_pseudo_p ()" "#" "&& 1" - [(set (match_dup 0) (match_dup 1))]) + [(set (match_dup 0) (match_dup 1))] + "{ + if (!easy_vector_constant (operands[1], mode)) + { + rtx dest = gen_reg_rtx (mode); + emit_move_insn (dest, operands[1]); + operands[1] = dest; + } + }") (define_insn "get_vrsave_internal" [(set (match_operand:SI 0 "register_operand" "=r") diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md index 52c65534e51..a16ee30f0c0 100644 --- a/gcc/config/rs6000/predicates.md +++ b/gcc/config/rs6000/predicates.md @@ -798,6 +798,43 @@ (define_predicate "easy_vector_constant_vsldoi" (and (match_test "easy_altivec_constant (op, mode)") (match_test "vspltis_shifted (op) != 0"))))) +;; Return true if this is a vector constant and each byte in +;; it is the same. +(define_predicate "const_vector_each_byte_same" + (match_code "const_vector") +{ + rtx elt; + if (!const_vec_duplicate_p (op, &elt)) + return false; + + machine_mode emode = GET_MODE_INNER (mode); + unsigned HOST_WIDE_INT eval; + if (CONST_INT_P (elt)) + eval = INTVAL (elt); + else if (CONST_DOUBLE_AS_FLOAT_P (elt)) + { + gcc_assert (emode == SFmode || emode == DFmode); + long l[2]; + real_to_target (l, CONST_DOUBLE_REAL_VALUE (elt), emode); + /* real_to_target puts 32-bit pieces in each long. */ + eval = zext_hwi (l[0], 32); + eval |= zext_hwi (l[1], 32) << 32; + } + else + return false; + + unsigned int esize = GET_MODE_SIZE (emode); + unsigned char byte0 = eval & 0xff; + for (unsigned int i = 1; i < esize; i++) + { + eval >>= BITS_PER_UNIT; + if (byte0 != (eval & 0xff)) + return false; + } + + return true; +}) + ;; Return 1 if operand is a vector int register or is either a vector constant ;; of all 0 bits of a vector constant of all 1 bits. (define_predicate "vector_int_reg_or_same_bit" diff --git a/gcc/testsuite/gcc.target/powerpc/pr109069-1.c b/gcc/testsuite/gcc.target/powerpc/pr109069-1.c new file mode 100644 index 00000000000..eb4d73a1e66 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr109069-1.c @@ -0,0 +1,25 @@ +/* { dg-do run } */ +/* { dg-require-effective-target vmx_hw } */ +/* { dg-options "-O2 -maltivec" } */ + +/* Verify it run successfully. */ + +#include + +__attribute__ ((noipa)) +vector signed int +test () +{ + vector signed int v = {-16, -16, -16, -16}; + vector signed int res = vec_sld (v, v, 3); + return res; +} + +int +main () +{ + vector signed int res = test (); + if (res[0] != 0xf0ffffff) + __builtin_abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.target/powerpc/pr109069-2-run.c b/gcc/testsuite/gcc.target/powerpc/pr109069-2-run.c new file mode 100644 index 00000000000..fad9fa5df73 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr109069-2-run.c @@ -0,0 +1,50 @@ +/* { dg-do run } */ +/* { dg-require-effective-target vsx_hw } */ +/* { dg-options "-O2 -mvsx" } */ + +/* Verify it doesn't generate wrong code. */ + +#include "pr109069-2.h" + +int +main () +{ + vector unsigned char res1 = test1 (); + for (int i = 0; i < 16; i++) + if (res1[i] != 0xd) + __builtin_abort (); + + vector signed short res2 = test2 (); + for (int i = 0; i < 8; i++) + if (res2[i] != 0x7777) + __builtin_abort (); + + vector signed int res3 = test3 (); + vector unsigned int res4 = test4 (); + vector float res6 = test6 (); + for (int i = 0; i < 4; i++) + { + if (res3[i] != 0xbbbbbbbb) + __builtin_abort (); + if (res4[i] != 0x7070707) + __builtin_abort (); + U32b u; + u.f = res6[i]; + if (u.i != 0x17171717) + __builtin_abort (); + } + + vector unsigned long long res5 = test5 (); + vector double res7 = test7 (); + for (int i = 0; i < 2; i++) + { + if (res5[i] != 0x4545454545454545ll) + __builtin_abort (); + U64b u; + u.f = res7[i]; + if (u.i != 0x5454545454545454ll) + __builtin_abort (); + } + return 0; +} + diff --git a/gcc/testsuite/gcc.target/powerpc/pr109069-2.c b/gcc/testsuite/gcc.target/powerpc/pr109069-2.c new file mode 100644 index 00000000000..e71bbeb5df5 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr109069-2.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target powerpc_vsx_ok } */ +/* Disable rs6000 optimize_swaps as it drops some REG_EQUAL + notes on const vector and affects test point here. */ +/* { dg-options "-O2 -mvsx -mno-optimize-swaps" } */ + +/* Verify we can optimize away vector shifting if every byte + of vector is the same. */ + +#include "pr109069-2.h" + +/* { dg-final { scan-assembler-not {\mvsldoi\M} } } */ diff --git a/gcc/testsuite/gcc.target/powerpc/pr109069-2.h b/gcc/testsuite/gcc.target/powerpc/pr109069-2.h new file mode 100644 index 00000000000..8b03bfb65fa --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr109069-2.h @@ -0,0 +1,83 @@ +#include + +typedef union +{ + unsigned int i; + float f; +} U32b; + +typedef union +{ + unsigned long long i; + double f; +} U64b; + +__attribute__ ((noipa)) +vector unsigned char +test1 () +{ + vector unsigned char v = {0xd, 0xd, 0xd, 0xd, 0xd, 0xd, 0xd, 0xd, + 0xd, 0xd, 0xd, 0xd, 0xd, 0xd, 0xd, 0xd}; + vector unsigned char res = vec_sld (v, v, 3); + return res; +} + +__attribute__ ((noipa)) +vector signed short +test2 () +{ + vector signed short v + = {0x7777, 0x7777, 0x7777, 0x7777, 0x7777, 0x7777, 0x7777, 0x7777}; + vector signed short res = vec_sld (v, v, 5); + return res; +} + +__attribute__ ((noipa)) +vector signed int +test3 () +{ + vector signed int v = {0xbbbbbbbb, 0xbbbbbbbb, 0xbbbbbbbb, 0xbbbbbbbb}; + vector signed int res = vec_sld (v, v, 7); + return res; +} + +__attribute__ ((noipa)) +vector unsigned int +test4 () +{ + vector unsigned int v = {0x07070707, 0x07070707, 0x07070707, 0x07070707}; + vector unsigned int res = vec_sld (v, v, 9); + return res; +} + +__attribute__ ((noipa)) +vector unsigned long long +test5 () +{ + vector unsigned long long v = {0x4545454545454545ll, 0x4545454545454545ll}; + vector unsigned long long res = vec_sld (v, v, 10); + return res; +} + +__attribute__ ((noipa)) +vector float +test6 () +{ + U32b u; + u.i = 0x17171717; + vector float vf = {u.f, u.f, u.f, u.f}; + vector float res = vec_sld (vf, vf, 11); + return res; +} + +__attribute__ ((noipa)) +vector double +test7 () +{ + U64b u; + u.i = 0x5454545454545454ll; + vector double vf = {u.f, u.f}; + vector double res = vec_sld (vf, vf, 13); + return res; +} +