From patchwork Wed Aug 7 14:13:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 1970058 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=TPbHD1ci; 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 4WfBx55qrwz1yfM for ; Thu, 8 Aug 2024 00:13:43 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9E5EE3858429 for ; Wed, 7 Aug 2024 14:13:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by sourceware.org (Postfix) with ESMTPS id E80CF3858C41 for ; Wed, 7 Aug 2024 14:13:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E80CF3858C41 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 E80CF3858C41 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::634 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723040000; cv=none; b=Rjrsjh11ApH2W0g2A7sBBAUF1jeScebIDB+Msw5dxc6zrQHE+9QKcUzyqLXSpNdusoSMnHcjEWBAHet50NfUfLrbZHeN8jREihXttN5LZRp44EE6GyvLWWUiD5YkgmErRE2k4rpMHKP0iRTF2rlbqK4HkRQ3K4NWy18ebK6CqgQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723040000; c=relaxed/simple; bh=JYEAl/Ag8L/wPbL3rtDYix+Geqj/gRgKHxy5M1IFuY4=; h=DKIM-Signature:Message-ID:Date:MIME-Version:From:Subject:To; b=FXPKbUecNmy6sCM4RxVmvy02/s1OFgLWtOpcfvC6T20eQQZD5MWU1d68BJ74hD27x2TGlByxjWgkas3uVJKqXvIUTP4k+8lt6QHmlALI8FLDKvrCPMNxFuaLhxd/kEQHiq0D96fZQA8a2feFJfPcenRfsXI4gG4oddYiUGVt/VU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1fb3b7d0d56so12286855ad.1 for ; Wed, 07 Aug 2024 07:13:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723039997; x=1723644797; darn=gcc.gnu.org; h=to:subject:from:content-language:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=HFBJ/fh+mPj9Dd8B9irv45bDB+wI/wP/kHMbUs7RNE8=; b=TPbHD1ciIqqnBO1RJa/jodT9S0A5Wvx0m1FcIi13E9yV2YE9dFFLNI2EheYJpcoAZ/ fmazHMy8f6/YORSVnrxVOVILFeF+oLrIwpDpva72c7C1OO/Z2J1976hmbcUPxspLEqsT q13PLx3hnKf4Ipmp5BRDrDHAjxsV9g+DKYtdmkwvPOr+se1qIzYemi0bSB3z2mCmln8L HNeH0zL952RTRsFXZ4vQ6pZeCPRCzdIN6UaWNhXEqjuCBqQRmZ2eqMMcDvdjNnXXtuTn mXj0WuSvwyj4rLXpJAh6wgTKHxQ5MIzgiOZmlBaO1wr2N1VpF4LWOVEeTiObQ0B3Ayb1 gJng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723039997; x=1723644797; h=to:subject:from:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=HFBJ/fh+mPj9Dd8B9irv45bDB+wI/wP/kHMbUs7RNE8=; b=bgdzoeeT8Xwbz2Iw1o1blBQle6HbDcda8golAq8NS8J2nxcTx3CAIeEh4eIg529ggn CMEvcI4Qxe7RhuUIO1/Z2/erzwp+XSZVDLcyQakbAEHHQJlSl1XZojMOOMCZkyIS4VG5 8/EA4LqJ6/s59r5DUhDnbOT6lGrIz9TypVx1/Rbt7SO09y4N9huz5K/MAdB03ZVYY6XB W0ADsmnJcJOBc9OhtdrBtaEazy8muzf15bMGLuj3alXx7PyWF43GSzOTABTKzT5gsdci J25qFd2wTk0gRzltmPyH7+OsDLH9BYW5SJuZ/HA7k3wB7vsg1gBLNezGNlekUu+DelEQ QwpA== X-Gm-Message-State: AOJu0YwHnvRDOWcZQOr2ZeIbZTTGVorPYG1ox3pVKOi5jwUc5D2Fxi0W K5tAQLzRhKLxsV5n/+XfCzNJKWSXaxBuOjsvE76JJ552mtrtYTpTRZe5zTiW X-Google-Smtp-Source: AGHT+IGYfoY/hMTehYWDrLmouTPrYGbYN3itdka7dqOkgFdSj1Yi6XAxBaVQw1jGc72Mw07eWBIR2w== X-Received: by 2002:a17:903:24c:b0:1fd:a412:5dff with SMTP id d9443c01a7336-1ff57462786mr185250185ad.43.1723039996861; Wed, 07 Aug 2024 07:13:16 -0700 (PDT) Received: from [172.31.0.109] ([136.36.72.243]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-200860f857asm14539325ad.180.2024.08.07.07.13.15 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 07 Aug 2024 07:13:16 -0700 (PDT) Message-ID: <8bf829ea-476e-4129-a5f8-cd367ba1b10f@gmail.com> Date: Wed, 7 Aug 2024 08:13:12 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Content-Language: en-US From: Jeff Law Subject: [to-be-committed][RISC-V][PR target/116240] Ensure object is a comparison before extracting arguments To: "gcc-patches@gcc.gnu.org" 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 was supposed to go out the door yesterday, but I kept getting interrupted. The target bits for rtx costing can't assume the rtl they're given actually matches a target pattern. It's just kind of inherent in how the costing routines get called in various places. In this particular case we're trying to cost a conditional move: (set (dest) (if_then_else (cond) (true) (false)) On the RISC-V port the backend only allows actual conditionals for COND. So something like (eq (reg) (const_int 0)). In the costing code for if-then-else we did something like (XEXP (XEXP (cond, 0), 0))) Which fails miserably if COND is a terminal node like (reg) rather than (ne (reg) (const_int 0) So this patch tightens up the RTL scanning to ensure that we have a comparison before we start looking at the comparison's arguments. Run through my tester without incident, but I'll wait for the pre-commit tester to run through a cycle before pushing to the trunk. Jeff ps. We probably could support a naked REG for the condition and internally convert it to (ne (reg) (const_int 0)), but I don't think it likely happens with any regularity. PR target/116240 gcc/ * config/riscv/riscv.cc (riscv_rtx_costs): Ensure object is a comparison before looking at its arguments. gcc/testsuite * gcc.target/riscv/pr116240.c: New test. diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 5fe4273beb7..3d0a1d12b14 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -3646,9 +3646,11 @@ riscv_rtx_costs (rtx x, machine_mode mode, int outer_code, int opno ATTRIBUTE_UN && XEXP (x, 2) == CONST0_RTX (GET_MODE (XEXP (x, 1)))) || (GET_CODE (XEXP (x, 2)) == REG && XEXP (x, 1) == CONST0_RTX (GET_MODE (XEXP (x, 2)))) - || (GET_CODE (XEXP (x, 1)) == REG + || (COMPARISON_P (XEXP (x, 0)) + && GET_CODE (XEXP (x, 1)) == REG && rtx_equal_p (XEXP (x, 1), XEXP (XEXP (x, 0), 0))) - || (GET_CODE (XEXP (x, 1)) == REG + || (COMPARISON_P (XEXP (x, 0)) + && GET_CODE (XEXP (x, 1)) == REG && rtx_equal_p (XEXP (x, 2), XEXP (XEXP (x, 0), 0))))) { *total = COSTS_N_INSNS (1); diff --git a/gcc/testsuite/gcc.target/riscv/pr116240.c b/gcc/testsuite/gcc.target/riscv/pr116240.c new file mode 100644 index 00000000000..7e3eaa2f544 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/pr116240.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-fwrapv -march=rv64imvxtheadcondmov_xventanacondops -mabi=lp64d" } */ + +int a, b; +void c() { + int e = a >= 2 ? b : a; + short d = e * 2; + if (d) + for (;;) + ; +} +