From patchwork Sun Jun 23 15:24:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 1951246 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=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=U6Kn0afp; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4W6ZfP2Ykmz20WR for ; Mon, 24 Jun 2024 01:25:17 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 709CB385E83E for ; Sun, 23 Jun 2024 15:25:15 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-yw1-x112e.google.com (mail-yw1-x112e.google.com [IPv6:2607:f8b0:4864:20::112e]) by sourceware.org (Postfix) with ESMTPS id 37123385DDF1 for ; Sun, 23 Jun 2024 15:24:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 37123385DDF1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 37123385DDF1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::112e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719156298; cv=none; b=lobi3t5wnX9X8aaWwGtS/R8qx9dTAplXIzDMiT/LeNQAOibE/vK62mJjZzfEW9Q48424s52MCGraEDifeSggb5YkfgkRAFNJjuQmtmq9m3jGdCFUISjmgoa1giGiXOHda+Xpka88nyU+MVBmqVtHFWTs2P2E4die2gXmKPjxsdo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719156298; c=relaxed/simple; bh=Fx4klGzuLnsWE3AioyAZDvrN89kLzG081KwOTgwq1mk=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=fz76AGRfPw/nWc1ThOTGWkghnJlime7eKCycv8wErXCKL5j8cKSA2qOFWXnqv1WMV77cK/8LXgTEIq/5xtqHj5bcCUrJKFslpl+DU1WmoHnFv0L6a3DsWyq7whbJmho+JfQkgBjBq6Gv3KaIBRnWfFnHIAQgRofV+aThJuOr5zs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-643f1ee4b3cso4347697b3.3 for ; Sun, 23 Jun 2024 08:24:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719156296; x=1719761096; darn=gcc.gnu.org; h=subject:from:to:content-language:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=zgP1pi/pYOOxycFuIAQRcO1V4m+81rIN2vu+yRQFyCE=; b=U6Kn0afps07T88V6S/gs/qpQEbvg2pdkgdbXaGPAum+dyZInLTDuFd7vZ1W9h9iA/T lnkVwryygz2zPDwwveWLKsbC8rzjqJh9k8kGruMrLpltZutRzuezm4bOAAuxG5MAxDAq DGUX6CcufgRSOM9AlrnkoYV8kP4V23Hh4zwHbRRA7bD89Z8JcgpKClZHWCFzr+yLzWVx sVK9fPsRHxBEaJZhvNcMViGvZ4D1KGdyHKWds2fzE4sjpK9+OqDhaQeTPVi5Vku+8SY5 busM4+El6c+4vnchl9I6QURZUQBb0w7v2UsmeP+DHIzGAjb71hmtqU73Ex+dDYj+FfLe vuTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719156296; x=1719761096; h=subject:from:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zgP1pi/pYOOxycFuIAQRcO1V4m+81rIN2vu+yRQFyCE=; b=N6PHLYUlOtH4NvzXapV2jh0MHwOCGIOtE7W8LbIKcGJBbWXKxU31zDRtmF8yb9qr27 yfpTCSzMdPILSDFF191IG5ahY+G617o6/MfJXCWOpu9dY0Jl05JpDtajAY1jdjvlwZtT XdmEfnrc9yAtJKKjj5yf2WqBqR4WroFhXNJjsMqC9waQFc1FVH2cZGcRPb4TkoUfCfQ7 VHADYiQLhefGdod3p/3qAAgAhWXWRrVt5nE9LaPamMZTSEPgenStEROGLWqSRi0c6lCr qsQKSUWEtw1/Y2eCplAfoSE6Ht3uG7h947G0LHW8Wr79r3pnZyR/2L/Jr+tYywiBGN2s OdZA== X-Gm-Message-State: AOJu0Yzg8FFHIUuo087LDnYZ+7aKGAykFY4YOFoh71KAuZEi7RsDYlFf QiVXgCifDKhF1qpSARcoidT/AVwZOc8M6Ykl6poik38InQYHosbXhG4gQw== X-Google-Smtp-Source: AGHT+IFx/N+5WBKHr0yXQWDd48sTW0afL6qneiL5cnDj3lXSOksCBy2XxEB/v0YieEzpz1P4BUwmIQ== X-Received: by 2002:a0d:ea11:0:b0:632:5859:8656 with SMTP id 00721157ae682-643aba45ee1mr19505297b3.36.1719156295434; Sun, 23 Jun 2024 08:24:55 -0700 (PDT) Received: from [172.31.0.109] ([136.36.72.243]) by smtp.gmail.com with ESMTPSA id 00721157ae682-63f154d5eedsm21090997b3.109.2024.06.23.08.24.54 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 23 Jun 2024 08:24:54 -0700 (PDT) Message-ID: <0f722ec6-5e0a-4475-a733-c223a92a355d@gmail.com> Date: Sun, 23 Jun 2024 09:24:53 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Content-Language: en-US To: "gcc-patches@gcc.gnu.org" From: Jeff Law Subject: [to-be-commited][RISC-V] Fix unrecognizable pattern in riscv_expand_conditional_move() X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, 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 This is Artemiy's patch just reformatting so that pre-commit can apply and test it. The patch looks good to me and it's spinning in my tester as well. --- Presently, the code fragment: int x[5]; void d(int a, int b, int c) { for (int i = 0; i < 5; i++) x[i] = (a != b) ? c : a; } causes an ICE when compiled with -O2 -march=rv32i_zicond: test.c: In function 'd': test.c: error: unrecognizable insn: 11 | } | ^ (insn 8 5 9 2 (set (reg:SI 139 [ iftmp.0_2 ]) (if_then_else:SI (ne:SI (reg/v:SI 136 [ a ]) (reg/v:SI 137 [ b ])) (reg/v:SI 136 [ a ]) (reg/v:SI 138 [ c ]))) -1 (nil)) during RTL pass: vregs This happens because, as part of one of the optimizations in riscv_expand_conditional_move(), an if_then_else is generated with both comparands being register operands, resulting in an unmatchable insn since Zicond patterns require constant 0 as the second comparand. Fix this by adding a extra check before performing this optimization. The code snippet mentioned above is also included in this patch as a new Zicond testcase. gcc/ChangeLog: * config/riscv/riscv.cc (riscv_expand_conditional_move): Add a CONST0_RTX check. gcc/testsuite/ChangeLog: * gcc.target/riscv/zicond-ice-3.c: New test. Signed-off-by: Artemiy Volkov --- gcc/config/riscv/riscv.cc | 3 ++- gcc/testsuite/gcc.target/riscv/zicond-ice-3.c | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/riscv/zicond-ice-3.c diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 5c758b95327..cca7ffde33a 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -5111,8 +5111,9 @@ riscv_expand_conditional_move (rtx dest, rtx op, rtx cons, rtx alt) /* reg, reg */ else if (REG_P (cons) && REG_P (alt)) { - if ((code == EQ && rtx_equal_p (cons, op0)) + if (((code == EQ && rtx_equal_p (cons, op0)) || (code == NE && rtx_equal_p (alt, op0))) + && op1 == CONST0_RTX (mode)) { rtx cond = gen_rtx_fmt_ee (code, GET_MODE (op0), op0, op1); alt = force_reg (mode, alt); diff --git a/gcc/testsuite/gcc.target/riscv/zicond-ice-5.c b/gcc/testsuite/gcc.target/riscv/zicond-ice-5.c new file mode 100644 index 00000000000..ac6049c9ae5 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zicond-ice-5.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gc_zicond -mabi=lp64d" { target { rv64 } } } */ +/* { dg-options "-march=rv32gc_zicond -mabi=ilp32f" { target { rv32 } } } */ + +int x[5]; + +void +d(int a, int b, int c) { + for (int i = 0; i < 5; i++) + x[i] = (a != b) ? c : a; +}