From patchwork Sat Jul 22 21:48:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vineet Gupta X-Patchwork-Id: 124378 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp992765vqg; Sat, 22 Jul 2023 14:48:51 -0700 (PDT) X-Google-Smtp-Source: APBJJlEvvZzps/3wAgbkXgf+ykezgc9t5qM8g7uTVkog6zNFquAHCCVvqJHFO6AOnEGBVesBFU2K X-Received: by 2002:aa7:c2c4:0:b0:522:1956:a29e with SMTP id m4-20020aa7c2c4000000b005221956a29emr2096342edp.34.1690062531569; Sat, 22 Jul 2023 14:48:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690062531; cv=none; d=google.com; s=arc-20160816; b=Qv0TEwTzWS2iGcHCHa0YWnWpM48njif/SVgCDXVJ2c9jrAJJy1ffjv/bI5uFNqf/Pu JhS6Kc3Kpok3G1XGDDlOkF5SYelTX1M+mMjsiaDpD4FdGeh3oQoX3YNbJjGPU/tSaWVS un5DzQs10Bfsdh5n7HIdIpNBLewuEZE7458eMJg2VgyhqcL8htRcalgQgmscl92SQiIO GJ+tpunSK5fVjsl3OGVlLw0Ax+Ixa1cujYEsB/6wS4YRmb1htypAwdY8JRStofzZk3lt Kv0havI8rJejzFf3lljIcglYfZ7xk4I9rObPFc0G5cSqGaCb41s7grQW3PfyO3hU3bRl r9Jw== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:dmarc-filter:delivered-to; bh=3+khbDYDMweC4CRf5tuHLcBfbuhy/nus/TSQhgKiH58=; fh=kYlXBwRGOYSmTKakko9dNdhAjhRKYHnpjgpu59Q/Y7Y=; b=wmTuSJd12afEzQl94LN1HKtDBHCTpvodE2cQtUINKRg3KwPxV/ImwBb+fj2FDoS0op jar/fbFReJvncT1xj4zOdkb6TGBVesuBbvsXE+ZqYhKSn+sY3DEzmQKNsWsgNsbpeNEw Yw4Fi5Csny27+XC0DePQDmE3lvHTswIjqUHXcK/k3BbeWPSecm88Ed+AVl7ZDlttqr/s 8knvbGfy+h0qeTLDbZphIMRRRPGsr8UFJ2eJm/fxq3RERDYwyd3J07TC+AFaYU4mHr91 uWdCJsjgRwmdRA1h6snPO8XxpeHbP5mBhSShWATeAEAPUUglowD/X/av+XSb+VuMWrre DJaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=qxA7de3K; 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 f15-20020aa7d84f000000b00521cb669a89si4394697eds.135.2023.07.22.14.48.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Jul 2023 14:48:51 -0700 (PDT) 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; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=qxA7de3K; 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 CA7D3385E00F for ; Sat, 22 Jul 2023 21:48:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by sourceware.org (Postfix) with ESMTPS id 728793858D1E for ; Sat, 22 Jul 2023 21:48:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 728793858D1E 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-pl1-x62b.google.com with SMTP id d9443c01a7336-1bb8a89b975so1618245ad.1 for ; Sat, 22 Jul 2023 14:48:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1690062490; x=1690667290; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3+khbDYDMweC4CRf5tuHLcBfbuhy/nus/TSQhgKiH58=; b=qxA7de3K2lIha+zGwuw9gT3Rh9jSciDe212Rij662UgPdZLKTPjcGQUQn5O3O4Xc+T qE4RRg6SNTOUt1FnAoGYdb6WneyZ38U/WCRe6y1CRDsy5nEl3QglIr1J7jhYLzFKKOUj BHHJsCyoBoUEm/g8R7DXBr5lWB21Ja8uDpMIIFiofOjKmLlqfwpVjzxo8QgEStRpGURR spiQWcDMCNK4uovHhSdXYz1uqmYNEa1auTnps0WwnEhNCWRRHnXYR40xfMjP3FKZ5rOr UYjfvcCrPF44NXyPNzft7CYBGFQdRlwR0+MEGooduVpJihz3Q172qmk8wpemk7l2TrO3 9p/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690062490; x=1690667290; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3+khbDYDMweC4CRf5tuHLcBfbuhy/nus/TSQhgKiH58=; b=Ok1J8DgB8bfrmwXQcpUILezKo1aQFun2UdRrcMI116cssJzqywbqzQUSkqxFB+aL1Y nTdj3203i3cECq5rHZPvjh2+5b8sRZcmXV4E5ajB13ONz7O5l50dxsrZj7z5G95FrXoO q+UnQyUAfr+vjdEHSdgV/56CQMz/NDU0zrIU7o/3RBi8Wf5WVnELHfwhFQiAxNvz8lbx bMjNTFp3oLCu8O9Xrnhen1BBmd/DMiSbKriu4b1mKQqGIJ3RFdk/ItgLZLjXYdAECS6J YM80ejfDjSoEwBdqxyodwEtCKbR2UL48aZdrcsbLji1SqqBr48VDTEX2+rDljBSxGwt+ 5lag== X-Gm-Message-State: ABy/qLaeV/ClTz2G3XU4KzOkibH43Y6fo4SoNzKVahL+xppx8Z0yp0Il 1PPN8F8CqoWXbBTpngW+BjDnPrjGxi2i2gOIoD9dEA== X-Received: by 2002:a17:902:e890:b0:1b6:4bbd:c3b6 with SMTP id w16-20020a170902e89000b001b64bbdc3b6mr5202132plg.9.1690062490174; Sat, 22 Jul 2023 14:48:10 -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 jw22-20020a170903279600b001b9da42cd7dsm5801092plb.279.2023.07.22.14.48.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Jul 2023 14:48:09 -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, Philipp Tomsich , Vineet Gupta Subject: [Committed] RISC-V: optim const DF +0.0 store to mem [PR/110748] Date: Sat, 22 Jul 2023 14:48:05 -0700 Message-Id: <20230722214805.297932-1-vineetg@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <032e1546-8d92-e274-37b8-9d8d5438b679@rivosinc.com> References: <032e1546-8d92-e274-37b8-9d8d5438b679@rivosinc.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 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: 1772159008991323343 Fixes: ef85d150b5963 ("RISC-V: Enable TARGET_SUPPORTS_WIDE_INT") 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 The fix updates predicate const_0_operand() so reg_or_0_operand () now includes const_double, enabling movdf expander -> riscv_legitimize_move () to generate below vs. an intermediate set (reg:DF) const_double:DF | (insn 6 3 0 2 (set (mem:DF (reg/v/f:DI 134 [ d ]) | (const_double:DF 0.0 [0x0.0p+0])) This change also enables such insns to be recog() by later passes. The md pattern "*movdf_hardfloat_rv64" despite already supporting the needed constraints {"m","G"} mem/const 0.0 was failing to match because the additional condition check reg_or_0_operand() was failing due to missing const_double. This failure to recog() was triggering an ICE when testing the in-flight f-m-o patches and is how all of this started, but then was deemed to be an independent optimization of it's own [1]. [1] https://gcc.gnu.org/pipermail/gcc-patches/2023-July/624857.html Its worthwhile to note all the set peices were already there and working up until my own commit mentioned at top regressed the whole thing. Ran thru full multilib testsuite and no surprises. There was 1 false failure due to random string "lw" appearing in lto build assembler output, which is also fixed here. gcc/ChangeLog: PR target/110748 * 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 --- 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" } } */