From patchwork Thu Jun 20 22:23:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 1119846 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-503408-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="dJLPHw0L"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45VGZM6LZ9z9s7h for ; Fri, 21 Jun 2019 08:24:11 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:message-id:date:mime-version:content-type; q=dns; s= default; b=SskKbwchEFGRkfHNHW7NYls1ouS+1NFfcyrBgF3Ak6CFKnSZR8+AJ vf35Cp1HkvjdrHEOMY2AOtAbF9U03+bmbUd87jjXd0bEcy9ERX850DEDCfJtk8pJ cw6KoSUEdP1d6bH4k56ds7LRYbnlI0H3o8eNlOw6vnEmSkgW9OxGk4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:message-id:date:mime-version:content-type; s= default; bh=3LXhlj0Y0/fByl/JAFLHBvbXRm8=; b=dJLPHw0LuflDVEaOBw9y U11KItz1Q+IpdoOw0flc/sJVbC23R9mvpOnI2dlcV3YiR4Dnias6W18bfhz4Q1tF 8iOK4iTnjNzxFLQtAvA8Sn3oCb5lrJkuUw7fZCmE2+lie0YHob25Q+qWE3bhODI9 A8dlAXwujPgmQwp5/RlkTtM= Received: (qmail 108623 invoked by alias); 20 Jun 2019 22:24:02 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 108603 invoked by uid 89); 20 Jun 2019 22:24:02 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-14.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 20 Jun 2019 22:24:00 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A00A2308339E for ; Thu, 20 Jun 2019 22:23:59 +0000 (UTC) Received: from localhost.localdomain (ovpn-112-72.rdu2.redhat.com [10.10.112.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 612845D71D for ; Thu, 20 Jun 2019 22:23:58 +0000 (UTC) From: Jeff Law Openpgp: preference=signencrypt To: gcc-patches Subject: [RFA] [PR tree-optimization/90949] Don't propagate context sensitive non-nullness when copy-propagating pointers Message-ID: <076d995d-533a-8648-e9c8-5527907329da@redhat.com> Date: Thu, 20 Jun 2019 16:23:57 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 X-IsSubscribed: yes As outlined in the BZ, our alias analysis code is context insensitive. So when we copy-propagate pointers, we can can and do copy PTA information from members to the representative pointer in the copy-of chain (we do this when the representative pointer has no associated PTA information). However, [E]VRP can set the non-nullness of a pointer using context sensitive information. So we have to be more careful when copying PTA information. We already have similar issues with alignment information as well. This patch just extends the hack to avoid copying alignment information in some circumstances to also avoid copying the non-nullness property. Bootstrapped and regression tested on x86_64-linux-gnu. OK for the trunk? Jeff * tree-ssa-copy.c (fini_copy_prop): Call clear_ptr_nonnull as needed. * tree-ssanames.c (clear_ptr_nonnull): New function. * tree-ssanames.h (clear_ptr_nonnull): Declare. * gcc.c-torture/execute/pr90949.c: New test. diff --git a/gcc/testsuite/gcc.c-torture/execute/pr90949.c b/gcc/testsuite/gcc.c-torture/execute/pr90949.c new file mode 100644 index 00000000000..12ae31d97a5 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr90949.c @@ -0,0 +1,33 @@ +void __attribute__((noipa,noinline)) my_puts (const char *str) { } +void __attribute__((noipa,noinline)) my_free (void *p) { } + + +struct Node +{ + struct Node* child; +}; + +char *space[sizeof (struct Node) * 2] = { }; + +void * __attribute__((noipa,noinline)) my_malloc (int bytes) { return &space;} + +void walk(struct Node* module, int cleanup) +{ + if (module == 0) { + return; + } + if (!cleanup) { + my_puts("No cleanup"); + } + walk(module->child, cleanup); + if (cleanup) { + my_free(module); + } +} + +int main() +{ + struct Node* node = my_malloc(sizeof(struct Node)); + node->child = 0; + walk(node, 1); +} diff --git a/gcc/tree-ssa-copy.c b/gcc/tree-ssa-copy.c index 89532633e42..ccb95bf18b7 100644 --- a/gcc/tree-ssa-copy.c +++ b/gcc/tree-ssa-copy.c @@ -548,10 +548,28 @@ fini_copy_prop (void) but alignment info might be cfg sensitive, if it e.g. is derived from VRP derived non-zero bits. So, do not copy alignment info if the two SSA_NAMEs - aren't defined in the same basic block. */ + aren't defined in the same basic block. + + Similarly, we may have a context sensitive non-NULL + state for an SSA_NAME (call it A), which in turn is + used to derive a global non-NULL state for a different + SSA_NAME (call it B) via a PHI node. + + That PHI node also represents a copy which we will try + to eliminate here. We will copy the alias info to the + representative element in the copy-of chains. If A is + the representative element, then we just made A globally + non-NULL which is incorrect. + + Arguably one might claim this is too fragile and that we + should never dupicate the points-to information if the + objects are in different blocks. */ if (var_bb != copy_of_bb) - mark_ptr_info_alignment_unknown - (SSA_NAME_PTR_INFO (copy_of[i].value)); + { + mark_ptr_info_alignment_unknown + (SSA_NAME_PTR_INFO (copy_of[i].value)); + clear_ptr_nonnull (copy_of[i].value); + } } else if (!POINTER_TYPE_P (TREE_TYPE (var)) && SSA_NAME_RANGE_INFO (var) diff --git a/gcc/tree-ssanames.c b/gcc/tree-ssanames.c index 5bac799e9a3..2114a9584ba 100644 --- a/gcc/tree-ssanames.c +++ b/gcc/tree-ssanames.c @@ -451,6 +451,16 @@ get_range_info (const_tree name, value_range_base &vr) return kind; } +/* Clear nonnull attribute to pointer NAME. */ + +void +clear_ptr_nonnull (tree name) +{ + gcc_assert (POINTER_TYPE_P (TREE_TYPE (name))); + struct ptr_info_def *pi = get_ptr_info (name); + pi->pt.null = 1; +} + /* Set nonnull attribute to pointer NAME. */ void diff --git a/gcc/tree-ssanames.h b/gcc/tree-ssanames.h index 6e6cffbce6a..6470d491deb 100644 --- a/gcc/tree-ssanames.h +++ b/gcc/tree-ssanames.h @@ -91,6 +91,7 @@ extern void set_ptr_info_alignment (struct ptr_info_def *, unsigned int, extern void adjust_ptr_info_misalignment (struct ptr_info_def *, poly_uint64); extern struct ptr_info_def *get_ptr_info (tree); extern void set_ptr_nonnull (tree); +extern void clear_ptr_nonnull (tree); extern bool get_ptr_nonnull (const_tree); extern tree copy_ssa_name_fn (struct function *, tree, gimple *);