From patchwork Wed Nov 16 06:51:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kewen.Lin" X-Patchwork-Id: 20738 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3126046wru; Tue, 15 Nov 2022 22:52:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf5RIW8ZH+x9JLFLFUUYTH5sQCVOVYe6+MXqUUIZfwcRN49kS6ft/DCov98fFsfePAfzqpTm X-Received: by 2002:aa7:cac1:0:b0:467:7827:232 with SMTP id l1-20020aa7cac1000000b0046778270232mr16574270edt.268.1668581520708; Tue, 15 Nov 2022 22:52:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668581520; cv=none; d=google.com; s=arc-20160816; b=Rn7ixTgcXR1J0FWcPPOgHJuCnBBn3vqs0okIWlJDURHL4DEVMrD6g3JnFmE2JbHD/v umUekYlf1i7Vdfid3h0UzwMDLpsiodB1Vm150Kv/WY2bc/NH/3Wxt5vFeYFR349FI/9s QiB/wNzDlHBbM5qpZnPMG5u5MT/W9YkUcuD5RabI1kYf6rTWUyt71mVz7+P67yh8Avm8 wu9Y56SAD6ERv3gr+Ju/kSXPujYFoWjaW8+FqdQ3r0neeRb8OQ+69CPN6TNt3x3mcEaF DLCdmfM/4ECGxIm8i8v/Hq/Pln9ScxaCne7F86uZ8IsfDaFzGqxYlU8ge4p5Idam3ItW XvlQ== 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:in-reply-to:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=l0vFr+PZww7+hh8OBCfjy9jlORvkd9GsbNlfzkqFLoM=; b=Rrql0dIbZ/JIMw+qVMXkX45Z3YWa+CH/cX/ju2Quh7hp8HI4d/3lyHGe04TyEg4lPo 9FNaAAfh9FLEel1eBnwyM7m5XqQ4aBYM98bjXcM3ZJTgXr4tR+vARg/AA4zhXi7yB/U4 twwIOfgYPk9lRMX5H03pUNPAhU68IDu8MXPH0cKE5ZWQykCqMj1UfOEMW21ouzPgQZDV eh+NqtfbtYtclMR0PJiSdKZ75b1yYG6oNUSwW+8hJenmHsjW7rtQeoiENabCV2oA/7dx 839RGRX2k7qfK0igYLNzUNWktT4yDSZAMbUzGbHEalBBPuyu6Kv67buOw5keSXTQMVFL /C4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=cxrb8Mds; 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 21-20020a508e15000000b00461f44d7bfcsi11606124edw.573.2022.11.15.22.52.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Nov 2022 22:52:00 -0800 (PST) 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=cxrb8Mds; 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 E9BE93954C73 for ; Wed, 16 Nov 2022 06:51:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E9BE93954C73 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668581519; bh=l0vFr+PZww7+hh8OBCfjy9jlORvkd9GsbNlfzkqFLoM=; h=Date:Subject:To:Cc:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=cxrb8MdsvfGZ16ePcxmrO2dcE532ThFFchFJf1J317Jy/1WZ4wfit8jg5p7EmnUhN 2cxwHPmsW5o1tJ3Ix2s/SF+FAeFlZziBYpM3/wFsnDmiJPmq0Hf+CFSHptmKxKnf+R /pJQ9KdE4n5hXWLrdD5Pw8pXWHyEdtArIp72/2ZA= 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 5A2503954C57 for ; Wed, 16 Nov 2022 06:51:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5A2503954C57 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2AG6eSdv015358; Wed, 16 Nov 2022 06:51:14 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3kvsqah5m2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Nov 2022 06:51:13 +0000 Received: from m0098420.ppops.net (m0098420.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 2AG6lG1S005056; Wed, 16 Nov 2022 06:51:13 GMT Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3kvsqah5kf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Nov 2022 06:51:13 +0000 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2AG6ZarG021224; Wed, 16 Nov 2022 06:51:11 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma04fra.de.ibm.com with ESMTP id 3kt349c1yd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Nov 2022 06:51:11 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2AG6j91C26214856 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Nov 2022 06:45:09 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 378634C044; Wed, 16 Nov 2022 06:51:08 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 275294C040; Wed, 16 Nov 2022 06:51:06 +0000 (GMT) Received: from [9.197.233.36] (unknown [9.197.233.36]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 16 Nov 2022 06:51:05 +0000 (GMT) Message-ID: <247bf71b-e0ab-7cf7-098b-a106a0764301@linux.ibm.com> Date: Wed, 16 Nov 2022 14:51: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 Subject: [PATCH 2/2] rs6000: Refine integer comparison handlings in rs6000_emit_vector_compare Content-Language: en-US To: GCC Patches Cc: Segher Boessenkool , David Edelsohn , Peter Bergner , Michael Meissner References: In-Reply-To: X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: WJmjDWiSh5_qxtefsuAVe2I6qw29lssD X-Proofpoint-GUID: IJMVGG1eAQsYl5PVSzDxxYEf5SBB3VpI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-15_08,2022-11-15_03,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 suspectscore=0 phishscore=0 adultscore=0 mlxscore=0 lowpriorityscore=0 clxscore=1015 mlxlogscore=999 impostorscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211160046 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, 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?1749634536421908926?= X-GMAIL-MSGID: =?utf-8?q?1749634536421908926?= Hi, The current handlings in rs6000_emit_vector_compare is a bit complicated to me, especially after we emit vector float comparison insn with the given code directly. This patch is to refine the handlings for vector integer comparison operators, it becomes not recursive, and we don't need the helper function rs6000_emit_vector_compare_inner any more. Bootstrapped and regtested on powerpc64-linux-gnu P7 and P8, and powerpc64le-linux-gnu P9 and P10. I'm going to push this later this week if no objections. BR, Kewen ----- gcc/ChangeLog: * config/rs6000/rs6000.cc (rs6000_emit_vector_compare_inner): Remove. (rs6000_emit_vector_compare): Refine it by directly using the reversed or swapped code, to avoid the recursion. --- gcc/config/rs6000/rs6000.cc | 159 ++++++++---------------------------- 1 file changed, 34 insertions(+), 125 deletions(-) -- 2.27.0 diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc index 56db12f08a0..21f4cda7b80 100644 --- a/gcc/config/rs6000/rs6000.cc +++ b/gcc/config/rs6000/rs6000.cc @@ -15639,169 +15639,78 @@ output_cbranch (rtx op, const char *label, int reversed, rtx_insn *insn) return string; } -/* Return insn for VSX or Altivec comparisons. */ - -static rtx -rs6000_emit_vector_compare_inner (enum rtx_code code, rtx op0, rtx op1) -{ - rtx mask; - machine_mode mode = GET_MODE (op0); - - switch (code) - { - default: - break; - - case GE: - if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT) - return NULL_RTX; - /* FALLTHRU */ - - case EQ: - case GT: - case GTU: - mask = gen_reg_rtx (mode); - emit_insn (gen_rtx_SET (mask, gen_rtx_fmt_ee (code, mode, op0, op1))); - return mask; - } - - return NULL_RTX; -} - /* Emit vector compare for operands OP0 and OP1 using code RCODE. - DMODE is expected destination mode. This is a recursive function. */ + DMODE is expected destination mode. */ static rtx rs6000_emit_vector_compare (enum rtx_code rcode, rtx op0, rtx op1, machine_mode dmode) { - rtx mask; gcc_assert (VECTOR_UNIT_ALTIVEC_OR_VSX_P (dmode)); gcc_assert (GET_MODE (op0) == GET_MODE (op1)); + rtx mask = gen_reg_rtx (dmode); /* In vector.md, we support all kinds of vector float point comparison operators in a comparison rtl pattern, we can just emit the comparison rtx insn directly here. Besides, we should have a centralized place to handle the possibility - of raising invalid exception. */ - if (GET_MODE_CLASS (dmode) == MODE_VECTOR_FLOAT) + of raising invalid exception. Also emit directly for vector + integer comparison operators EQ/GT/GTU. */ + if (GET_MODE_CLASS (dmode) == MODE_VECTOR_FLOAT + || rcode == EQ + || rcode == GT + || rcode == GTU) { - mask = gen_reg_rtx (dmode); emit_insn (gen_rtx_SET (mask, gen_rtx_fmt_ee (rcode, dmode, op0, op1))); return mask; } bool swap_operands = false; - bool try_again = false; - - /* See if the comparison works as is. */ - mask = rs6000_emit_vector_compare_inner (rcode, op0, op1); - if (mask) - return mask; + bool need_invert = false; + enum rtx_code code = UNKNOWN; switch (rcode) { case LT: - rcode = GT; - swap_operands = true; - try_again = true; - break; case LTU: - rcode = GTU; + code = swap_condition (rcode); swap_operands = true; - try_again = true; break; case NE: - /* Invert condition and try again. - e.g., A != B becomes ~(A==B). */ - { - enum rtx_code rev_code; - enum insn_code nor_code; - rtx mask2; - - rev_code = reverse_condition_maybe_unordered (rcode); - if (rev_code == UNKNOWN) - return NULL_RTX; - - nor_code = optab_handler (one_cmpl_optab, dmode); - if (nor_code == CODE_FOR_nothing) - return NULL_RTX; - - mask2 = rs6000_emit_vector_compare (rev_code, op0, op1, dmode); - if (!mask2) - return NULL_RTX; - - mask = gen_reg_rtx (dmode); - emit_insn (GEN_FCN (nor_code) (mask, mask2)); - return mask; - } + case LE: + case LEU: + code = reverse_condition (rcode); + need_invert = true; break; case GE: + code = GT; + swap_operands = true; + need_invert = true; + break; case GEU: - case LE: - case LEU: - /* Try GT/GTU/LT/LTU OR EQ */ - { - rtx c_rtx, eq_rtx; - enum insn_code ior_code; - enum rtx_code new_code; - - switch (rcode) - { - case GE: - new_code = GT; - break; - - case GEU: - new_code = GTU; - break; - - case LE: - new_code = LT; - break; - - case LEU: - new_code = LTU; - break; - - default: - gcc_unreachable (); - } - - ior_code = optab_handler (ior_optab, dmode); - if (ior_code == CODE_FOR_nothing) - return NULL_RTX; - - c_rtx = rs6000_emit_vector_compare (new_code, op0, op1, dmode); - if (!c_rtx) - return NULL_RTX; - - eq_rtx = rs6000_emit_vector_compare (EQ, op0, op1, dmode); - if (!eq_rtx) - return NULL_RTX; - - mask = gen_reg_rtx (dmode); - emit_insn (GEN_FCN (ior_code) (mask, c_rtx, eq_rtx)); - return mask; - } + code = GTU; + swap_operands = true; + need_invert = true; break; default: - return NULL_RTX; + gcc_unreachable (); + break; } - if (try_again) - { - if (swap_operands) - std::swap (op0, op1); + if (swap_operands) + std::swap (op0, op1); + + emit_insn (gen_rtx_SET (mask, gen_rtx_fmt_ee (code, dmode, op0, op1))); - mask = rs6000_emit_vector_compare_inner (rcode, op0, op1); - if (mask) - return mask; + if (need_invert) + { + enum insn_code nor_code = optab_handler (one_cmpl_optab, dmode); + gcc_assert (nor_code != CODE_FOR_nothing); + emit_insn (GEN_FCN (nor_code) (mask, mask)); } - /* You only get two chances. */ - return NULL_RTX; + return mask; } /* Emit vector conditional expression. DEST is destination. OP_TRUE and