From patchwork Fri Nov 17 02:38:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wei X-Patchwork-Id: 165976 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp258728vqn; Thu, 16 Nov 2023 18:38:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IEl/3RAuVB671BfTp/sy9FScgFEU0UtEKcwG4cA97srZMBcJT5ENtwIJufeDkX+dRURLzbT X-Received: by 2002:a25:687:0:b0:daf:81e5:d2fa with SMTP id 129-20020a250687000000b00daf81e5d2famr13945250ybg.33.1700188718697; Thu, 16 Nov 2023 18:38:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700188718; cv=pass; d=google.com; s=arc-20160816; b=Mji6C9U0eMvuKEgTDLOma6fOGiX5NS2kMJc7S43209yDyOAX7KqPOtOAHYZvSHRxlw SzOnBBeyA83qGsOs/NrNNcfwDeTYWMAkeOX7HdPfpP+2ipwfewTiigkrbwS3rxwPS/O+ Z1nw3oAt2hxsxGcXJG96+4mBCfO9XpJJiT1QaEN1dSFuEpU64p00Q6nl+8SBdRmjGykp JkR+Q5+8gWYlivVkm67vrHxL0tmvSuHRCrxCtXjT1yW7NYY6Zm9zqrLs2PSDgVKjBMJx SKmz9hmz3aXr7C71ceDJLcAoUOwhvSjQPgob1NhuSrbBbebJlkbgrUT0O/TJA8+9OBv8 Y5eA== 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=qJbNTsQCCLMhl/3yTwADujLNi1iDjVvykC6ZqTBc7PU=; fh=qByQSPvg+/wD954+0Cj99cs2VLzuSy0bdUhDlHLuDa4=; b=MYPlUBBvcXhjZ/s9hxYKo8wsdFkmdIDH3qIJ3sc18NgKFIyz8X6dDPwwEMBuddCpRh ahvySI+cCCK1tEFqH3LQpqDSzv66N1Yr08VyvSq/Kl3xh3UxNeHat9nmj/RP4f1p0hU2 VHtEXHdMXSKutRpaP6zq1FwM7vKsYmIs9o4q3j6Kg3YCdHgqqHZH89QRATFfbdciVF7t nXT7tIi+WP0rRRHz6LGpd4xPnURttA1VC0hyXxqBg+wbFBLukPdqW4/qLtA1/ryuLw9N uQmJdh5KjeOokr+Wi3MQLfZxF+NwDio9PUtRs9v0Q0iyRPDDC324DCXGMwqF+oyTzW2V x2/g== 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 bq18-20020a05620a469200b0077894fa3885si883757qkb.268.2023.11.16.18.38.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 18:38:38 -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 76D52385840E for ; Fri, 17 Nov 2023 02:38:38 +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 D07B63858D28 for ; Fri, 17 Nov 2023 02:38:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D07B63858D28 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 D07B63858D28 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=1700188694; cv=none; b=nYkYTz1NY8eLqhfnZ1TzU5pfaXUWpEyhUpujGaQiptF4io7Qe4yXPQ+khUCUS6FaQIB8nXWPhk2/ClIf9t+iSq0N4rr5MV3nsbIfbt2wsK7Iv+ZIvx8lCZELfXu5UgEXBJn+U2rLz9C7H8IAlvLy4odNw1RoSBKhEZomg2Vl9ug= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700188694; c=relaxed/simple; bh=iD5WPS1rdJLIZ77tjloWm88uCeM3lA05aCUgV5S4k5A=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=Ipp9G2E6VShoYSYXjHxToA1SwGiXfQp8JzbL6T9644nKjEEaYk7I3FkyRCOlb/vvspxiPeZchJ0JcRgy7UkmcF2gaDsnUwdGXGyfZ5t1rqkPtztJYh4bUBjL381f368ZLU12yzWFIqAGTil9cOC0syfIxH23mCK9OQCqDI1m8OY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from loongson.cn (unknown [10.2.6.5]) by gateway (Coremail) with SMTP id _____8AxEvAO0lZlVbY6AA--.49730S3; Fri, 17 Nov 2023 10:38:07 +0800 (CST) Received: from 5.5.5 (unknown [10.2.6.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxbNwM0lZl59ZEAA--.20021S4; Fri, 17 Nov 2023 10:38:04 +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 v2] LoongArch: Implement C[LT]Z_DEFINED_VALUE_AT_ZERO Date: Fri, 17 Nov 2023 10:38:02 +0800 Message-Id: <20231117023802.476523-1-liwei@loongson.cn> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-CM-TRANSID: AQAAf8BxbNwM0lZl59ZEAA--.20021S4 X-CM-SenderInfo: 5olzvxo6or00hjvr0hdfq/ X-Coremail-Antispam: 1Uk129KBj93XoW7KF13Gw1rCF48CFWrJw1UJwc_yoW8tr43p3 9xuryDtrWxKFs7Wr4vq34fWr47trW7Kry29a9IqrWxua47tr92gr48KrZrJ3W5Ja1UZrWa qws5C3y7Za10y3cCm3ZEXasCq-sJn29KB7ZKAUJUUUU5529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkYb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Jr0_Gr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27w Aqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jrv_JF1lYx0Ex4A2jsIE 14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x 0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E 7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcV C0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF 04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7 CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU1QVy3UUUUU== X-Spam-Status: No, score=-13.5 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: 1782777085826090771 X-GMAIL-MSGID: 1782777085826090771 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/ChangeLog: * config/loongarch/loongarch.h (CLZ_DEFINED_VALUE_AT_ZERO): Implement. (CTZ_DEFINED_VALUE_AT_ZERO): Same. gcc/testsuite/ChangeLog: * gcc.dg/pr90838.c: add clz/ctz test support on LoongArch. --- 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*-*-* } } } } */