From patchwork Tue Jul 23 06:18:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1963542 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=RwPYlxtF; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4WSn6j3c4dz1yYm for ; Tue, 23 Jul 2024 16:19:24 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8FC0D386101E for ; Tue, 23 Jul 2024 06:19:21 +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 ESMTP id 0C7553858403 for ; Tue, 23 Jul 2024 06:18:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0C7553858403 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 0C7553858403 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=1721715541; cv=none; b=b2RGx0mqca6Uej7sslUMSRQ5SgUF0tnKnom4pwaBWiHpB0uAwg0UWZZ5ljC3+8Qj5cpIbbRvyb2XIFi+Gfi9kZKh2N4oGtCJ5TtHaOfhgmXf1Mi531zt4OFkjxbLiU2eKxRx4mfrjuCZQc9HutnCER6jRp6F8L1u72W25PslqT4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721715541; c=relaxed/simple; bh=lY6cOGXB5pQP/91wsB0lK2uPev1IyW2CWuU0dOJwD3Y=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=EySy6HU0GfgqrmKcte9eM3V92wQHyQQIIKIj1Gn1r4C+x8tidIynilucnpTu9+Bc5GxvGZzubYTUiiQKtQe9pdrtorzMrHVQqvnKqeKvWIvUGID3hUxAftdSHeFfp7bWgwCtiBaD/G12vCOpFj6mudy7/gDnJm3Vbc7NXItg0Ks= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721715538; 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=9/WVXkEbiaCv1NIQ9/Azo68e0cbA/o8WL7k1GcWkddQ=; b=RwPYlxtFuBrCtQqf5+Izvjazq/r1ZX6qduQvfig+8csAOYYa5EDy/11SU9DKBNV4JjCYob h/Ba0EC97LsitWB5d5YZ1DbDRO6l+oW64UHmFWImlwDx9l4Ss0ulN/UkzHldyovNhSg0TD TOAb8JXQM7sfUBCsb+ii8CaF9N0Jah4= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-168-4Fd4QJt6O9ix0YmF7ctUFw-1; Tue, 23 Jul 2024 02:18:56 -0400 X-MC-Unique: 4Fd4QJt6O9ix0YmF7ctUFw-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 14C0C1955F3D; Tue, 23 Jul 2024 06:18:55 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.25]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3ECA0195605A; Tue, 23 Jul 2024 06:18:54 +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 46N6IpJL3094332 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 23 Jul 2024 08:18:51 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 46N6Ipfs3094331; Tue, 23 Jul 2024 08:18:51 +0200 Date: Tue, 23 Jul 2024 08:18:50 +0200 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] ssa: Fix up maybe_rewrite_mem_ref_base complex type handling [PR116034] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.7 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 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! The folding into REALPART_EXPR is correct, used only when the mem_offset is zero, but for IMAGPART_EXPR it didn't check the exact offset value (just that it is not 0). The following patch fixes that by using IMAGPART_EXPR only if the offset is right and using BITFIELD_REF or whatever else otherwise. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk, 14.2 and other release branches? 2024-07-23 Jakub Jelinek Andrew Pinski PR tree-optimization/116034 * tree-sra.cc (maybe_rewrite_mem_ref_base): Only use IMAGPART_EXPR if MEM_REF offset is equal to element type size. * gcc.dg/pr116034.c: New test. Jakub --- gcc/tree-ssa.cc.jj 2024-03-11 11:00:46.768915988 +0100 +++ gcc/tree-ssa.cc 2024-07-22 21:27:02.115530861 +0200 @@ -1506,7 +1506,10 @@ maybe_rewrite_mem_ref_base (tree *tp, bi } else if (TREE_CODE (TREE_TYPE (sym)) == COMPLEX_TYPE && useless_type_conversion_p (TREE_TYPE (*tp), - TREE_TYPE (TREE_TYPE (sym)))) + TREE_TYPE (TREE_TYPE (sym))) + && (integer_zerop (TREE_OPERAND (*tp, 1)) + || tree_int_cst_equal (TREE_OPERAND (*tp, 1), + TYPE_SIZE_UNIT (TREE_TYPE (*tp))))) { *tp = build1 (integer_zerop (TREE_OPERAND (*tp, 1)) ? REALPART_EXPR : IMAGPART_EXPR, --- gcc/testsuite/gcc.dg/pr116034.c.jj 2024-07-22 21:39:50.050994243 +0200 +++ gcc/testsuite/gcc.dg/pr116034.c 2024-07-22 21:39:32.432213042 +0200 @@ -0,0 +1,21 @@ +/* PR tree-optimization/116034 */ +/* { dg-do run } */ +/* { dg-options "-O1 -fno-strict-aliasing" } */ + +int g; + +static inline int +foo (_Complex unsigned short c) +{ + __builtin_memmove (&g, 1 + (char *) &c, 2); + return g; +} + +int +main () +{ + if (__SIZEOF_SHORT__ == 2 + && __CHAR_BIT__ == 8 + && foo (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ ? 0x0100 : 1) != 1) + __builtin_abort (); +}