From patchwork Tue May 14 10:57:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 1934950 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=ucw.cz header.i=@ucw.cz header.a=rsa-sha256 header.s=gen1 header.b=sYtomGDj; 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 4Vdtc32tT4z1ymw for ; Tue, 14 May 2024 20:57:36 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EDAEF3870C25 for ; Tue, 14 May 2024 10:57:34 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nikam.ms.mff.cuni.cz (nikam.ms.mff.cuni.cz [195.113.20.16]) by sourceware.org (Postfix) with ESMTPS id 6113E385842A for ; Tue, 14 May 2024 10:57:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6113E385842A Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=ucw.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kam.mff.cuni.cz ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6113E385842A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.113.20.16 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715684236; cv=none; b=vZcM/Zi24DJAp0vfT3meJ3OOG0CwK2Y+zB6G+NqfGU1P/MUrqL9oBuRjh4dg2oDWu7aU8kb30kJi8FukXfnVxrA9WBIMpnSN8YiZ86yeJm+kpIJJ3C1ukih6N+gRC2JRC0hmNN7wlI0NcYihXeehZ5vPYXAzUN5W+dWVQM3HOwg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715684236; c=relaxed/simple; bh=FUR5/fbMdeRY8lvpQTj+aEVc5QPGDNukA12L4UcRa6w=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=rOKOWBgyG0jxNePChRqYm51dxygsbncfQKDJRgkDPTYrKiSFq+3FdDEkijF7Zu9pzlkbAvJ5NBX2ToDwLpjqpPDrGw5OUMkTu/iO08FqwuV37PzudG6QFj2dgBUs9JtKC8J9fRA3VRGQ4N9zcKodaP75HQ3FGsPQcL9wuMztWjY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id D4112286F2E; Tue, 14 May 2024 12:57:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ucw.cz; s=gen1; t=1715684232; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=wFKcUytvcIQLHzqSfkNN5iChAdfsIYr44ebrSebq4+E=; b=sYtomGDjJTwdWDAtJWEClIWfs27k4ovH0BSrNsoMkvQ81zapHHBp//PiitlnYp7e9UHzQP wSldYr8q4XyzbAsOzp6QwhvmmePVQGhXhXNkQFIAY7j7UVNrHqx/zGLl0dX/Cq0Hi299Dq IwoaKFtcohpR8T2AaNLTYnU6XcZ/PbQ= Date: Tue, 14 May 2024 12:57:12 +0200 From: Jan Hubicka To: gcc-patches@gcc.gnu.org, rguenther@suse.de Subject: Avoid TYPE_MAIN_VARIANT compares in TBAA Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, JMQ_SPF_NEUTRAL, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, 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: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Hi, while building more testcases for ipa-icf I noticed that there are two places in aliasing code where we still compare TYPE_MAIN_VARIANT for pointer equality. This is not good idea for LTO since type merging may not happen for example when in one unit pointed to type is forward declared while in other it is fully defined. We have same_type_for_tbaa for that. Bootstrapped/regtested x86_64-linux, OK? gcc/ChangeLog: * alias.cc (reference_alias_ptr_type_1): Use view_converted_memref_p. * alias.h (view_converted_memref_p): Declare. * tree-ssa-alias.cc (view_converted_memref_p): Export. (ao_compare::compare_ao_refs): Use same_type_for_tbaa. diff --git a/gcc/alias.cc b/gcc/alias.cc index 808e2095d9b..853e84d7439 100644 --- a/gcc/alias.cc +++ b/gcc/alias.cc @@ -770,10 +770,7 @@ reference_alias_ptr_type_1 (tree *t) /* If the innermost reference is a MEM_REF that has a conversion embedded treat it like a VIEW_CONVERT_EXPR above, using the memory access type for determining the alias-set. */ - if (TREE_CODE (inner) == MEM_REF - && (TYPE_MAIN_VARIANT (TREE_TYPE (inner)) - != TYPE_MAIN_VARIANT - (TREE_TYPE (TREE_TYPE (TREE_OPERAND (inner, 1)))))) + if (view_converted_memref_p (inner)) { tree alias_ptrtype = TREE_TYPE (TREE_OPERAND (inner, 1)); /* Unless we have the (aggregate) effective type of the access diff --git a/gcc/alias.h b/gcc/alias.h index f8d93e8b5f4..36095f0bf73 100644 --- a/gcc/alias.h +++ b/gcc/alias.h @@ -41,6 +41,7 @@ bool alias_ptr_types_compatible_p (tree, tree); int compare_base_decls (tree, tree); bool refs_same_for_tbaa_p (tree, tree); bool mems_same_for_tbaa_p (rtx, rtx); +bool view_converted_memref_p (tree); /* This alias set can be used to force a memory to conflict with all other memories, creating a barrier across which no memory reference diff --git a/gcc/tree-ssa-alias.cc b/gcc/tree-ssa-alias.cc index e7c1c1aa624..632cf78028b 100644 --- a/gcc/tree-ssa-alias.cc +++ b/gcc/tree-ssa-alias.cc @@ -2044,7 +2044,7 @@ decl_refs_may_alias_p (tree ref1, tree base1, which is done by ao_ref_base and thus one extra walk of handled components is needed. */ -static bool +bool view_converted_memref_p (tree base) { if (TREE_CODE (base) != MEM_REF && TREE_CODE (base) != TARGET_MEM_REF) @@ -4325,8 +4325,8 @@ ao_compare::compare_ao_refs (ao_ref *ref1, ao_ref *ref2, else if ((end_struct_ref1 != NULL) != (end_struct_ref2 != NULL)) return flags | ACCESS_PATH; if (end_struct_ref1 - && TYPE_MAIN_VARIANT (TREE_TYPE (end_struct_ref1)) - != TYPE_MAIN_VARIANT (TREE_TYPE (end_struct_ref2))) + && same_type_for_tbaa (TREE_TYPE (end_struct_ref1), + TREE_TYPE (end_struct_ref2)) != 1) return flags | ACCESS_PATH; /* Now compare all handled components of the access path.