Message ID | 20230905152015.9738-1-vineetg@rivosinc.com |
---|---|
State | New |
Headers | show
Return-Path: <gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org> X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=rbD87COx; 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 4Rg8Mq3nMcz1ygx for <incoming@patchwork.ozlabs.org>; Wed, 6 Sep 2023 01:20:39 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D366E3857355 for <incoming@patchwork.ozlabs.org>; Tue, 5 Sep 2023 15:20:34 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by sourceware.org (Postfix) with ESMTPS id EE0FE3858D32 for <gcc-patches@gcc.gnu.org>; Tue, 5 Sep 2023 15:20:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EE0FE3858D32 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-x632.google.com with SMTP id d9443c01a7336-1bf57366ccdso21821975ad.1 for <gcc-patches@gcc.gnu.org>; Tue, 05 Sep 2023 08:20:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1693927219; x=1694532019; 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=v+YZcHT21XHJ5XH3gqFrsTVEQJLOrE/qxUlFgnpXx6Q=; b=rbD87COx4lDWniE+eSQ+BttfLZs3Q1lSHCJP3w/IsVCSjYQY7E3n8nh6S/rMODila0 TimT/GHL0NcY69VN1RSbeUaW1AVMMDN5hY8xfpDlokHK1tnnEmQWq4xQEcrI0cFgkDct RdXfdBFozlZUKsMt81xIrzUyX81NYvpuGj7VcS+fOFIy1OUta712DJCx4qybjOhGv7hk wtE0dh2L9Fotn6Wn+Zr8+kfaIfAE+5Hj998AM+z3/sog9TgZqPkUa3b5LWnhubwf7OX9 TsZSL/QNrdXVuo25G1jl3dUyBIluaT9yu41DC7J37Xz6r23TKJYDhD5YNUz6HTxnkecP zDaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693927219; x=1694532019; 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=v+YZcHT21XHJ5XH3gqFrsTVEQJLOrE/qxUlFgnpXx6Q=; b=KOSeP1IS1YKrzp5N1wzdgwRNe/JKAXAlp+7ncYmaXnvQ7EWpozCFZNZTyKNARHo23F uoDf+2uRcmq8GGPisoqqvCJ3DORNAX+O5SQAJVCBC7PGCujMU1Me0T0KJBvAvFbaatXs UwCjqA1hhnvp2Z7TAD2cGisbKHyAYqwa+0lIknoV3gwCKi7W0Ur8P4cAMu9sKA4eFKMy gmbQ8oOe69WrMVxSCR3aT43jb+qbiG5P6y/5JOBS57cpnSGQJZhAua5DKDONukwqCYGS dyN6x6mtUHNpFA44f2MOZJ+P6lDUgmnvSmzqjTCZss5twpG0lf9hyuNxYiWofYKUKwHB 3waQ== X-Gm-Message-State: AOJu0YyfnAvhTpeRMWJBZFsH1DqBuCYQoV0a1yYBxtVWlTvpDJwvi9+M g+s/5NN4txGS81OKD2kUdS/ORILR1oBFS4o08/w= X-Google-Smtp-Source: AGHT+IG6TB6DNXHznJL7Yu5HSBMfdvx6fty+CYxsO5qi+Yhs0K36xTC3nxkwrJiT4E6KhBCS6fFsAw== X-Received: by 2002:a17:90a:c78b:b0:26f:510b:b64e with SMTP id gn11-20020a17090ac78b00b0026f510bb64emr16872951pjb.11.1693927219185; Tue, 05 Sep 2023 08:20:19 -0700 (PDT) Received: from vineet-framework.. (c-98-210-197-24.hsd1.ca.comcast.net. [98.210.197.24]) by smtp.gmail.com with ESMTPSA id w11-20020a63b74b000000b00564b313d526sm8727538pgt.54.2023.09.05.08.20.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Sep 2023 08:20:18 -0700 (PDT) From: Vineet Gupta <vineetg@rivosinc.com> To: gcc-patches@gcc.gnu.org Subject: [Committed] RISC-V: zicond: Fix opt2 pattern Date: Tue, 5 Sep 2023 08:20:15 -0700 Message-Id: <20230905152015.9738-1-vineetg@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <629c9a26-a12e-46f8-b8aa-1d1f125cf116@gmail.com> References: <629c9a26-a12e-46f8-b8aa-1d1f125cf116@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Cc: Vineet Gupta <vineetg@rivosinc.com> Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org> |
Series |
[Committed] RISC-V: zicond: Fix opt2 pattern
|
expand
|
diff --git a/gcc/config/riscv/zicond.md b/gcc/config/riscv/zicond.md index 4619220ef8ac..1721e1011ea8 100644 --- a/gcc/config/riscv/zicond.md +++ b/gcc/config/riscv/zicond.md @@ -60,7 +60,7 @@ (match_operand:GPR 2 "register_operand" "r") (match_operand:GPR 3 "register_operand" "1")))] "TARGET_ZICOND && rtx_equal_p (operands[1], operands[3])" - "czero.nez\t%0,%2,%1" + "czero.eqz\t%0,%2,%1" ) ;; Combine creates this form in some cases (particularly the coremark
Fixes: 1d5bc3285e8a ("[committed][RISC-V] Fix 20010221-1.c with zicond") This was tripping up gcc.c-torture/execute/pr60003.c at -O1 since in failing case, pattern semantics were not matching with asm czero.nez We start with the following src code snippet: if (a == 0) return 0; else return x; } which is equivalent to: "x = (a != 0) ? x : a" where x is NOT 0. ^^^^^^^^^^^^^^^^ and matches define_insn "*czero.nez.<GPR:mode><X:mode>.opt2" | (insn 41 20 38 3 (set (reg/v:DI 136 [ x ]) | (if_then_else:DI (ne (reg/v:DI 134 [ a ]) | (const_int 0 [0])) | (reg/v:DI 136 [ x ]) | (reg/v:DI 134 [ a ]))) {*czero.nez.didi.opt2} The corresponding asm pattern generates czero.nez x, x, a ; %0, %2, %1 which implies "x = (a != 0) ? 0 : a" clearly not what the pattern wants to do. Essentially "(a != 0) ? x : a" cannot be expressed with CZERO.nez if X is not guaranteed to be 0. However this can be fixed with a small tweak "x = (a != 0) ? x : a" is same as "x = (a == 0) ? a : x" and since middle operand is 0 when a == 0, it is equivalent to "x = (a == 0) ? 0 : x" which can be expressed with CZERO.eqz before fix after fix ----------------- ----------------- li a5,1 li a5,1 ld a4,8(sp) ld a4,8(sp) czero.nez a0,a4,a5 czero.eqz a0,a4,a5 The issue only happens at -O1 as at higher optimization levels, the whole conditional move gets optimized away. This fixes 4 testsuite failues in a zicond build: FAIL: gcc.c-torture/execute/pr60003.c -O1 execution test FAIL: gcc.dg/setjmp-3.c execution test FAIL: gcc.dg/torture/stackalign/setjmp-3.c -O1 execution test FAIL: gcc.dg/torture/stackalign/setjmp-3.c -O1 -fpic execution test gcc/ChangeLog: * config/riscv/zicond.md: Fix op2 pattern. Signed-off-by: Vineet Gupta <vineetg@rivosinc.com> --- gcc/config/riscv/zicond.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)