From patchwork Tue Jun 27 18:40:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 1800782 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nextmovesoftware.com header.i=@nextmovesoftware.com header.a=rsa-sha256 header.s=default header.b=AQTu1wsT; dkim-atps=neutral Received: from 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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QrD6b3tgLz20bH for ; Wed, 28 Jun 2023 04:40:23 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 77E5A3858C41 for ; Tue, 27 Jun 2023 18:40:21 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id 815993858C2D for ; Tue, 27 Jun 2023 18:40:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 815993858C2D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nextmovesoftware.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=m3z59Ks385vdc/fJbD+OJuciKkHuO50jynM7ms18Zt4=; b=AQTu1wsTF6w8qUjweYpoj4ZHje Pgb7tEqpo0ITiTvbAkVVReCcyROWIcE86YxvI+zx4rOqJUqN7PXMcUDfZIO9IyABVYhQVxgdlLpVG Sx740CouecoK15PTK+yX0gWqBoYd/KpH3Z+PnBQgmn7k1bX//6y0SC8zWQjztuLE1El1bLnoJGhaE PyMxMr6au1eThhCHbRrnm/vL0266tog+XNDea01Qq4lrUK1P6znqkO40D+ogMrya3x661+u9pjO9s lEovhVMF2hDhU02ZZEvBX8J9Qu6dKYPZwAGCqi/WAB9cbtC0cr15scDvCq5kL7FdfYmlt/fuLZszu BVSzDzoQ==; Received: from [185.62.158.67] (port=50122 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1qEDbk-0002Mo-2p; Tue, 27 Jun 2023 14:40:09 -0400 From: "Roger Sayle" To: Cc: "'Uros Bizjak'" Subject: [x86 PATCH] Fix FAIL of gcc.target/i386/pr78794.c on ia32. Date: Tue, 27 Jun 2023 19:40:06 +0100 Message-ID: <020901d9a926$cc4b7950$64e26bf0$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdmpJc6pH+vH/9weTfORenFvnTcElg== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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.29 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 Sender: "Gcc-patches" This patch fixes the FAIL of gcc.target/i386/pr78794.c on ia32, which is caused by minor STV rtx_cost differences with -march=silvermont. It turns out that generic tuning results in pandn, but the lack of accurate parameterization for COMPARE in compute_convert_gain combined with small differences in scalar<->SSE costs on silvermont results in this DImode chain not being converted. The solution is to provide more accurate costs/gains for converting (DImode and SImode) comparisons. I'd been holding off of doing this as I'd thought it would be possible to turn pandn;ptestz into ptestc (for an even bigger scalar-to-vector win) but I've recently realized that these optimizations (as I've implemented them) occur in the wrong order (stv2 occurs after combine), so it isn't easy for STV to convert CCZmode into CCCmode. Doh! Perhaps something can be done in peephole2... This patch has been tested on x86_64-pc-linux-gnu with make bootstrap and make -k check, both with and without --target_board=unix{-m32} with no new failures. Ok for mainline? 2023-06-27 Roger Sayle gcc/ChangeLog PR target/78794 * config/i386/i386-features.cc (compute_convert_gain): Provide more accurate gains for conversion of scalar comparisons to PTEST. Thanks for your patience. Roger diff --git a/gcc/config/i386/i386-features.cc b/gcc/config/i386/i386-features.cc index 4a3b07a..53bec08 100644 --- a/gcc/config/i386/i386-features.cc +++ b/gcc/config/i386/i386-features.cc @@ -631,7 +631,31 @@ general_scalar_chain::compute_convert_gain () break; case COMPARE: - /* Assume comparison cost is the same. */ + if (XEXP (src, 1) != const0_rtx) + { + /* cmp vs. pxor;pshufd;ptest. */ + igain += COSTS_N_INSNS (m - 3); + } + else if (GET_CODE (XEXP (src, 0)) != AND) + { + /* test vs. pshufd;ptest. */ + igain += COSTS_N_INSNS (m - 2); + } + else if (GET_CODE (XEXP (XEXP (src, 0), 0)) != NOT) + { + /* and;test vs. pshufd;ptest. */ + igain += COSTS_N_INSNS (2 * m - 2); + } + else if (TARGET_BMI) + { + /* andn;test vs. pandn;pshufd;ptest. */ + igain += COSTS_N_INSNS (2 * m - 3); + } + else + { + /* not;and;test vs. pandn;pshufd;ptest. */ + igain += COSTS_N_INSNS (3 * m - 3); + } break; case CONST_INT: