From patchwork Mon Feb 5 00:24:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 1895104 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=nextmovesoftware.com header.i=@nextmovesoftware.com header.a=rsa-sha256 header.s=default header.b=dMoXq+xb; 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 4TSnGB05NHz23g7 for ; Mon, 5 Feb 2024 11:25:20 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D47303858422 for ; Mon, 5 Feb 2024 00:25:12 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from server.nextmovesoftware.com (unknown [69.48.154.134]) by sourceware.org (Postfix) with ESMTPS id 006503858CDB for ; Mon, 5 Feb 2024 00:24:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 006503858CDB Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=nextmovesoftware.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 006503858CDB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=69.48.154.134 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707092689; cv=none; b=T/HaslF6wA+7Gwg4aKtjkZloGH7tY3dAOclEKNwSxrgmz3o+P29dfRlgltdsmrtC26t0jvL6tSx69tBF8bkzl++5l7hojO4cwtXddhXqwockAPPlSOxYJlfgxrEW50xxHmDdutN4bQ0xzv1Hq3YTDJNHEISzwE1+fhdxahDLl1A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707092689; c=relaxed/simple; bh=xnlq/pXbbioajs6Vxm9OL4IkxZNp6mhXlUwLdUSGHvo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=AyVOiE3Ff75pxTut+prtMQi75i21Wa4KDbpIKFxo6h4iqX1nvnmdpDiOqDB4qGFddbjvXRoiXdFVi7B13bRQuMgleEi+riF4cdHDG8PHtxm+uhl4x7bSxe5RAU080VrVYeg8Y7gAKJHH3u4Jpzw18Fh9VPg0UdyvI6OGWMjLLrs= ARC-Authentication-Results: i=1; server2.sourceware.org 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=4fOx5YaKs6iSYm/5OyUfgahadVCIeJLIG8/jjuB7CQA=; b=dMoXq+xb18AtuHevO2doukglmg /9OrFPmvBTyjCayMnutrDk0wK2ZcKcdzQgm/bEzZQhVODcar1+sk8wz2LdEYJBmG4Ir4heGwhTxd7 08WX+sUBZj8RSJbl0fNg7GjsAA9X3dnysxwSvHaiWmsoYtxBQbwaRI01E9qoDKceHjTrsdqcuUmyt GSZ5AAAmRXjenTfYyeHRhXWf9Ws7I35W6zCZ0qP5U8laPFJgexdqF7Kc3INefWhxx0+4L96/a9m9v X9EPbOSjzraSOT2okonBRQArurSQTRJjjkgCZrdndW3LSao2GTomnXaHbgEeY0FToYdRi/smcvhdG rMjde+4w==; Received: from host109-154-238-250.range109-154.btcentralplus.com ([109.154.238.250]:60485 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1rWmmy-00D2fu-0X; Sun, 04 Feb 2024 19:24:44 -0500 From: "Roger Sayle" To: Cc: "'Uros Bizjak'" Subject: [x86_64 PATCH] PR target/113690: Fix-up MULT REG_EQUAL notes in STV. Date: Mon, 5 Feb 2024 00:24:40 -0000 Message-ID: <00b701da57c9$b7444a80$25ccdf80$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdpXyQbQoxZ/kdbcR2mXeCN/mF8KHA== 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.4 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_SOFTFAIL, 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.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 patch fixes PR target/113690, an ICE-on-valid regression on x86_64 that exhibits with a specific combination of command line options. The cause is that x86's scalar-to-vector pass converts a chain of instructions from TImode to V1TImode, but fails to appropriately update the attached REG_EQUAL note. Given that multiplication isn't supported in V1TImode, the REG_NOTE handling code wasn't expecting to see a MULT. Easily solved with additional handling for other binary operators that may potentially (in future) have an immediate constant as the second operand that needs handling. For convenience, this code (re)factors the logic to convert a TImode constant into a V1TImode constant vector into a subroutine and reuses it. For the record, STV is actually doing something useful in this strange testcase, GCC with -O2 -fno-dce -fno-forward-propagate -fno-split-wide-types -funroll-loops generates: foo: movl $v, %eax pxor %xmm0, %xmm0 movaps %xmm0, 48(%rax) movaps %xmm0, (%rax) movaps %xmm0, 16(%rax) movaps %xmm0, 32(%rax) ret With the addition of -mno-stv (to disable the patched code) it gives: foo: movl $v, %eax movq $0, 48(%rax) movq $0, 56(%rax) movq $0, (%rax) movq $0, 8(%rax) movq $0, 16(%rax) movq $0, 24(%rax) movq $0, 32(%rax) movq $0, 40(%rax) ret 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? 2024-02-05 Roger Sayle gcc/ChangeLog PR target/113690 * config/i386/i386-features.cc (timode_convert_cst): New helper function to convert a TImode CONST_SCALAR_INT_P to a V1TImode CONST_VECTOR. (timode_scalar_chain::convert_op): Use timode_convert_cst. (timode_scalar_chain::convert_insn): If a REG_EQUAL note contains a binary operator where the second operand is an immediate integer constant, convert it to V1TImode using timode_convert_cst. Use timode_convert_cst. gcc/testsuite/ChangeLog PR target/113690 * gcc.target/i386/pr113690.c: New test case. Thanks in advance, Roger diff --git a/gcc/config/i386/i386-features.cc b/gcc/config/i386/i386-features.cc index 4020b27..90ada7d 100644 --- a/gcc/config/i386/i386-features.cc +++ b/gcc/config/i386/i386-features.cc @@ -1749,6 +1749,19 @@ timode_scalar_chain::fix_debug_reg_uses (rtx reg) } } +/* Helper function to convert immediate constant X to V1TImode. */ +static rtx +timode_convert_cst (rtx x) +{ + /* Prefer all ones vector in case of -1. */ + if (constm1_operand (x, TImode)) + return CONSTM1_RTX (V1TImode); + + rtx *v = XALLOCAVEC (rtx, 1); + v[0] = x; + return gen_rtx_CONST_VECTOR (V1TImode, gen_rtvec_v (1, v)); +} + /* Convert operand OP in INSN from TImode to V1TImode. */ void @@ -1775,18 +1788,8 @@ timode_scalar_chain::convert_op (rtx *op, rtx_insn *insn) } else if (CONST_SCALAR_INT_P (*op)) { - rtx vec_cst; rtx tmp = gen_reg_rtx (V1TImode); - - /* Prefer all ones vector in case of -1. */ - if (constm1_operand (*op, TImode)) - vec_cst = CONSTM1_RTX (V1TImode); - else - { - rtx *v = XALLOCAVEC (rtx, 1); - v[0] = *op; - vec_cst = gen_rtx_CONST_VECTOR (V1TImode, gen_rtvec_v (1, v)); - } + rtx vec_cst = timode_convert_cst (*op); if (!standard_sse_constant_p (vec_cst, V1TImode)) { @@ -1830,12 +1833,28 @@ timode_scalar_chain::convert_insn (rtx_insn *insn) tmp = find_reg_equal_equiv_note (insn); if (tmp) { - if (GET_MODE (XEXP (tmp, 0)) == TImode) - PUT_MODE (XEXP (tmp, 0), V1TImode); - else if (CONST_SCALAR_INT_P (XEXP (tmp, 0))) - XEXP (tmp, 0) - = gen_rtx_CONST_VECTOR (V1TImode, - gen_rtvec (1, XEXP (tmp, 0))); + rtx expr = XEXP (tmp, 0); + if (GET_MODE (expr) == TImode) + { + PUT_MODE (expr, V1TImode); + switch (GET_CODE (expr)) + { + case PLUS: + case MINUS: + case MULT: + case AND: + case IOR: + case XOR: + if (CONST_SCALAR_INT_P (XEXP (expr, 1))) + XEXP (expr, 1) = timode_convert_cst (XEXP (expr, 1)); + break; + + default: + break; + } + } + else if (CONST_SCALAR_INT_P (expr)) + XEXP (tmp, 0) = timode_convert_cst (expr); } } break; @@ -1876,7 +1895,7 @@ timode_scalar_chain::convert_insn (rtx_insn *insn) } else { - src = gen_rtx_CONST_VECTOR (V1TImode, gen_rtvec (1, src)); + src = timode_convert_cst (src); src = validize_mem (force_const_mem (V1TImode, src)); use_move = MEM_P (dst); } diff --git a/gcc/testsuite/gcc.target/i386/pr113690.c b/gcc/testsuite/gcc.target/i386/pr113690.c new file mode 100644 index 0000000..23a1108 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr113690.c @@ -0,0 +1,12 @@ +/* { dg-do compile { target int128 } } */ +/* { dg-options "-O2 -fno-dce -fno-forward-propagate -fno-split-wide-types -funroll-loops" } */ +int i; +__attribute__((__vector_size__(64))) __int128 v; + +void +foo(void) +{ + v <<= 127; + __builtin_mul_overflow(0, i, &v[3]); + v *= 6; +}