From patchwork Wed Aug 7 06:27:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christoph_M=C3=BCllner?= X-Patchwork-Id: 1969789 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=vrull.eu header.i=@vrull.eu header.a=rsa-sha256 header.s=google header.b=tASGyXdU; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wf0bk6CPXz1yXs for ; Wed, 7 Aug 2024 16:28:02 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AE8F3385DDC8 for ; Wed, 7 Aug 2024 06:28:00 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by sourceware.org (Postfix) with ESMTPS id F1E483858432 for ; Wed, 7 Aug 2024 06:27:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F1E483858432 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org F1E483858432 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::233 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723012045; cv=none; b=nsfKE97KvKuiQh/plQMsUXnCzYtA7cCGdphUfi7AGfCqXsxiis9Wbmqea153Ix8x4wohJGRjVYIgT6hDEpjzEQQ3eF9zdRTg8asi7dvKLTceLYJ0rAzrqBvSil7W56ezAxt3g51yC3cKWyvzZ84687GJmxR6gRAPXj5sFDWBL0w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723012045; c=relaxed/simple; bh=fWdsBJbjyzINYVm6sykDS5Oi/eLbvoQYsUJqwRsKyj8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ukfRSao/33MYWU9RbpLDMlXmnkVmXNAZ8D9ga7/sglUxFcU3QRVodXPfY1LDYO4+2YCQyDrfQyezz9jtwUjhrcRfNmitaEBKF1q/AM0Fni/1S01AajzO0SFd3BtcwrchccryEPkQogAScXfZo1X1AQJ2k+Jg3heQyXrTQEgoUsk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2f1870c355cso15130521fa.1 for ; Tue, 06 Aug 2024 23:27:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1723012041; x=1723616841; darn=gcc.gnu.org; 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=a6OzhFFREVGH8n01/xGC1GeUIWZoi5CryaRi3k3WgWE=; b=tASGyXdU0tLfebxI6hNgglHzg/u+FFRXzkFx8B7evUqHj3P97zDpWIt2gMl+D1FEPb oOGOgSxtIKpdzjYs8owYb0ZtmOGIDHbao6Gelr/lpu7dU3u+8Z4zUkrro/0osZ4S5C31 ohDXQr+CjSsjyFsAiVF50qOgDqNVs/1ZdFn7fdQLaaicDamobiMGsIT06OhyngSkZ7vU qQeB9AEQ0BNIIWqrLQag6uMvDzE0pSaoNEpEqXki/UCa+tw+Z4x2M9dKbRWRx8J0Fucq 9vh4ntkT+2dVsNVeDX/WpIlsPLkUOMIaR6k42DbFX3+zgZXcoTtU5tJx2CWVsWCIMpzB XBuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723012041; x=1723616841; 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=a6OzhFFREVGH8n01/xGC1GeUIWZoi5CryaRi3k3WgWE=; b=NdeLm2mdPi3bIyr1J5WLZNVwaraQgxjkA6XREFh1ReGqvXvYKgqoZt4xESRWM1BJsM MAetOarmfxfeiRoSLeXi2oamtXsVlOJFZKK1UrftowY8KntQfeuFKDx0PQ9Byo0RO7kR a/esHS4xax88Swy1XeRJgJ6FOVDhF9xVSLJs08HYtQCBuu1i67rxbwfjFRbWsJNhe28K ubp+JHc2EuJ8YdOI1YA8artEYyC5Ws8wn4Pc/pJhQ5rStfkRT/zOt+TtAOU3gR3D+vgV 8brudjqSiQJxk8L/qaou2QVJhanx/XPaVwUlO4EiKWWARHHPwdtysC8mZ5EPwIZAv5p+ hVdg== X-Gm-Message-State: AOJu0YymrYOEur1jBpbWFed920qKbnuxwsdK/Rp3QlwoN83JJHCwE473 iBJxGqCO2lDf41G2aGmDi5PhqviGIhvwZYKbHJxh0Pj2HKgGQDjgd39JPwN0v0b249lMd+icOs0 Qexo= X-Google-Smtp-Source: AGHT+IG+uTrsYed6RA75WxxOvjsFa+MxNHZuOK1IDzIJoi4miVD3nQkV+HUqMCK2HorDKVqpelDaHg== X-Received: by 2002:a2e:9548:0:b0:2ef:265e:bb93 with SMTP id 38308e7fff4ca-2f15aa84e0cmr111992451fa.3.1723012039312; Tue, 06 Aug 2024 23:27:19 -0700 (PDT) Received: from antares.fritz.box (62-178-148-172.cable.dynamic.surfer.at. [62.178.148.172]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-429059a564asm12101995e9.32.2024.08.06.23.27.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 23:27:19 -0700 (PDT) From: =?utf-8?q?Christoph_M=C3=BCllner?= To: gcc-patches@gcc.gnu.org, Kito Cheng , Jim Wilson , Palmer Dabbelt , Andrew Waterman , Philipp Tomsich , Jeff Law , Patrick O'Neill Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [PATCH 3/3] RISC-V: rv32/DF: Prevent 2 SImode loads using XTheadMemIdx Date: Wed, 7 Aug 2024 08:27:14 +0200 Message-ID: <20240807062714.2989672-3-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240807062714.2989672-1-christoph.muellner@vrull.eu> References: <20240807062714.2989672-1-christoph.muellner@vrull.eu> MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_MANYTO, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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~incoming=patchwork.ozlabs.org@gcc.gnu.org When enabling XTheadFmv/Zfa and XThead(F)MemIdx, we might end up with the following insn (registers are examples, but of correct class): (set (reg:DF a4) (mem:DF (plus:SI (mult:SI (reg:SI a0) (const_int 8)) (reg:SI a5)))) This is a result of an attempt to load the DF register via two SI register loads followed by XTheadFmv/Zfa instructions to move the contents of the two SI registers into the DF register. The two loads are generated in riscv_split_doubleword_move(), where the second load adds an offset of 4 to load address. While this works fine for RVI loads, this can't be handled for XTheadMemIdx addresses. Coming back to the example above, we would end up with the following insn, which can't be simplified or matched: (set (reg:SI a4) (mem:SI (plus:SI (plus:SI (mult:SI (reg:SI a0) (const_int 8)) (reg:SI a5)) (const_int 4)))) This triggered an ICE in the past, which was resolved in b79cd204c780, which also added the test xtheadfmemidx-medany.c, where the examples are from. The patch postponed the optimization insn_and_split pattern for XThead(F)MemIdx, so that the situation could effectively be avoided. Since we don't want to rely on these optimization pattern in the future, we need a different solution. Therefore, this patch restricts the movdf_hardfloat_rv32 insn to not match for split-double-word-moves with XThead(F)MemIdx operands. This ensures we don't need to split them up later. When looking at the code generation of the test file, we can see that we have less GP<->FP conversions, but cannot use the indexed loads. The new sequence is identical to rv32gc_xtheadfmv (similar to rv32gc_zfa). Old: [...] lla a5,.LANCHOR0 th.flrd fa5,a5,a0,3 fmv.x.w a4,fa5 th.fmv.x.hw a5,fa5 .L1: fmv.w.x fa0,a4 th.fmv.hw.x fa0,a5 ret [...] New: [...] lla a5,.LANCHOR0 slli a4,a0,3 add a4,a4,a5 lw a5,4(a4) lw a4,0(a4) .L1: fmv.w.x fa0,a4 th.fmv.hw.x fa0,a5 ret [...] This was tested (together with the patch that eliminates the XTheadMemIdx optimization patterns) with SPEC CPU 2017 intrate on QEMU (RV64/lp64d). gcc/ChangeLog: * config/riscv/constraints.md (th_m_noi): New constraint. * config/riscv/riscv.md: Adjust movdf_hardfloat_rv32 for XTheadMemIdx. gcc/testsuite/ChangeLog: * gcc.target/riscv/xtheadfmemidx-xtheadfmv-medany.c: Adjust. * gcc.target/riscv/xtheadfmemidx-zfa-medany.c: Likewise. Signed-off-by: Christoph Müllner --- gcc/config/riscv/constraints.md | 9 +++++++++ gcc/config/riscv/riscv.md | 4 ++-- .../gcc.target/riscv/xtheadfmemidx-xtheadfmv-medany.c | 3 ++- .../gcc.target/riscv/xtheadfmemidx-zfa-medany.c | 3 ++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/gcc/config/riscv/constraints.md b/gcc/config/riscv/constraints.md index a9ee346af6f0..3ab6d5426223 100644 --- a/gcc/config/riscv/constraints.md +++ b/gcc/config/riscv/constraints.md @@ -243,6 +243,15 @@ (define_memory_constraint "th_m_miu" (and (match_code "mem") (match_test "th_memidx_legitimate_index_p (op, true)"))) +(define_memory_constraint "th_m_noi" + "@internal + A MEM with does not match XTheadMemIdx operands." + (and (match_code "mem") + (and (match_test "!th_memidx_legitimate_modify_p (op, true)") + (and (match_test "!th_memidx_legitimate_modify_p (op, false)") + (and (match_test "!th_memidx_legitimate_index_p (op, false)") + (match_test "!th_memidx_legitimate_index_p (op, true)")))))) + ;; CORE-V Constraints (define_constraint "CV_alu_pow2" "@internal diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md index d9f6c1765d0a..f46851dd4717 100644 --- a/gcc/config/riscv/riscv.md +++ b/gcc/config/riscv/riscv.md @@ -2592,8 +2592,8 @@ (define_expand "movdf" ;; In RV32, we lack fmv.x.d and fmv.d.x. Go through memory instead. ;; (However, we can still use fcvt.d.w to zero a floating-point register.) (define_insn "*movdf_hardfloat_rv32" - [(set (match_operand:DF 0 "nonimmediate_operand" "=f, f,f,f,m,m,*zmvf,*zmvr, *r,*r,*m") - (match_operand:DF 1 "move_operand" " f,zfli,G,m,f,G,*zmvr,*zmvf,*r*G,*m,*r"))] + [(set (match_operand:DF 0 "nonimmediate_operand" "=f, f,f,f,m,m,*zmvf,*zmvr, *r,*r,*th_m_noi") + (match_operand:DF 1 "move_operand" " f,zfli,G,m,f,G,*zmvr,*zmvf,*r*G,*th_m_noi,*r"))] "!TARGET_64BIT && TARGET_DOUBLE_FLOAT && (register_operand (operands[0], DFmode) || reg_or_0_operand (operands[1], DFmode))" diff --git a/gcc/testsuite/gcc.target/riscv/xtheadfmemidx-xtheadfmv-medany.c b/gcc/testsuite/gcc.target/riscv/xtheadfmemidx-xtheadfmv-medany.c index 7c70b7758246..6746c3140578 100644 --- a/gcc/testsuite/gcc.target/riscv/xtheadfmemidx-xtheadfmv-medany.c +++ b/gcc/testsuite/gcc.target/riscv/xtheadfmemidx-xtheadfmv-medany.c @@ -35,5 +35,6 @@ double foo (int i, int j) return z; } -/* { dg-final { scan-assembler-times {\mth\.flrd\M} 1 } } */ +/* { dg-final { scan-assembler-not {\mth\.flrd\M} } } */ +/* { dg-final { scan-assembler-times {\mlw\M} 2 } } */ /* { dg-final { scan-assembler-times {\mth\.fmv\.hw\.x\M} 3 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/xtheadfmemidx-zfa-medany.c b/gcc/testsuite/gcc.target/riscv/xtheadfmemidx-zfa-medany.c index 4215eab11951..fb1ac2b735c3 100644 --- a/gcc/testsuite/gcc.target/riscv/xtheadfmemidx-zfa-medany.c +++ b/gcc/testsuite/gcc.target/riscv/xtheadfmemidx-zfa-medany.c @@ -35,5 +35,6 @@ double foo (int i, int j) return z; } -/* { dg-final { scan-assembler-times {\mth\.flrd\M} 1 } } */ +/* { dg-final { scan-assembler-not {\mth\.flrd\M} } } */ +/* { dg-final { scan-assembler-times {\mlw\M} 2 } } */ /* { dg-final { scan-assembler-times {\mfmvp\.d\.x\M} 3 } } */