From patchwork Wed Aug 30 21:57:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vineet Gupta X-Patchwork-Id: 1828031 Return-Path: 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=m7qiJTmH; 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 4RbdSX5fxQz1yZs for ; Thu, 31 Aug 2023 07:57:31 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 71E063858000 for ; Wed, 30 Aug 2023 21:57:29 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by sourceware.org (Postfix) with ESMTPS id 03FCA3858D20 for ; Wed, 30 Aug 2023 21:57:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 03FCA3858D20 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-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-27183f4ccc1so137137a91.2 for ; Wed, 30 Aug 2023 14:57:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1693432632; x=1694037432; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=7ZB24octsSPM3qMQhTidE9kflZheu/LyzHaTKaNRpbg=; b=m7qiJTmHu2kO6YnLBoDkaCoGkVJQYZoPQU7ua9I/VvWf0poQaRN1TqWg3I5pQvsdXt hMofyFHZ0EpBfprhFKqfDvgWHSYSXLeT19FGiay4FWo7UNWhFqpnErs0ny6/asIXK7tX xafYIXRiG/NKuR1m6tse2r9uNLJHLsCLqUF6k5MbBVCpfdwfpREx1P2JpRROYYs3zy0T 6PdFNVBBWZNDSWy8W/Ll3XZw0F8WcSxyYbq1fNUTXLzv9ufjwi9UbMgadK33UgPQi6R1 nglk0gP22dju37oQgJh3cDBwSst9AF5ZBeQFlzmuWH25U2/wJoCtqHDbhjtW9EqT+lq8 xOug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693432632; x=1694037432; 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=7ZB24octsSPM3qMQhTidE9kflZheu/LyzHaTKaNRpbg=; b=lIAHwirmsY3b1ai5vtMTwoWCCvHEA0+eQENAPuLxB8xQNAlMdf90VLkcxXGBHxL0fC h40kiggMNTWhcaKE78+DM2ljhQMx76H7vFdJuQzSi4XKEz7cGmlnNX9VfSiQ4RG0QzFl 0U8xmgXsNF5kapf0WlOt7KJe1Xg198apk7oVDWHGJcmttesxfLM44RIrOoiLeVdxuKJ/ Z83AEopmFn/xR89SM8Wm4N0RyZbJ80N5IF60ZUmySLfujER0hLJrzGEXPP9iqXe9W/jQ /UgNIwdUpM9hvnPXjE7cId90yvz0A94AA3JbCNWelOSmIGMcRWDbH1sf9B4kDxek+Dey VXnA== X-Gm-Message-State: AOJu0YzhLBbEdw3fW/tv2oNsyBDVdrw/8CmvP7rUB7G1G8eRazltyNOV 0NOI1NM4jLV++wTwUpX+KGTqU4qaDXclk+QEYmQ= X-Google-Smtp-Source: AGHT+IEhQyqoxkef+l7K/zviQzc8es3kIhY2u3dWgX+lGI4RYj+VEt79flNOOZlInh+rMSJxppjYHA== X-Received: by 2002:a17:90b:384a:b0:268:5203:b8b7 with SMTP id nl10-20020a17090b384a00b002685203b8b7mr3372488pjb.21.1693432631648; Wed, 30 Aug 2023 14:57:11 -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 cq14-20020a17090af98e00b00263e4dc33aasm1656681pjb.11.2023.08.30.14.57.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 14:57:11 -0700 (PDT) From: Vineet Gupta To: gcc-patches@gcc.gnu.org Subject: [PATCH] RISC-V: zicond: remove bogus opt2 pattern Date: Wed, 30 Aug 2023 14:57:08 -0700 Message-Id: <20230830215708.369610-1-vineetg@rivosinc.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.2 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: gnu-toolchain@rivosinc.com, Vineet Gupta , kito.cheng@gmail.com Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This was tripping up gcc.c-torture/execute/pr60003.c at -O1 since the pattern semantics can't be expressed by zicond instructions. This involves test code snippet: if (a == 0) return 0; else return x; } which is equivalent to: "x = (a != 0) ? x : a" and matches define_insn "*czero.nez..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 implying "x = (a != 0) ? 0 : a" which is not what the pattern semantics are. Essentially "(a != 0) ? x : a" cannot be expressed with CZERO.nez As a side note, while correctness prevails, this test still gets a czero in the end, albeit a different one. if-convert generates two if_then_else | (insn 43 20 44 3 (set (reg:DI 143) | (reg/v:DI 136 [ x ])) "pr60003.c":36:9 179 {*movdi_64bit} | (insn 44 43 46 3 (set (reg:DI 142) | (reg/v:DI 134 [ a ])) "pr60003.c":36:9 179 {*movdi_64bit} | | (insn 46 44 47 3 (set (reg:DI 145) | (if_then_else:DI (ne:DI (reg/v:DI 134 [ a ]) | (const_int 0 [0])) | (const_int 0 [0]) | (reg:DI 142))) "pr60003.c":36:9 14532 {*czero.nez.didi} | | (insn 47 46 48 3 (set (reg:DI 144) | (if_then_else:DI (eq:DI (reg/v:DI 134 [ a ]) | (const_int 0 [0])) | (const_int 0 [0]) | (reg:DI 143))) "pr60003.c":36:9 14531 {*czero.eqz.didi} and combine is able to fuse them together | (insn 38 48 39 3 (set (reg/i:DI 10 a0) | (if_then_else:DI (eq:DI (reg/v:DI 134 [ a ]) | (const_int 0 [0])) | (const_int 0 [0]) | (reg:DI 143))) "pr60003.c":40:1 14531 {*czero.eqz.didi} before fix after fix ----------------- ----------------- li a5,1 li a0,1 ld a4,8(sp) ld a5,8(sp) czero.nez a0,a4,a5 czero.eqz a0,a5,a0 The issue only happens at -O1 as at higher optimization levels, the whole conditional move gets optimized away. gcc/ChangeLog: * config/riscv/zicond.md: Remove incorrect op2 pattern. Fixes: 1d5bc3285e8a ("[committed][RISC-V] Fix 20010221-1.c with zicond") Signed-off-by: Vineet Gupta --- gcc/config/riscv/zicond.md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/gcc/config/riscv/zicond.md b/gcc/config/riscv/zicond.md index 25f21d33487e..aa5607a9efd8 100644 --- a/gcc/config/riscv/zicond.md +++ b/gcc/config/riscv/zicond.md @@ -52,13 +52,3 @@ "TARGET_ZICOND && rtx_equal_p (operands[1], operands[2])" "czero.eqz\t%0,%3,%1" ) - -(define_insn "*czero.nez..opt2" - [(set (match_operand:GPR 0 "register_operand" "=r") - (if_then_else:GPR (ne (match_operand:X 1 "register_operand" "r") - (const_int 0)) - (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" -)