From patchwork Mon Oct 9 02:30:15 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: 149811 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1617018vqo; Sun, 8 Oct 2023 19:30:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGb+UWa3/kokkH1AlRwXsIlUgqEmimp/LB6eSEoBAPmm7Vak/x4yOApanv//Mdhe/eEkDV6 X-Received: by 2002:a17:907:78d1:b0:9b3:264:446 with SMTP id kv17-20020a17090778d100b009b302640446mr12989070ejc.0.1696818653002; Sun, 08 Oct 2023 19:30:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696818652; cv=none; d=google.com; s=arc-20160816; b=jFHLNcaKOFmMfAQmQaWQYF2d1YtEp1ZghFPVocoeETpt9Mgsn4a087+UD99zdRD27M /y2SAROh5Q6CAeTBAqkIb0lTZrD0VupAxTQhKZ2mnaX+14+PG4eVV/KOGK5hyZnD7zbI 83f9d7Q968QQLaUZ7sdftgLRs4YOdrcTs2AjLoFb1Ep3cs8bq+dF4D5zBL9KDhy9+RWE 0OWYT/tvuXOZT6wFvsX3bggV2pTWVl3T44mLaBzffKOAj4p1oBBHxhXS8PpLWzB/nKoJ V/56Fbg1vMBwIrin5IYYEs3O6OSlgU4AhmoTpf1Tf0xy3TqS7uohGr5idIhtbHZpxHfE PiwA== 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=j50PXhWdl6tir0Vn2IRsi6O4pvVWd4PVK/IEqxTcnvI=; fh=3eUSxJU+9IWNwGHlMjnmqDQDnJfeMKAjlglEUO7a4vw=; b=AWeUMeo1rIz+OUtOnP3CVpH6c+GEA7eeTzmOrzHgZX6xBAWTHj+FlwtZ42tZ4ox14D eYt/WONltiRm9IC63hXipEOWb4G3q6X4q0MMLgfOTX+2u8M/sfbMxPqgZ7fddTNWZQDo HOBY8lhkxI+lx4jgH8IAuX9HzBVooQkLJkaPXIfyGDRJKwj5jouufsAXF7VR4d4whBRG MWwS9fBoZaxEZls7ybaPTriCnq/OxfFMzy5h7/8Bi1oeccJ8XzVr5rLU3LVVF66GDl9D cs4aa5CNRF22xh4OpYfvZpsnr1ZpWbFzhowz3Og7V0elMFFnToBLmJoxhJcdhzwoIE9r N3vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b="duaSGgd/"; 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 h14-20020a17090634ce00b0099cbed6da42si3929911ejb.157.2023.10.08.19.30.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 19:30:52 -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="duaSGgd/"; 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 28DB63858C36 for ; Mon, 9 Oct 2023 02:30:48 +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 9AFF43858D28 for ; Mon, 9 Oct 2023 02:30:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9AFF43858D28 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 3992HGHk023598; Mon, 9 Oct 2023 02:30:22 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=j50PXhWdl6tir0Vn2IRsi6O4pvVWd4PVK/IEqxTcnvI=; b=duaSGgd/WuxWzN07yvpmTJPsy0skZCMGloP/j6j7qkWSri9a0j9+Ajak23sa1ZxH+Nvm Oppi1InfXlQoP4YUA+FHd0aJxjQgNdB0reEtUrlrupIE1/M+mm9upXuoI0rOrT1QIh9h aEAEYl0/w3Kee5HtkT54AnPimgNJsSIbHZQK2Ehez14opeQa3FQ2Gwbhu4PvBRJoWCAU lKZ495HQvr9SXB7KmE6GYPHeqkjH+In/t5atf1ElAgj3dYSeIqvxHxN41cvgvUTO0jtw PT4OnxTpkZ+2FFtfq2GeXv1E/nnOQHHBOcQj4qHp49awxz1elGXAi3nFhJ5boyuP0Gj+ Kw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3tm8ks06ma-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Oct 2023 02:30:22 +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 3992Qhf1015815; Mon, 9 Oct 2023 02:30:21 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3tm8ks06kx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Oct 2023 02:30:21 +0000 Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3990KZfw001239; Mon, 9 Oct 2023 02:30:20 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 3tkkvjdr7r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Oct 2023 02:30:20 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3992UH4124314376 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 9 Oct 2023 02:30:17 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A250920043; Mon, 9 Oct 2023 02:30:17 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BA89620040; Mon, 9 Oct 2023 02:30:15 +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:15 +0000 (GMT) Message-ID: <8bafe965-f392-8f5c-ad46-4efa5e5d695d@linux.ibm.com> Date: Mon, 9 Oct 2023 10:30:15 +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-1, expand] Enable vector mode for compare_by_pieces [PR111449] X-TM-AS-GCONF: 00 X-Proofpoint-GUID: WUoJhk54ABWWFB_Zsx2O_8fA5Zfo6Vw_ X-Proofpoint-ORIG-GUID: WEUKIJelrcburdXbVgBkAwhJhAyrsACD 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, 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: 1779243315794132369 X-GMAIL-MSGID: 1779243315794132369 Hi, Vector mode instructions are efficient on some targets (e.g. ppc64). This patch enables vector mode for compare_by_pieces. The non-member function widest_fixed_size_mode_for_size takes by_pieces_operation as the second argument and decide whether vector mode is enabled or not by the type of operations. Currently only set and compare enabled vector mode and do the optab checking correspondingly. The test case is in the second patch which is rs6000 specific. Bootstrapped and tested on x86 and powerpc64-linux BE and LE with no regressions. Thanks Gui Haochen ChangeLog Expand: Enable vector mode for pieces compare Vector mode compare instructions are efficient for equality compare on rs6000. This patch refactors the codes of pieces operation to enable vector mode for compare. gcc/ PR target/111449 * expr.cc (widest_fixed_size_mode_for_size): Enable vector mode for compare. Replace the second argument with the type of pieces operation. Add optab checks for vector mode used in compare. (by_pieces_ninsns): Pass the type of pieces operation to widest_fixed_size_mode_for_size. (class op_by_pieces_d): Add virtual function widest_fixed_size_mode_for_size. (op_by_pieces_d::op_by_pieces_d): Call outer function widest_fixed_size_mode_for_size. (op_by_pieces_d::get_usable_mode): Call class function widest_fixed_size_mode_for_size. (op_by_pieces_d::run): Likewise. (class move_by_pieces_d): Declare function widest_fixed_size_mode_for_size. (move_by_pieces_d::widest_fixed_size_mode_for_size): Implement. (class store_by_pieces_d): Declare function widest_fixed_size_mode_for_size. (store_by_pieces_d::widest_fixed_size_mode_for_size): Implement. (can_store_by_pieces): Pass the type of pieces operation to widest_fixed_size_mode_for_size. (class compare_by_pieces_d): Declare function widest_fixed_size_mode_for_size. (compare_by_pieces_d::compare_by_pieces_d): Set m_qi_vector_mode to true. (compare_by_pieces_d::widest_fixed_size_mode_for_size): Implement. patch.diff diff --git a/gcc/expr.cc b/gcc/expr.cc index d87346dc07f..9885404ee9c 100644 --- a/gcc/expr.cc +++ b/gcc/expr.cc @@ -992,8 +992,9 @@ alignment_for_piecewise_move (unsigned int max_pieces, unsigned int align) that is narrower than SIZE bytes. */ static fixed_size_mode -widest_fixed_size_mode_for_size (unsigned int size, bool qi_vector) +widest_fixed_size_mode_for_size (unsigned int size, by_pieces_operation op) { + bool qi_vector = ((op == COMPARE_BY_PIECES) || op == SET_BY_PIECES); fixed_size_mode result = NARROWEST_INT_MODE; gcc_checking_assert (size > 1); @@ -1009,8 +1010,13 @@ widest_fixed_size_mode_for_size (unsigned int size, bool qi_vector) { if (GET_MODE_SIZE (candidate) >= size) break; - if (optab_handler (vec_duplicate_optab, candidate) - != CODE_FOR_nothing) + if ((op == SET_BY_PIECES + && optab_handler (vec_duplicate_optab, candidate) + != CODE_FOR_nothing) + || (op == COMPARE_BY_PIECES + && optab_handler (mov_optab, mode) + != CODE_FOR_nothing + && can_compare_p (EQ, mode, ccp_jump))) result = candidate; } @@ -1061,8 +1067,7 @@ by_pieces_ninsns (unsigned HOST_WIDE_INT l, unsigned int align, { /* NB: Round up L and ALIGN to the widest integer mode for MAX_SIZE. */ - mode = widest_fixed_size_mode_for_size (max_size, - op == SET_BY_PIECES); + mode = widest_fixed_size_mode_for_size (max_size, op); if (optab_handler (mov_optab, mode) != CODE_FOR_nothing) { unsigned HOST_WIDE_INT up = ROUND_UP (l, GET_MODE_SIZE (mode)); @@ -1076,8 +1081,7 @@ by_pieces_ninsns (unsigned HOST_WIDE_INT l, unsigned int align, while (max_size > 1 && l > 0) { - mode = widest_fixed_size_mode_for_size (max_size, - op == SET_BY_PIECES); + mode = widest_fixed_size_mode_for_size (max_size, op); enum insn_code icode; unsigned int modesize = GET_MODE_SIZE (mode); @@ -1327,6 +1331,8 @@ class op_by_pieces_d virtual void finish_mode (machine_mode) { } + virtual fixed_size_mode widest_fixed_size_mode_for_size (unsigned int size) + = 0; public: op_by_pieces_d (unsigned int, rtx, bool, rtx, bool, by_pieces_constfn, @@ -1375,8 +1381,7 @@ op_by_pieces_d::op_by_pieces_d (unsigned int max_pieces, rtx to, { /* Find the mode of the largest comparison. */ fixed_size_mode mode - = widest_fixed_size_mode_for_size (m_max_size, - m_qi_vector_mode); + = ::widest_fixed_size_mode_for_size (m_max_size, COMPARE_BY_PIECES); m_from.decide_autoinc (mode, m_reverse, len); m_to.decide_autoinc (mode, m_reverse, len); @@ -1401,7 +1406,7 @@ op_by_pieces_d::get_usable_mode (fixed_size_mode mode, unsigned int len) if (len >= size && prepare_mode (mode, m_align)) break; /* widest_fixed_size_mode_for_size checks SIZE > 1. */ - mode = widest_fixed_size_mode_for_size (size, m_qi_vector_mode); + mode = widest_fixed_size_mode_for_size (size); } while (1); return mode; @@ -1451,7 +1456,7 @@ op_by_pieces_d::run () /* widest_fixed_size_mode_for_size checks M_MAX_SIZE > 1. */ fixed_size_mode mode - = widest_fixed_size_mode_for_size (m_max_size, m_qi_vector_mode); + = widest_fixed_size_mode_for_size (m_max_size); mode = get_usable_mode (mode, length); by_pieces_prev to_prev = { nullptr, mode }; @@ -1516,8 +1521,7 @@ op_by_pieces_d::run () else { /* widest_fixed_size_mode_for_size checks SIZE > 1. */ - mode = widest_fixed_size_mode_for_size (size, - m_qi_vector_mode); + mode = widest_fixed_size_mode_for_size (size); mode = get_usable_mode (mode, length); } } @@ -1538,6 +1542,8 @@ class move_by_pieces_d : public op_by_pieces_d insn_gen_fn m_gen_fun; void generate (rtx, rtx, machine_mode) final override; bool prepare_mode (machine_mode, unsigned int) final override; + fixed_size_mode widest_fixed_size_mode_for_size (unsigned int) + final override; public: move_by_pieces_d (rtx to, rtx from, unsigned HOST_WIDE_INT len, @@ -1626,14 +1632,23 @@ move_by_pieces (rtx to, rtx from, unsigned HOST_WIDE_INT len, return to; } +fixed_size_mode +move_by_pieces_d::widest_fixed_size_mode_for_size (unsigned int size) +{ + return ::widest_fixed_size_mode_for_size (size, MOVE_BY_PIECES); +} + /* Derived class from op_by_pieces_d, providing support for block move operations. */ class store_by_pieces_d : public op_by_pieces_d { insn_gen_fn m_gen_fun; + void generate (rtx, rtx, machine_mode) final override; bool prepare_mode (machine_mode, unsigned int) final override; + fixed_size_mode widest_fixed_size_mode_for_size (unsigned int) + final override; public: store_by_pieces_d (rtx to, by_pieces_constfn cfn, void *cfn_data, @@ -1686,6 +1701,13 @@ store_by_pieces_d::finish_retmode (memop_ret retmode) return m_to.adjust (QImode, m_offset); } +fixed_size_mode +store_by_pieces_d::widest_fixed_size_mode_for_size (unsigned int size) +{ + return ::widest_fixed_size_mode_for_size (size, + m_qi_vector_mode ? SET_BY_PIECES : STORE_BY_PIECES); +} + /* Determine whether the LEN bytes generated by CONSTFUN can be stored to memory using several move instructions. CONSTFUNDATA is a pointer which will be passed as argument in every CONSTFUN call. @@ -1730,7 +1752,8 @@ can_store_by_pieces (unsigned HOST_WIDE_INT len, while (max_size > 1 && l > 0) { fixed_size_mode mode - = widest_fixed_size_mode_for_size (max_size, memsetp); + = widest_fixed_size_mode_for_size (max_size, + memsetp ? SET_BY_PIECES : STORE_BY_PIECES); icode = optab_handler (mov_optab, mode); if (icode != CODE_FOR_nothing @@ -1832,12 +1855,15 @@ class compare_by_pieces_d : public op_by_pieces_d void generate (rtx, rtx, machine_mode) final override; bool prepare_mode (machine_mode, unsigned int) final override; void finish_mode (machine_mode) final override; + fixed_size_mode widest_fixed_size_mode_for_size (unsigned int) + final override; + public: compare_by_pieces_d (rtx op0, rtx op1, by_pieces_constfn op1_cfn, void *op1_cfn_data, HOST_WIDE_INT len, int align, rtx_code_label *fail_label) : op_by_pieces_d (COMPARE_MAX_PIECES, op0, true, op1, true, op1_cfn, - op1_cfn_data, len, align, false) + op1_cfn_data, len, align, false, true) { m_fail_label = fail_label; } @@ -1943,6 +1969,13 @@ compare_by_pieces (rtx arg0, rtx arg1, unsigned HOST_WIDE_INT len, return target; } + +fixed_size_mode +compare_by_pieces_d::widest_fixed_size_mode_for_size (unsigned int size) +{ + return ::widest_fixed_size_mode_for_size (size, COMPARE_BY_PIECES); +} + /* Emit code to move a block Y to a block X. This may be done with string-move instructions, with multiple scalar move instructions,