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: 113547 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8398051vqr; Tue, 27 Jun 2023 11:40:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4pQLuwDSxxg+CAV+LpR9Ur1MysFZ1Ds+7dq8Q+h32Dg4qkcADVvgiUJLBPeFbIq4uEmcBf X-Received: by 2002:a17:906:fd8e:b0:982:c69c:8c30 with SMTP id xa14-20020a170906fd8e00b00982c69c8c30mr27585464ejb.55.1687891245337; Tue, 27 Jun 2023 11:40:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687891245; cv=none; d=google.com; s=arc-20160816; b=xkt/zp/y3m38oRYw3tso3+9BjHrv/KdCUTPCa8dIzbcidFAquvnACrRkc7GrEXAQyn RPNuIlHLv+etDq/PeSdd7eIMXdelmcMYkOW9Tg30L9FDjg4WhRbIqtbBPsKDNpimmS5W jFY2r0c8gJb6B36djj35/jZIP1WqUADDQ0X7Bf0yWcMXOdo/pDliwupBNSFBd36noqu3 mznoIZ1m6I0OBQwhynQ+IxcFvkBMfBOmu8VG2CeSbELvWEidc6GF8tZpR0Nxg3QjKtol Iv2/AaQPykS1Z0oA5Wq12dWoquVU2BpwunmHWzl530DPZUePQ6ZH3WKkPvQnnP6Vl6Fb X1iQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-language:thread-index :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dmarc-filter:delivered-to; bh=m3z59Ks385vdc/fJbD+OJuciKkHuO50jynM7ms18Zt4=; fh=ez+UBk19YaOo+lQEyE9porlijlGbJDzUOtzUi3k96eQ=; b=cOidgeEmGtzt8o0DsFXJKAI/v/T/gcqXBTCtUcJALmPKWxUPXxt0wAE7EwNRdFvhc8 Lp1v/dx2qIOylZpSgyCqp9BDmEDfPS/c1p/1eT27qv6gGtsPDq74pRWfYJ5bh1DuSAXX WFgV7xq/9yCM+zWhJbWY5CTOq2mHWHt9UQTI1Q5cFrZPMfz9FijUB0gJHpCB3+8iQpcF B1GftjVwWYwHD94hXxNv8ObQGA13AJgFNVVxoB3LT06Id6Ae4Hv2g907IbfJR06IxLOX uTP/3zSbVRce6cM9sb4Pe/QxYu0G2gekmSAiPUe3ygUU4fDU5q9bT/BLmakRCEkfHKAE I38A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nextmovesoftware.com header.s=default header.b=AQTu1wsT; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id q16-20020a170906361000b0098ce5bd2ed0si4562455ejb.257.2023.06.27.11.40.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 11:40:45 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=fail header.i=@nextmovesoftware.com header.s=default header.b=AQTu1wsT; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 D6373385800A for ; Tue, 27 Jun 2023 18:40:33 +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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769882250525551815?= X-GMAIL-MSGID: =?utf-8?q?1769882250525551815?= 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: