From patchwork Thu Nov 16 12:30:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wei X-Patchwork-Id: 165788 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp3175868vqg; Thu, 16 Nov 2023 04:31:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IG9FB1OrtM5O179yju6HMEc1GToXycEkG9W9AQe2GdqnoEgwOipcgH9RRbeEhDqVu0vEOPC X-Received: by 2002:a05:622a:89:b0:41c:cd2a:f05a with SMTP id o9-20020a05622a008900b0041ccd2af05amr9399393qtw.25.1700137887242; Thu, 16 Nov 2023 04:31:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700137887; cv=pass; d=google.com; s=arc-20160816; b=qJzuWioNNIrz2of7Cr/WGgpi7WOoAUpxKBpwch7skI+pFMLWiWCs63+RSAnKaEQbEX O0r2CqXjDOxxP00F5rdvIay3xrPH4JJAYHW2qvkXX7DB6AzSG5fPAbGuy05Q5dyHN9E+ wgC+NVCsKD0sXphYDJZKEeoEpEWIGTdMeiOnYhskZ+oCEyOqQ6RN9FzYES+1IHqgHUMi 2HqI+YZNKidYioGKbstMxBpdsbKtwO0posghzE/Bss93UBTw+c0PadAmm9VM4ycb2pL/ UEE2XLvLtGHzLQTIIL18PBj3+kPd80PRcf/Qh2s6gKz9zb9bu4zblCC11I7XEm2RwPR4 zV9A== 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:message-id:date:subject:cc:to:from:arc-filter :dmarc-filter:delivered-to; bh=PlZQJZWko0J+q8f9YummYpywqex4FFxhN+7v+pc3UmA=; fh=qByQSPvg+/wD954+0Cj99cs2VLzuSy0bdUhDlHLuDa4=; b=mwhQpPL9OHu/jsOSj6SgrqAjNuKQbzanIAHXrHPLjckqq136l8tb0JicHCenGUE4Ns s3cr+U9Z2qc8XtEVM3BdLzW/eeZ5SQPKbfUSiFGGjZC/qf2hxQT5GPvFDkQjZtLParNY 3H0d6EOekH1/rYfwpA7T77eX5KoT6d+QGzC2C4BpXADIS4v46EcrNQ7zXWRgy255VZav i2SRwA7xlfwbIQI/lLr/X+SMOncYT2MCd/aSJesdD4zMtZiDvqoxy8mmub3bbpBT+Cwo QYN6MJvAvkrO5DBdKxSqvsAEPlTGv2SFB9ssOgxiAVOAoHQ803mbd6QUjWCDdd523Hgc AzAA== 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 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id b19-20020ac87fd3000000b0041991ecf2e7si10414649qtk.635.2023.11.16.04.31.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 04:31:27 -0800 (PST) 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; arc=pass (i=1); 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 784023857BAD for ; Thu, 16 Nov 2023 12:31:18 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by sourceware.org (Postfix) with ESMTPS id DE3D63858D33 for ; Thu, 16 Nov 2023 12:30:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DE3D63858D33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=loongson.cn ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DE3D63858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:470:142:3::10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700137853; cv=none; b=O3iJTMzUpTdXi41OJbcyN7jzyM50NRpkVJGF5KHlEzzckrxzDerJl8EVjMIsNxAgOk2gT0ZpwUTCDmldSM3r8beu4ALavQLEpTgEYZak7ATkO+fE+nvg0wyX6d2H/HrK3rBh/bNTwYuo2fccxE1HD9dPvkKQCQesEWJ/FwHaRQI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700137853; c=relaxed/simple; bh=22LAq/FEf5b5OYv6JVC8OUm+sD+8NT1peHdNiO5klDA=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=GsPSzmLzs6IX19Zd8C88wYQIDZmqQSHZVHvFGyG3je+AU2zVEmDCWuSlc1cgzAjkCXszWmutTKZHlpBESNmUXRy389sEVFyABME/WRbcb2C0/ETLMYa62Bo/uRk1H/B0q+4zsxpnKNLcVyyK0w6qdxo3BhyumIwKWxb7B3FkXfE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3bWB-0005r5-Vs for gcc-patches@gcc.gnu.org; Thu, 16 Nov 2023 07:30:50 -0500 Received: from loongson.cn (unknown [10.2.6.5]) by gateway (Coremail) with SMTP id _____8BxJvFrC1ZlhIo6AA--.50091S3; Thu, 16 Nov 2023 20:30:36 +0800 (CST) Received: from 5.5.5 (unknown [10.2.6.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Bx3y9pC1ZlvR1EAA--.18839S4; Thu, 16 Nov 2023 20:30:34 +0800 (CST) From: Li Wei To: gcc-patches@gcc.gnu.org Cc: xry111@xry111.site, i@xen0n.name, xuchenghua@loongson.cn, chenglulu@loongson.cn, Li Wei Subject: [PATCH v1] LoongArch: Implement C[LT]Z_DEFINED_VALUE_AT_ZERO Date: Thu, 16 Nov 2023 20:30:04 +0800 Message-Id: <20231116123004.3731806-1-liwei@loongson.cn> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Bx3y9pC1ZlvR1EAA--.18839S4 X-CM-SenderInfo: 5olzvxo6or00hjvr0hdfq/ X-Coremail-Antispam: 1Uk129KBj93XoW7KF13Gw1rCF48Cr47XrWrWFX_yoW8Zryfp3 9ruryUtrWxKFs7Wr4vq34fXrW7trW7Gry29a9rXrWxua4UtF92gr18KrW7J3WUJa18ZFW2 qw4kC3y7ZF40y3gCm3ZEXasCq-sJn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUk2b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r106r15M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Jr0_Gr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx 1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r106r15McIj6I8E87Iv 67AKxVWxJVW8Jr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxAIw28Icx kI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2Iq xVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42 IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwCI42IY 6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aV CY1x0267AKxVWUJVW8JbIYCTnIWIevJa73UjIFyTuYvjxUFwZ2UUUUU Received-SPF: pass client-ip=114.242.206.163; envelope-from=liwei@loongson.cn; helo=mail.loongson.cn X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_FAIL, SPF_HELO_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: 1782723784870852703 X-GMAIL-MSGID: 1782723784870852703 The LoongArch has defined ctz and clz on the backend, but if we want GCC do CTZ transformation optimization in forwprop2 pass, GCC need to know the value of c[lt]z at zero, which may be beneficial for some test cases (like spec2017 deepsjeng_r). After implementing the macro, we test dynamic instruction count on deepsjeng_r: - before 1688423249186 - after 1660311215745 (1.66% reduction) --- gcc/config/loongarch/loongarch.h | 5 +++++ gcc/testsuite/gcc.dg/pr90838.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/gcc/config/loongarch/loongarch.h b/gcc/config/loongarch/loongarch.h index ddac8e98ea9..115222e70fd 100644 --- a/gcc/config/loongarch/loongarch.h +++ b/gcc/config/loongarch/loongarch.h @@ -1239,3 +1239,8 @@ struct GTY (()) machine_function #define TARGET_EXPLICIT_RELOCS \ (la_opt_explicit_relocs == EXPLICIT_RELOCS_ALWAYS) + +#define CLZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) \ + ((VALUE) = GET_MODE_UNIT_BITSIZE (MODE), 2) +#define CTZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) \ + ((VALUE) = GET_MODE_UNIT_BITSIZE (MODE), 2) diff --git a/gcc/testsuite/gcc.dg/pr90838.c b/gcc/testsuite/gcc.dg/pr90838.c index 759059683a9..40aad70499d 100644 --- a/gcc/testsuite/gcc.dg/pr90838.c +++ b/gcc/testsuite/gcc.dg/pr90838.c @@ -83,3 +83,8 @@ int ctz4 (unsigned long x) /* { dg-final { scan-assembler-times "ctz\t" 3 { target { rv32 } } } } */ /* { dg-final { scan-assembler-times "andi\t" 1 { target { rv32 } } } } */ /* { dg-final { scan-assembler-times "mul\t" 1 { target { rv32 } } } } */ + +/* { dg-final { scan-tree-dump-times {= \.CTZ} 4 "forwprop2" { target { loongarch64*-*-* } } } } */ +/* { dg-final { scan-assembler-times "ctz.d\t" 1 { target { loongarch64*-*-* } } } } */ +/* { dg-final { scan-assembler-times "ctz.w\t" 3 { target { loongarch64*-*-* } } } } */ +/* { dg-final { scan-assembler-times "andi\t" 4 { target { loongarch64*-*-* } } } } */