Message ID | 20230905152015.9738-1-vineetg@rivosinc.com |
---|---|
State | Unresolved |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ab0a:0:b0:3f2:4152:657d with SMTP id m10csp1751270vqo; Tue, 5 Sep 2023 08:20:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFzHdPzXvQ+yZ8Im5zTJPX+h0SJw0/nzDAifqu9+8V0V3Q0oCCqcepteyKtJO2dQSaVjp5h X-Received: by 2002:a50:ef13:0:b0:522:1d30:efce with SMTP id m19-20020a50ef13000000b005221d30efcemr129288eds.22.1693927252648; Tue, 05 Sep 2023 08:20:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693927252; cv=none; d=google.com; s=arc-20160816; b=H325D/5MzJPvBdRakBJ6Oa9PxzjxFamVWdorrCNpv1Th46pWYawauUxU6SgC34W9Gy bQ45wZUGIxNFavQvNBKbRIWAnm1iEMzhufuPdnjW4hB1wsql1fCeBLw/9p2Qaai5kata 6FtMkQuObk3AuYUGIfKE6ul0tLvSrDZ+9Ia/QoAvH7kx/dLdb7/7wWczNk2gmJwC4Wzc v3cx0puOw7qQvEOItTajMtsvA2+QnFQqBP2S1yaWiEhZqEGw7RIdvcR+fvTli/xtmK5b btMy1Iy7/KOcu/7OhiHQYO3haMO0Ca5o6/0Pn5DygT+F1d8VO6ovyEMrc2GeDwwWhzD7 gquw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to:from :dkim-signature:dmarc-filter:delivered-to; bh=v+YZcHT21XHJ5XH3gqFrsTVEQJLOrE/qxUlFgnpXx6Q=; fh=ydQ/5StBXPwBoCR+dlqqegDRP0vDb5Guks04U4f4PRo=; b=kZ1t3O+JtXz7vBWEHDQA7Mebrbo185sbxhdwVmHoxkdiZfWwx3LT65J5Cn+WHiMLlb 3cOxsm2PG/QbB0cXK7lYef+fJdsQliIDyDJSZtJ51fu+pwhhAZmI4yaPxTgrF6YSZ3go z17tk1e7Xx2qIXlWv9RuEqt2rn7G6S0yTnT9W8AVHLJ40bll+WQemik2GwTyhbJIaiHu 1LsDGpnR9aDxtosfKIb6BkdosXFc9Ct54GBkrGZl9XyMw+HxEM/JY8CKGaoPzBAlAb1o ocj61QCrz3H7qm1QPLG11i2PjTZAN3Tc26d+CvmhOeS4eoUHrUgZeK5x7G5kuJ6Hpuu4 q2xA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=rbD87COx; 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 z1-20020aa7c641000000b00526eb42f4a8si7804557edr.330.2023.09.05.08.20.52 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Sep 2023 08:20:52 -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=fail header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=rbD87COx; 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 707B4385AC26 for <ouuuleilei@gmail.com>; Tue, 5 Sep 2023 15:20:47 +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-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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1775866246554256349 X-GMAIL-MSGID: 1776211462814686620 |
Series |
[Committed] RISC-V: zicond: Fix opt2 pattern
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | warning | Git am fail log |
Commit Message
Vineet Gupta
Sept. 5, 2023, 3:20 p.m. UTC
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(-)
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