From patchwork Mon Oct 9 02:30:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: HAO CHEN GUI X-Patchwork-Id: 149812 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1617182vqo; Sun, 8 Oct 2023 19:31:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEHkaAOD3gh5vcms8oCi3K9EvtVA/aIQTURw6o9QIRi0wbG6skN9qUqyckukmD+KQj2uR9f X-Received: by 2002:a17:906:538f:b0:99e:f3b:2f78 with SMTP id g15-20020a170906538f00b0099e0f3b2f78mr13637823ejo.67.1696818688619; Sun, 08 Oct 2023 19:31:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696818688; cv=none; d=google.com; s=arc-20160816; b=eaoYIEqvXNK7+HqOteuMm+wdenc4MRzUPs3J4mxC+pAVmfFH6FW19OaRjLUYAL9hb/ F4kD+FKsirlSOYy9bC7B4iCwRtx9c1PKhVgVaHfH3yAgZYUyFCBQE0qSek4bhwxrhacY JuD0Mkcs9IkLqnCbWLAq8gZ2ZR7GVz8yv7m0JE5replrpMnYYeWX8PWxya8L6bSxgNOL 9WmTC0DWLyLNTAFQSv7dJRjXpqDHUECVT3OAmHRLMrmi0Z17JI/HEjqMBlQGjKU5lH1Q UwloniJomby9FGW2I4yP0DpYidwOA1M3o6N2IhyW6zvuyUSZqh6ZIJuAg957LxiyX8sR po8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:dkim-signature:dmarc-filter:delivered-to; bh=cP7MOb32pi25WWeMFptGWOH07Espu14R9V+qz0m1eIg=; fh=3eUSxJU+9IWNwGHlMjnmqDQDnJfeMKAjlglEUO7a4vw=; b=wGFGPhyKXTLpqAwchtew7oB+uDMRyHiyX49k0tvsXy65WNWSQALB7+2u5+D4AgHp6W 93XfZiJTTmZ+7O5MrC9AkoiAGCdQyXb8c4Kd6Wgz5hAYXWgLKvEa3UBo+k08K6evsggL PxT/WPEgB6PkF9qwOj2kqjRw7zxXqoPbN+WnzZFTt6ug4Fjlji7ARW176sCEOOERFzuf aQH0ZTBChtRJXLIt1oczhhUW50/Ul7irX4LrKc92vrhxx3w3ChGGig4PeZQfEQCuFqsV Gw18GrBBPV3/+urRgMMCsqRDG7ax2SKJIBs5PWnfaH0QhJTCnsKfwUWYVPqyR9aqc+1r f8Mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=gFh0X04i; 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=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id u24-20020a170906069800b009ae20605ce0si4132904ejb.323.2023.10.08.19.31.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 19:31:28 -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=@ibm.com header.s=pp1 header.b=gFh0X04i; 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=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3C653385701C for ; Mon, 9 Oct 2023 02:31:12 +0000 (GMT) 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 416F63857707 for ; Mon, 9 Oct 2023 02:30:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 416F63857707 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3992HJ0n023920; Mon, 9 Oct 2023 02:30:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : mime-version : to : cc : from : subject : content-type : content-transfer-encoding; s=pp1; bh=cP7MOb32pi25WWeMFptGWOH07Espu14R9V+qz0m1eIg=; b=gFh0X04iObtyxK4fTSodcd9hI4wCbzeDqoF1ckVbjuMHe7oHWFjBZxODoB7KpqVis/m2 Z0af/yGlO4u+Swlc2gdWx8txY/koAWG2TlbplKYi9zZv7zYDVHfZZ/sgsH1fPCeKfUxh ZRTKboOHJ5wysUZjAPmQ1v0ppZUjjersnUchBJgtElKWyFqobe6ydbO8E4tMWLxP6JQN ZtVKbIqv8TtTTmicC5KTVD7NoDeSh9d2u8ZTlnjafQToKBOtXxJm8jAlIP4Aiefdt9KY hnEV0ycgeKzKjViczmZgzImdxHQri2hQ2JaXow4L4LcTI+LSdipHQm9Rt6db7ZKaAUGW Cw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3tm8ks06tx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Oct 2023 02:30:44 +0000 Received: from m0360083.ppops.net (m0360083.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3992ItSF028846; Mon, 9 Oct 2023 02:30:44 GMT Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3tm8ks06tt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Oct 2023 02:30:44 +0000 Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 399139Jk024487; Mon, 9 Oct 2023 02:30:43 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3tkhns6f3j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Oct 2023 02:30:43 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3992Uelx2359836 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 9 Oct 2023 02:30:40 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B031D20040; Mon, 9 Oct 2023 02:30:40 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E0A2420043; Mon, 9 Oct 2023 02:30:38 +0000 (GMT) Received: from [9.200.63.48] (unknown [9.200.63.48]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 9 Oct 2023 02:30:38 +0000 (GMT) Message-ID: Date: Mon, 9 Oct 2023 10:30:38 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Content-Language: en-US To: gcc-patches Cc: Segher Boessenkool , David , "Kewen.Lin" , Peter Bergner From: HAO CHEN GUI Subject: [PATCH-2, rs6000] Enable vector mode for memory equality compare [PR111449] X-TM-AS-GCONF: 00 X-Proofpoint-GUID: rnahoIVT8Y-uB3VuFq-Pm5VvuOVMKbJu X-Proofpoint-ORIG-GUID: VDhbDNsGIy1ROxSojGFC1dSFoxPzJV0z X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-09_01,2023-10-06_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 priorityscore=1501 mlxlogscore=999 suspectscore=0 malwarescore=0 lowpriorityscore=0 adultscore=0 impostorscore=0 clxscore=1015 spamscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310090020 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779243353526582997 X-GMAIL-MSGID: 1779243353526582997 Hi, This patch enables vector mode for memory equality compare by adding a new expand cbranchv16qi4 and implementing it. Also the corresponding CC reg and compare code is set in rs6000_generate_compare. With the patch, 16-byte equality compare can be implemented by one vector compare instructions other than 2 8-byte compares with branches. The test case is in the second patch which is rs6000 specific. Bootstrapped and tested on powerpc64-linux BE and LE with no regressions. Thanks Gui Haochen ChangeLog rs6000: Enable vector compare for memory equality compare gcc/ PR target/111449 * config/rs6000/altivec.md (cbranchv16qi4): New expand pattern. * config/rs6000/rs6000.cc (rs6000_generate_compare): Generate insn sequence for V16QImode equality compare. * config/rs6000/rs6000.h (MOVE_MAX_PIECES): Define. (COMPARE_MAX_PIECES): Define. gcc/testsuite/ PR target/111449 * gcc.target/powerpc/pr111449.c: New. patch.diff diff --git a/gcc/config/rs6000/altivec.md b/gcc/config/rs6000/altivec.md index e8a596fb7e9..c69bf266402 100644 --- a/gcc/config/rs6000/altivec.md +++ b/gcc/config/rs6000/altivec.md @@ -2605,6 +2605,39 @@ (define_insn "altivec_vupklpx" } [(set_attr "type" "vecperm")]) +(define_expand "cbranchv16qi4" + [(use (match_operator 0 "equality_operator" + [(match_operand:V16QI 1 "gpc_reg_operand") + (match_operand:V16QI 2 "gpc_reg_operand")])) + (use (match_operand 3))] + "VECTOR_UNIT_ALTIVEC_P (V16QImode)" +{ + if (!TARGET_P9_VECTOR + && MEM_P (operands[1]) + && !altivec_indexed_or_indirect_operand (operands[1], V16QImode) + && MEM_P (operands[2]) + && !altivec_indexed_or_indirect_operand (operands[2], V16QImode)) + { + /* Use direct move as the byte order doesn't matter for equality + compare. */ + rtx reg_op1 = gen_reg_rtx (V16QImode); + rtx reg_op2 = gen_reg_rtx (V16QImode); + rs6000_emit_le_vsx_permute (reg_op1, operands[1], V16QImode); + rs6000_emit_le_vsx_permute (reg_op2, operands[2], V16QImode); + operands[1] = reg_op1; + operands[2] = reg_op2; + } + else + { + operands[1] = force_reg (V16QImode, operands[1]); + operands[2] = force_reg (V16QImode, operands[2]); + } + rtx_code code = GET_CODE (operands[0]); + operands[0] = gen_rtx_fmt_ee (code, V16QImode, operands[1], operands[2]); + rs6000_emit_cbranch (V16QImode, operands); + DONE; +}) + ;; Compare vectors producing a vector result and a predicate, setting CR6 to ;; indicate a combined status (define_insn "altivec_vcmpequ_p" diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc index efe9adce1f8..0087d786840 100644 --- a/gcc/config/rs6000/rs6000.cc +++ b/gcc/config/rs6000/rs6000.cc @@ -15264,6 +15264,15 @@ rs6000_generate_compare (rtx cmp, machine_mode mode) else emit_insn (gen_stack_protect_testsi (compare_result, op0, op1b)); } + else if (mode == V16QImode) + { + gcc_assert (code == EQ || code == NE); + + rtx result_vector = gen_reg_rtx (V16QImode); + compare_result = gen_rtx_REG (CCmode, CR6_REGNO); + emit_insn (gen_altivec_vcmpequb_p (result_vector, op0, op1)); + code = (code == NE) ? GE : LT; + } else emit_insn (gen_rtx_SET (compare_result, gen_rtx_COMPARE (comp_mode, op0, op1))); diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h index 3503614efbd..dc33bca0802 100644 --- a/gcc/config/rs6000/rs6000.h +++ b/gcc/config/rs6000/rs6000.h @@ -1730,6 +1730,8 @@ typedef struct rs6000_args in one reasonably fast instruction. */ #define MOVE_MAX (! TARGET_POWERPC64 ? 4 : 8) #define MAX_MOVE_MAX 8 +#define MOVE_MAX_PIECES (!TARGET_POWERPC64 ? 4 : 16) +#define COMPARE_MAX_PIECES (!TARGET_POWERPC64 ? 4 : 16) /* Nonzero if access to memory by bytes is no faster than for words. Also nonzero if doing byte operations (specifically shifts) in registers diff --git a/gcc/testsuite/gcc.target/powerpc/pr111449.c b/gcc/testsuite/gcc.target/powerpc/pr111449.c new file mode 100644 index 00000000000..a8c30b92a41 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr111449.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target powerpc_p8vector_ok } */ +/* { dg-options "-maltivec -O2" } */ +/* { dg-require-effective-target has_arch_ppc64 } */ + +/* Ensure vector comparison is used for 16-byte memory equality compare. */ + +int compare1 (const char* s1, const char* s2) +{ + return __builtin_memcmp (s1, s2, 16) == 0; +} + +int compare2 (const char* s1) +{ + return __builtin_memcmp (s1, "0123456789012345", 16) == 0; +} + +/* { dg-final { scan-assembler-times {\mvcmpequb\.} 2 } } */ +/* { dg-final { scan-assembler-not {\mcmpd\M} } } */