From patchwork Tue Mar 5 07:15:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1908040 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=HD+4qySU; 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 4Tpn060FyRz23fC for ; Tue, 5 Mar 2024 18:15:34 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E3454385840B for ; Tue, 5 Mar 2024 07:15:31 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 74DED3858C41 for ; Tue, 5 Mar 2024 07:15:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 74DED3858C41 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 74DED3858C41 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709622915; cv=none; b=RedGyydjYNnjhnWhA84gVjaTXGD1zjpGi/vDtvyDvKFS0WhkSJOlnPIxDmrmGq23Atq6bwPMx80AOpx0UdLtXRZPxbNyOlV6RBRbWnoiHM/KDHLiKcqzSH/5rU5her1k3vJmPJYqjU4MVUMb8vfToIlNB93To4zHeamnjpV3ofc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709622915; c=relaxed/simple; bh=eLlqTehUgf0YkJb6scAx9AsMzS2xOOMM6lOa47UvjSo=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=MI2UWH7I0xLun8OVL2lKIArFz5r+XBhkGagHTazlLFUf9+zPXGaJNT1tTC41u1KXQ7L1hAlpwdImyM/rdtrf0lcmvd1io6W9Zft8CqmpfDwp7JfwXgDZAVPBKIDZ5luYSlG4SZxhpVMfLzfuwBRkeEDlKOEmhzYpZ/627KEPbxQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709622913; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=zhwLrCM895mdWXgrevXaRPJdz73NQ6EBhBXLHKGsero=; b=HD+4qySUsnhGQocLOrQUlb0wvbAH5v/jPQOZeo4XJtTYhksIGCHbcxZk0cGVVoPHUPzoev ajQat3u18yc9zNuca/HqYfUifjBgSzauDKgw5O7e6beS7KPGeLwqWEbD9SmzwY91Z2MRFW 9KOvXAXk9OLbGxR909rBXVpPchM6qb8= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-588-2nmA0CFNP1CWpX7xVXbk3A-1; Tue, 05 Mar 2024 02:15:09 -0500 X-MC-Unique: 2nmA0CFNP1CWpX7xVXbk3A-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F11C73C025C4; Tue, 5 Mar 2024 07:15:08 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.226.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AD6364043925; Tue, 5 Mar 2024 07:15:08 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 4257F62f508771 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 5 Mar 2024 08:15:06 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 4257F6ON508770; Tue, 5 Mar 2024 08:15:06 +0100 Date: Tue, 5 Mar 2024 08:15:06 +0100 From: Jakub Jelinek To: Richard Biener , Jeff Law , Eric Botcazou , Peter Bergner Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] lower-subreg: Fix ROTATE handling [PR114211] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Hi! On the following testcase, we have (insn 10 7 11 2 (set (reg/v:TI 106 [ h ]) (rotate:TI (reg/v:TI 106 [ h ]) (const_int 64 [0x40]))) "pr114211.c":8:5 1042 {rotl64ti2_doubleword} (nil)) before subreg1 and the pass decides to use (reg:DI 127 [ h ]) / (reg:DI 128 [ h+8 ]) register pair instead of (reg/v:TI 106 [ h ]). resolve_operand_for_swap_move_operator implements it by pretending it is an assignment from (concatn (reg:DI 127 [ h ]) (reg:DI 128 [ h+8 ])) to (concatn (reg:DI 128 [ h+8 ]) (reg:DI 127 [ h ])) The problem is that if the rotate argument is the same as destination or if there is even an overlap between the first half of the destination with second half of the source we emit incorrect code, because the store to (reg:DI 128 [ h+8 ]) overwrites what we need for source of the second move. THe following patch detects that case and uses a temporary pseudo to hold the original (reg:DI 128 [ h+8 ]) value across the first store. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-03-05 Jakub Jelinek PR rtl-optimization/114211 * lower-subreg.cc (resolve_simple_move): For double-word rotates by BITS_PER_WORD if there is overlap between source and destination use a temporary. * gcc.dg/pr114211.c: New test. Jakub --- gcc/lower-subreg.cc.jj 2024-01-03 11:51:33.713700906 +0100 +++ gcc/lower-subreg.cc 2024-03-04 20:29:13.911428988 +0100 @@ -927,6 +927,21 @@ resolve_simple_move (rtx set, rtx_insn * SRC's operator. */ dest = resolve_operand_for_swap_move_operator (dest); src = src_op; + if (resolve_reg_p (src)) + { + gcc_assert (GET_CODE (src) == CONCATN); + if (reg_overlap_mentioned_p (XVECEXP (dest, 0, 0), + XVECEXP (src, 0, 1))) + { + /* If there is overlap betwee the first half of the + destination and what will be stored to the second one, + use a temporary pseudo. See PR114211. */ + rtx tem = gen_reg_rtx (GET_MODE (XVECEXP (src, 0, 1))); + emit_move_insn (tem, XVECEXP (src, 0, 1)); + src = copy_rtx (src); + XVECEXP (src, 0, 1) = tem; + } + } } else if (resolve_reg_p (src_op)) { --- gcc/testsuite/gcc.dg/pr114211.c.jj 2024-03-04 20:37:58.735339443 +0100 +++ gcc/testsuite/gcc.dg/pr114211.c 2024-03-04 20:37:33.666678077 +0100 @@ -0,0 +1,23 @@ +/* PR rtl-optimization/114211 */ +/* { dg-do run { target int128 } } */ +/* { dg-options "-O -fno-tree-coalesce-vars -Wno-psabi" } */ + +typedef unsigned __int128 V __attribute__((__vector_size__ (16))); +unsigned int u; +V v; + +V +foo (unsigned __int128 h) +{ + h = h << 64 | h >> 64; + h *= ~u; + return h + v; +} + +int +main () +{ + V x = foo (1); + if (x[0] != (unsigned __int128) 0xffffffff << 64) + __builtin_abort (); +}