From patchwork Thu May 16 13:35:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 1936011 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=r0jJX3bz; 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 4VgB1B2JNPz1yfq for ; Thu, 16 May 2024 23:35:26 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 79B1C384CB97 for ; Thu, 16 May 2024 13:35:24 +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 227A93858D38 for ; Thu, 16 May 2024 13:35:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 227A93858D38 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 227A93858D38 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=1715866509; cv=none; b=rxJK5YOeoZs8/cKPuM12mwQbm8RmpGSBQ8kishEXLTjjbMA44ZUEmlo0kO91fqOhh4+/Pato5hl2wQs6azqJRwWsI7LC0SVBul1AQLoOZZtVDhv7FQmgn+fo0jzPIuBTlTEbtLulgdT4Mo04OPSqAq5JzGQ9g/4+6ujMcA7q0sU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715866509; c=relaxed/simple; bh=DYeRouwGbUL0tN/Gn8oCqMVG/22ICLaAeI8TtkXJ8aA=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=t2QmGNO2vOIidQGnfOgfRiM9k/ZUo/xcPhUyF1TFz/kObS4tM8NFIansbzD2Jqo8XMX+Tt+Gkz07izr4FAQvHJ8eBriGh6uwTu/GdbtFo69Df3U5t85gyRUg+bN/frb+X9Rc59eZkkTFvPLM9CvGI7OL4uGVOv48e7ePAbVAAh8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 8806228707E; Thu, 16 May 2024 15:35:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ucw.cz; s=gen1; t=1715866504; 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=WfcqD+zLP6KwYmPulziIcioEy1PicAz97DuXf8PsgNo=; b=r0jJX3bz4fq2BMNmRapxIG0gmriv6t5kfgW6r+n0+wm1mI0bT4lwiHPZDfmW6KXm8TAnMY MLgo4T6kQ/wWQVfz7iBzQo05Tk8vGW4LFVXYz/SKdvVlqAqUP57n9ChvcJgB7J/8Q07zaY CxWQzrMQk8d+6JCDN7iJuoZ4TCuwcGw= Date: Thu, 16 May 2024 15:35:04 +0200 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Fix points_to_local_or_readonly_memory_p wrt TARGET_MEM_REF 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, TARGET_MEM_REF can be used to offset constant base into a memory object (to produce lea instruction). This confuses points_to_local_or_readonly_memory_p which treats the constant address as a base of the access. Bootstrapped/regtsted x86_64-linux, comitted. Honza gcc/ChangeLog: PR ipa/113787 * ipa-fnsummary.cc (points_to_local_or_readonly_memory_p): Do not look into TARGET_MEM_REFS with constant opreand 0. gcc/testsuite/ChangeLog: * gcc.c-torture/execute/pr113787.c: New test. diff --git a/gcc/ipa-fnsummary.cc b/gcc/ipa-fnsummary.cc index 07a853f78e3..2faf2389297 100644 --- a/gcc/ipa-fnsummary.cc +++ b/gcc/ipa-fnsummary.cc @@ -2648,7 +2648,9 @@ points_to_local_or_readonly_memory_p (tree t) return true; return !ptr_deref_may_alias_global_p (t, false); } - if (TREE_CODE (t) == ADDR_EXPR) + if (TREE_CODE (t) == ADDR_EXPR + && (TREE_CODE (TREE_OPERAND (t, 0)) != TARGET_MEM_REF + || TREE_CODE (TREE_OPERAND (TREE_OPERAND (t, 0), 0)) != INTEGER_CST)) return refs_local_or_readonly_memory_p (TREE_OPERAND (t, 0)); return false; } diff --git a/gcc/testsuite/gcc.c-torture/execute/pr113787.c b/gcc/testsuite/gcc.c-torture/execute/pr113787.c new file mode 100644 index 00000000000..702b6c35fc6 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr113787.c @@ -0,0 +1,38 @@ +void foo(int x, int y, int z, int d, int *buf) +{ + for(int i = z; i < y-z; ++i) + for(int j = 0; j < d; ++j) + /* buf[x(i+1) + j] = buf[x(i+1)-j-1] */ + buf[i*x+(x-z+j)] = buf[i*x+(x-z-1-j)]; +} + +void bar(int x, int y, int z, int d, int *buf) +{ + for(int i = 0; i < d; ++i) + for(int j = z; j < x-z; ++j) + /* buf[j+(y+i)*x] = buf[j+(y-1-i)*x] */ + buf[j+(y-z+i)*x] = buf[j+(y-z-1-i)*x]; +} + +__attribute__((noipa)) +void baz(int x, int y, int d, int *buf) +{ + foo(x, y, 0, d, buf); + bar(x, y, 0, d, buf); +} + +int main(void) +{ + int a[] = { 1, 2, 3 }; + baz (1, 2, 1, a); + /* foo does: + buf[1] = buf[0]; + buf[2] = buf[1]; + + bar does: + buf[2] = buf[1]; (no-op) + so we should have { 1, 1, 1 }. */ + for (int i = 0; i < 3; i++) + if (a[i] != 1) + __builtin_abort (); +}