From patchwork Sat Nov 13 00:52:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 47582 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 213E73858435 for ; Sat, 13 Nov 2021 00:53:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 213E73858435 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636764817; bh=PCOXZJJFJMiSQRrQAsWrzDscHLBZ2/j3SmyCuDzvrzw=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=I3bXAvmmMlqNPddG9ZoReszsEn30s6S8fUUxKf2PdMumRKoFReu0k+0QUMUYmAbwM G7JqDlfexBsuNT4cZlJGV4hXWKYHhnAG4OfXMoMQlteJXSg2sd/OqBBLPh53LjnIVc zB6n8pOLC9ZD6Hd/+O2WT/ceAQhzwuHuvsJhHtFg= 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 7C8783858024 for ; Sat, 13 Nov 2021 00:52:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7C8783858024 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 7228A280898; Sat, 13 Nov 2021 01:52:06 +0100 (CET) Date: Sat, 13 Nov 2021 01:52:06 +0100 To: gcc-patches@gcc.gnu.org Subject: Fix modref and hadnling of some builtins Message-ID: <20211113005206.GA15769@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-11.8 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 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, ipa-modref gets confused by EAF flags of memcpy becuase parameter 1 is escaping but used only directly. In modref we do not track values saved to memory and thus we clear all other flags on each store. This needs to also happen when called function escapes parameter. gcc/ChangeLog: PR tree-optimization/103182 * ipa-modref.c (callee_to_caller_flags): Fix merging of flags. (modref_eaf_analysis::analyze_ssa_name): Fix merging of flags. diff --git a/gcc/ipa-modref.c b/gcc/ipa-modref.c index e999c2c5d1e..90985cc1326 100644 --- a/gcc/ipa-modref.c +++ b/gcc/ipa-modref.c @@ -1888,19 +1888,18 @@ callee_to_caller_flags (int call_flags, bool ignore_stores, that is not the same as caller returning it. */ call_flags |= EAF_NOT_RETURNED_DIRECTLY | EAF_NOT_RETURNED_INDIRECTLY; - /* TODO: We miss return value propagation. - Be conservative and if value escapes to memory - also mark it as escaping. */ if (!ignore_stores && !(call_flags & EAF_UNUSED)) { + /* If value escapes we are no longer able to track what happens + with it because we can read it from the escaped location + anytime. */ if (!(call_flags & EAF_NO_DIRECT_ESCAPE)) - lattice.merge (~(EAF_NOT_RETURNED_DIRECTLY - | EAF_NOT_RETURNED_INDIRECTLY - | EAF_NO_DIRECT_READ - | EAF_UNUSED)); - if (!(call_flags & EAF_NO_INDIRECT_ESCAPE)) + lattice.merge (0); + else if (!(call_flags & EAF_NO_INDIRECT_ESCAPE)) lattice.merge (~(EAF_NOT_RETURNED_INDIRECTLY | EAF_NO_DIRECT_READ + | EAF_NO_INDIRECT_READ + | EAF_NO_INDIRECT_CLOBBER | EAF_UNUSED)); } else @@ -2036,18 +2035,17 @@ modref_eaf_analysis::analyze_ssa_name (tree name) not_returned and escape has same meaning. However passing arg to return slot is different. If the callee's return slot is returned it means that - arg is written to itself which is an escape. */ + arg is written to itself which is an escape. + Since we do not track the memory it is written to we + need to give up on analysisng it. */ if (!isretslot) { if (!(call_flags & (EAF_NOT_RETURNED_DIRECTLY | EAF_UNUSED))) - m_lattice[index].merge (~(EAF_NO_DIRECT_ESCAPE - | EAF_UNUSED)); - if (!(call_flags & (EAF_NOT_RETURNED_INDIRECTLY - | EAF_UNUSED))) - m_lattice[index].merge (~(EAF_NO_INDIRECT_ESCAPE - | EAF_NO_DIRECT_READ - | EAF_UNUSED)); + m_lattice[index].merge (0); + else gcc_checking_assert + (call_flags & (EAF_NOT_RETURNED_INDIRECTLY + | EAF_UNUSED)); call_flags = callee_to_caller_flags (call_flags, false, m_lattice[index]);