From patchwork Fri Jul 21 17:55:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vineet Gupta X-Patchwork-Id: 124043 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp372934vqg; Fri, 21 Jul 2023 10:56:48 -0700 (PDT) X-Google-Smtp-Source: APBJJlFRdlb2lsNwuKm6JSaUnpio1PQj9xCZPvE5vPi/Le8HjtMI7MToqJuDptw9cSkiP88FrgOt X-Received: by 2002:a2e:7e07:0:b0:2b6:e196:68c4 with SMTP id z7-20020a2e7e07000000b002b6e19668c4mr2255816ljc.39.1689962207835; Fri, 21 Jul 2023 10:56:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689962207; cv=none; d=google.com; s=arc-20160816; b=SbSAKtLyozLo1vCH0ir16ALSNJcabz8g6TaOyj13Ps0lJWpUbVwW0SZDlh/t+U9UQr 49uxaCV8LgNnfLxxdLaaooKLKJascQtORIpe2LbHRzESWcSPnNp1tX5TlAFqt2cSZ4te hpJ8BuJgDQNo5bEcrxBe+JkWkAZD4/mL2vd8CW2z18caTolFNvHamCPUN47/NzY5l1I9 kZUHj8DWFAWe8V68cUcTkCgJt+tmiSxP4DI7x/P70yjCTzxQyPj131wsnX1f+JK1n18P OpjnHEl0wl+Q2xDEoBg2u0cNBz2Zx5Q4i4CCAjuA45FWOObFr8sKR2mihILYURjFv0eB LIPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender: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:dkim-signature :dmarc-filter:delivered-to; bh=zoloZyT4eVKrh+jppsNQ7yjGliNDvcim4UN0ZojNWs8=; fh=m7noDAVcgmnwX+dSBsD8e2gMVdc9JkDMKDD8YjZacnc=; b=Yu/4LV6sNEvmBQGlzloLBhS86xRa8A1bxLCIbPwNlOCpB9nBbxR7wqtAiz9i8H2I2/ WnzueKk8yDVz11AKKXyRAtzH6gRYPqx9aZAewXIL62FZk6y68ISgqZUXN6fjmkkNsnRQ MZ9eQFpgzd8qK/fh+2qo6wxgoAibUlcUx2xVEDZ0W3ynh9ZuzGdUyLaHZO5klHLd35Rb S8kM+Lz3FXkKQfZvTIjFRD6UDU87idNxqysz95FlehL/aSS7Hxm/227tqMvQqovVbBSC He+9gcZszE5PBBQBLUJP9PC/2TDj3Bc8bQgSFE56rl1IGGe5o4G+0QV3cEx6atGDi1EJ Szcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=Vmh4OXcD; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id s4-20020a170906454400b009933205fdb5si2445361ejq.141.2023.07.21.10.56.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jul 2023 10:56:47 -0700 (PDT) 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=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=Vmh4OXcD; 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 7C6CB3860765 for ; Fri, 21 Jul 2023 17:56:26 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id 06DFB3858409 for ; Fri, 21 Jul 2023 17:55:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 06DFB3858409 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-6b9e478e122so1859630a34.1 for ; Fri, 21 Jul 2023 10:55:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1689962157; x=1690566957; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=zoloZyT4eVKrh+jppsNQ7yjGliNDvcim4UN0ZojNWs8=; b=Vmh4OXcDxQ9+TTfkirr+g3TXWMyXWuVbE7RS0bwTClK+36XwTeDNKcdnltPEHKDKxH dyA+Jo170YcJSsN0JJgJvtFMesLlnSQDj1g2YPoFUjsybd+Izjbj4V1y53D6V+4Q+M3P kp+KKjU/VAzBgJ+ZO7czGmFGWSwLgU29XzeYXFW+iSc/KJZxryjDs3YDb9m/r5oUJSQT ktwkGxiD8B1To+uP54tISTf5NZHOamYS6Tzuc+fcK4+3vjr4dSKtfMOEpFh0oDu2ASQx L3ZRSUy61ge+4qFNFBrybBN1jIM/fCcOpOxR5H9dOSPkK/5EJueimGbsCBjXyYUbT5CC WHFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689962157; x=1690566957; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zoloZyT4eVKrh+jppsNQ7yjGliNDvcim4UN0ZojNWs8=; b=Bwh4MXjVpAktzDPPY+v9idd8KqxVyQqqRGd/xlQiJdggNpI72CTSFCdnzFc8TUHQeW N25kF8rBgG3fquuRT0caU2aEywhmTK8G4uXCkR4CEA7R9tqReHZY1y1teDzu6LLDSVNe ISXsD+QhELDPgpa/S4ypLUzqIsUPxvBZaN+hOQR/7liocChcDTzW2kOUCQWvHNNgCTkw Bk6FIgtJLcrz4h/hgmVC1PB8tR08uKfIqm7oP8cVNC7/4plgzTVCMlsDClNCWNVoVVQp +awshY6nWCjQd6lysXnspqq10AyjFg3etzPW0rCVLCx89W5VUYWgH3gvhx7pwa6nTCHx XEEg== X-Gm-Message-State: ABy/qLZHSa68bG7xGLrsTykFzEizFxX+VAuW4cGezgwxP/7cc2Iez0Nu jbXYVYcB5mRCOzQX3kgmtYMBa/dvB3m7RV4R2b68ug== X-Received: by 2002:a05:6358:3412:b0:134:ddad:2b4f with SMTP id h18-20020a056358341200b00134ddad2b4fmr683017rwd.18.1689962157525; Fri, 21 Jul 2023 10:55:57 -0700 (PDT) Received: from vineet-framework.ba.rivosinc.com (c-98-210-197-24.hsd1.ca.comcast.net. [98.210.197.24]) by smtp.gmail.com with ESMTPSA id s123-20020a637781000000b005635bf2f09bsm3354841pgc.42.2023.07.21.10.55.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jul 2023 10:55:57 -0700 (PDT) From: Vineet Gupta To: gcc-patches@gcc.gnu.org, Manolis Tsamis Cc: kito.cheng@gmail.com, Jeff Law , Palmer Dabbelt , gnu-toolchain@rivosinc.com, Vineet Gupta Subject: [PATCH] RISC-V: optim const DF +0.0 store to mem [PR/110748] Date: Fri, 21 Jul 2023 10:55:52 -0700 Message-Id: <20230721175552.2693295-1-vineetg@rivosinc.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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.29 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 Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772053812445428621 X-GMAIL-MSGID: 1772053812445428621 DF +0.0 is bitwise all zeros so int x0 store to mem can be used to optimize it. void zd(double *) { *d = 0.0; } currently: | fmv.d.x fa5,zero | fsd fa5,0(a0) | ret With patch | sd zero,0(a0) | ret This came to light when testing the in-flight f-m-o patch where an ICE was gettinh triggered due to lack of this pattern but turns out this is an independent optimization of its own [1] [1] https://gcc.gnu.org/pipermail/gcc-patches/2023-July/624857.html Apparently this is a regression in gcc-13, introduced by commit ef85d150b5963 ("RISC-V: Enable TARGET_SUPPORTS_WIDE_INT") and the fix thus is a partial revert of that change. Ran thru full multilib testsuite, there was 1 false failure due to random string "lw" appearing in lto build assembler output, which is also fixed in the patch. gcc/Changelog: * config/riscv/predicates.md (const_0_operand): Add back const_double. gcc/testsuite/ChangeLog: * gcc.target/riscv/pr110748-1.c: New Test. * gcc.target/riscv/xtheadfmv-fmv.c: Add '\t' around test patterns to avoid random string matches. Signed-off-by: Vineet Gupta Reviewed-by: Palmer Dabbelt --- gcc/config/riscv/predicates.md | 2 +- gcc/testsuite/gcc.target/riscv/pr110748-1.c | 10 ++++++++++ gcc/testsuite/gcc.target/riscv/xtheadfmv-fmv.c | 8 ++++---- 3 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/pr110748-1.c diff --git a/gcc/config/riscv/predicates.md b/gcc/config/riscv/predicates.md index 5a22c77f0cd0..9db28c2def7e 100644 --- a/gcc/config/riscv/predicates.md +++ b/gcc/config/riscv/predicates.md @@ -58,7 +58,7 @@ (match_test "INTVAL (op) + 1 != 0"))) (define_predicate "const_0_operand" - (and (match_code "const_int,const_wide_int,const_vector") + (and (match_code "const_int,const_wide_int,const_double,const_vector") (match_test "op == CONST0_RTX (GET_MODE (op))"))) (define_predicate "const_1_operand" diff --git a/gcc/testsuite/gcc.target/riscv/pr110748-1.c b/gcc/testsuite/gcc.target/riscv/pr110748-1.c new file mode 100644 index 000000000000..2f5bc08aae72 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/pr110748-1.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target hard_float } */ +/* { dg-options "-march=rv64g -mabi=lp64d -O2" } */ + + +void zd(double *d) { *d = 0.0; } +void zf(float *f) { *f = 0.0; } + +/* { dg-final { scan-assembler-not "\tfmv\\.d\\.x\t" } } */ +/* { dg-final { scan-assembler-not "\tfmv\\.s\\.x\t" } } */ diff --git a/gcc/testsuite/gcc.target/riscv/xtheadfmv-fmv.c b/gcc/testsuite/gcc.target/riscv/xtheadfmv-fmv.c index 1036044291e7..89eb48bed1b9 100644 --- a/gcc/testsuite/gcc.target/riscv/xtheadfmv-fmv.c +++ b/gcc/testsuite/gcc.target/riscv/xtheadfmv-fmv.c @@ -18,7 +18,7 @@ d2ll (double d) /* { dg-final { scan-assembler "th.fmv.hw.x" } } */ /* { dg-final { scan-assembler "fmv.x.w" } } */ /* { dg-final { scan-assembler "th.fmv.x.hw" } } */ -/* { dg-final { scan-assembler-not "sw" } } */ -/* { dg-final { scan-assembler-not "fld" } } */ -/* { dg-final { scan-assembler-not "fsd" } } */ -/* { dg-final { scan-assembler-not "lw" } } */ +/* { dg-final { scan-assembler-not "\tsw\t" } } */ +/* { dg-final { scan-assembler-not "\tfld\t" } } */ +/* { dg-final { scan-assembler-not "\tfsd\t" } } */ +/* { dg-final { scan-assembler-not "\tlw\t" } } */