From patchwork Thu Apr 7 11:26:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 52700 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9689C3858418 for ; Thu, 7 Apr 2022 11:26:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9689C3858418 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1649330811; bh=JXn0hcovPj45Bk0gHdDZ8ayng3BJ7ana88p39fyxZ1U=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=EGO2kAe8SBZL04b/gjJ1DIUyRhRctZhNybSmD++i9N0w+/GjCsbaUt3PwtjVB5IyK CdoKa8aG9WCqKkN2BqIuAVnrdt1Ll7oXQa+chfi8kXQ6Mqe9E2cCCg2vdHH2R02MTy p24lmT+Rfdyl+lWZ1dCD8eGhWhou+VbJ074cAX/4= 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 DD23C3858C50 for ; Thu, 7 Apr 2022 11:26:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DD23C3858C50 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id C25BB280BD6; Thu, 7 Apr 2022 13:26:21 +0200 (CEST) Date: Thu, 7 Apr 2022 13:26:21 +0200 To: gcc-patches@gcc.gnu.org, rguenther@suse.de Subject: Fix wrong code in gnatmake Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jan Hubicka via Gcc-patches From: Jan Hubicka Reply-To: Jan Hubicka Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi, this patch fixes miscompilation of gnatmake. Modref attempts to track memory accesses relative to the base pointers which are parameters of functions. If it fails, it still makes difference between unknown memory access and global memory access. The second makes it possible to disambiguate with memory that is not accessible from outside world (i.e. everything that does not escape from the caller function). This is useful so we do not punt when unknown function is called. Now I added ref_may_access_global_memory_p to tree-ssa-alias whic is using ptr_deref_may_alias_global_p. There is however a shift in meaning of this predicate: the second tests that the dereference may alias with global variable. In the testcase we are disambiguating heap allocated escaping memory which is not a global variable but it is still a global memory in the modref's sense. So we need to test in addition contains_escaped. The patch simply copies logic from the predicate and adds the check. I am not sure if there is better way to handle this? I apologize for taking so long time to look into the PR (and other my bugs). Will try to handle them quickly now. Bootstrapped/regtested x86_64-linux. Honza gcc/ChangeLog: 2022-04-07 Jan Hubicka PR 104303 * tree-ssa-alias.cc (ref_may_access_global_memory_p): Fix handling of refs. diff --git a/gcc/tree-ssa-alias.cc b/gcc/tree-ssa-alias.cc index 50bd47b31f3..9e34f76c3cb 100644 --- a/gcc/tree-ssa-alias.cc +++ b/gcc/tree-ssa-alias.cc @@ -2578,8 +2578,24 @@ ref_may_access_global_memory_p (ao_ref *ref) if (TREE_CODE (base) == MEM_REF || TREE_CODE (base) == TARGET_MEM_REF) { - if (ptr_deref_may_alias_global_p (TREE_OPERAND (base, 0))) + struct ptr_info_def *pi; + tree ptr = TREE_OPERAND (base, 0); + + /* If we end up with a pointer constant here that may point + to global memory. */ + if (TREE_CODE (ptr) != SSA_NAME) + return true; + + pi = SSA_NAME_PTR_INFO (ptr); + + /* If we do not have points-to information for this variable, + we have to punt. */ + if (!pi) return true; + + /* ??? This does not use TBAA to prune globals ptr may not access. */ + return pt_solution_includes_global (&pi->pt) + || pi->pt.vars_contains_escaped; } else {