From patchwork Tue Dec 5 07:01:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiahao Xu X-Patchwork-Id: 173754 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3254484vqy; Mon, 4 Dec 2023 23:03:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IHMwkB/aAKaC4so3Zu9N7798r0snV/7jlTvBu3KvKu/OrfXT3GhwhHa2+RbkehISY94YQgV X-Received: by 2002:a05:6830:1057:b0:6d9:4e66:97d4 with SMTP id b23-20020a056830105700b006d94e6697d4mr2435020otp.35.1701759823051; Mon, 04 Dec 2023 23:03:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701759823; cv=pass; d=google.com; s=arc-20160816; b=hvEuMdxL9I9LLAAgD1bQlIjtzZqAY41B3bCtt6rhFokvUaUR8pFKiBWctTFiiharo6 WcWLiQcpKeDqIAYDJqeEmYKDfJTAq702hRNmRB9rzyYqRJX3VvKvBuW3vdhwRvFlhrYt V3FgWxyWzGRDBR6dTaaS+IudeNs1D9QND6jBkgqwiP2+aUhxeWBrerWQp1toGLVx81Db 0IRmrPffUSb7RyI/DWOnHmpBxwCd4033Ut3i6TF/gZzp7Sx6f8oh8PLlPBqdmkealT4i +C9yBq08mBGNS+G6YkjkSfvBGhQoR3UCOc2wQevskoQgSXeHhLDLzsukGE35R2Zgs/Cy iRYw== ARC-Message-Signature: i=2; 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 :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to; bh=KLiUBS5SYD2FaZTiM2B/7ycJng9ZJM9mVL9Gp/K+DfY=; fh=w+xsGLuzpTj56E0bzPMCc39RWHkBXt2f2AGs+4pGimo=; b=tBETzAMzCqaFOREoZ2Axa2fBCi9BxO4hwDrRxfeTTQjpYrrbbBmUkH+y/cDIVBvcn/ c/ZKRa2ClWdqDMWTC36gbKGQ0EzG/g2XZZS3hIKGeuQ0+YcLotXXR0QOpdW3p9t6HEAH uR27v3pF+DlG1E87SzZRDwNg9Mdt2Lp27XMTTHxsbzhJxhmc5pX7lRqQ+3jlxneFMwQc MGCaB5E3P8ru9Ofyq5PQzSGqCr2aWFX+cqVFD3XrYafStQhZXjEljEoX2RAjNAal++Rv g26aBEEQ1+BfsYRpLcad99gU29YfxBCdxLGikdT050oTKD/PUWk6++pECkZtcklncr51 kDUQ== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); 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" Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id q17-20020ad44351000000b0067a95b81a86si9366425qvs.235.2023.12.04.23.03.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 23:03:43 -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; arc=pass (i=1); 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D7E63384CBB6 for ; Tue, 5 Dec 2023 07:03:39 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 07AFF3857B99 for ; Tue, 5 Dec 2023 07:02:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 07AFF3857B99 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 07AFF3857B99 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701759743; cv=none; b=TWVv+Sf6JYXw7lm7KtuZepK2v+ZmUZz9AdNKYR4Di4Ahugwl8B/N60xact3xzhQEYsxB1Gq9i6xyABpb9lb9DZp33BbTqtrXRKDZ+Xgk5bMJZw3TvbmiWvLlTqHltlenZFzH4eDInx06ubaN4J54ObRZPtwsBXQlcmmT5xF/vss= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701759743; c=relaxed/simple; bh=gtvKEAUbYRjuSptFnR0xIoa60twLkfCjw3OJJ2hx9L4=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=s/Wfp0cBEKTnhGUq5L/HJ3itIH5FfJZKb15z82BtPIBcaKHgiHLHsm/jXRJJvovXah/2GHcamw/5BbP+ksTZwgCkYUxiXz2LOJNopQj0p9dCvSHcWIyTy0wMyUbiaOJt9TJjrBsUZ4cm9Jpr3KhLNQPumIlQKC8U6cTh1I5qzOg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from loongson.cn (unknown [10.10.130.252]) by gateway (Coremail) with SMTP id _____8CxNvH5ym5l1_g+AA--.59904S3; Tue, 05 Dec 2023 15:02:17 +0800 (CST) Received: from slurm-master.loongson.cn (unknown [10.10.130.252]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cxvdzeym5ljDlVAA--.57842S9; Tue, 05 Dec 2023 15:02:16 +0800 (CST) From: Jiahao Xu To: gcc-patches@gcc.gnu.org Cc: xry111@xry111.site, i@xen0n.name, chenglulu@loongson.cn, xuchenghua@loongson.cn, Jiahao Xu Subject: [PATCH v2 5/5] LoongArch: Vectorized loop unrolling is disable for divf/sqrtf/rsqrtf when -mrecip is enabled. Date: Tue, 5 Dec 2023 15:01:47 +0800 Message-Id: <20231205070147.53352-6-xujiahao@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20231205070147.53352-1-xujiahao@loongson.cn> References: <20231205070147.53352-1-xujiahao@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Cxvdzeym5ljDlVAA--.57842S9 X-CM-SenderInfo: 50xmxthkdrqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoW7KrWUAFW7trWfZryrCry7twc_yoW8tFyUpr ZIyr13tw4DJr47WrsrJ3yxWw1ayr9xGF42qa13ta4fCa17Kr1Fq3WkKr1qvFZrX3y5WryI vr1IqFs8Za45CwbCm3ZEXasCq-sJn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUk2b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r106r15M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx 1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1q6rW5McIj6I8E87Iv 67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE 42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6x kF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUcHUqUUUUU X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: 1784424508315558246 X-GMAIL-MSGID: 1784424508315558246 Using -mrecip generates a sequence of instructions to replace divf, sqrtf and rsqrtf. The number of generated instructions is close to or exceeds the maximum issue instructions per cycle of the LoongArch, so vectorized loop unrolling is not performed on them. gcc/ChangeLog: * config/loongarch/loongarch.cc (loongarch_vector_costs::determine_suggested_unroll_factor): If m_has_recip is true, uf return 1. (loongarch_vector_costs::add_stmt_cost): Detect the use of approximate instruction sequence. diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc index 2c06edcff92..0ca60e15ced 100644 --- a/gcc/config/loongarch/loongarch.cc +++ b/gcc/config/loongarch/loongarch.cc @@ -3974,7 +3974,9 @@ protected: /* Reduction factor for suggesting unroll factor. */ unsigned m_reduc_factor = 0; /* True if the loop contains an average operation. */ - bool m_has_avg =false; + bool m_has_avg = false; + /* True if the loop uses approximation instruction sequence. */ + bool m_has_recip = false; }; /* Implement TARGET_VECTORIZE_CREATE_COSTS. */ @@ -4021,7 +4023,7 @@ loongarch_vector_costs::determine_suggested_unroll_factor (loop_vec_info loop_vi { class loop *loop = LOOP_VINFO_LOOP (loop_vinfo); - if (m_has_avg) + if (m_has_avg || m_has_recip) return 1; /* Don't unroll if it's specified explicitly not to be unrolled. */ @@ -4081,6 +4083,36 @@ loongarch_vector_costs::add_stmt_cost (int count, vect_cost_for_stmt kind, } } + combined_fn cfn; + if (kind == vector_stmt + && stmt_info + && stmt_info->stmt) + { + /* Detect the use of approximate instruction sequence. */ + if ((TARGET_RECIP_VEC_SQRT || TARGET_RECIP_VEC_RSQRT) + && (cfn = gimple_call_combined_fn (stmt_info->stmt)) != CFN_LAST) + switch (cfn) + { + case CFN_BUILT_IN_SQRTF: + m_has_recip = true; + default: + break; + } + else if (TARGET_RECIP_VEC_DIV + && gimple_code (stmt_info->stmt) == GIMPLE_ASSIGN) + { + machine_mode mode = TYPE_MODE (vectype); + switch (gimple_assign_rhs_code (stmt_info->stmt)) + { + case RDIV_EXPR: + if (GET_MODE_INNER (mode) == SFmode) + m_has_recip = true; + default: + break; + } + } + } + return retval; }