From patchwork Fri Nov 12 23:01:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 47580 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 2D1323858420 for ; Fri, 12 Nov 2021 23:02:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D1323858420 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636758125; bh=5QXh+nRX515Be7IAfw1rUlTcnOkk31vuGoMG2fznwO4=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Ab1VmXFvQbH5heQyHpZBKaXLmtn0bwBxxdO6UKH/+ibNgB7TXso3GhkKHHfFlm7Iy luDWIDaftSgC6uEcSHzml6/CEfnym4zjMcHui2f37uRNgbyeVzuRYXS1l8ntfAd/KE pZSGKK8p/XIBSOGHdL62w+j8lG3T1vZgWUyUQIhY= 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 7971E385840B for ; Fri, 12 Nov 2021 23:01:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7971E385840B Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 6F60B280898; Sat, 13 Nov 2021 00:01:34 +0100 (CET) Date: Sat, 13 Nov 2021 00:01:34 +0100 To: gcc-patches@gcc.gnu.org Subject: Fix wrong code with pure functions Message-ID: <20211112230134.GA97722@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" Fix wrong code with pure functions I introduced bug into find_func_aliases_for_call in handling pure functions. Instead of reading global memory pure functions are believed to write global memory. This results in misoptimization of the testcase at -O1. The change to pta-callused.c updates the template for new behaviour of the constraint generation. We copy nonlocal memory to calluse which is correct but also not strictly necessary because later we take care to add nonlocal_p flag manually. Bootstrapped/regtested x86_64-linux, comitted. gcc/ChangeLog: PR tree-optimization/103209 * tree-ssa-structalias.c (find_func_aliases_for_call): Fix use of handle_rhs_call gcc/testsuite/ChangeLog: PR tree-optimization/103209 * gcc.dg/tree-ssa/pta-callused.c: Update template. * gcc.c-torture/execute/pr103209.c: New test. diff --git a/gcc/testsuite/gcc.c-torture/execute/pr103209.c b/gcc/testsuite/gcc.c-torture/execute/pr103209.c new file mode 100644 index 00000000000..481689396f4 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr103209.c @@ -0,0 +1,36 @@ +#include +#include + +int32_t a[6]; +int64_t b; +int32_t *c; +int32_t **d = &c; +int64_t *e = &b; +int32_t **const *f = &d; +int32_t **const **g = &f; +int32_t *h(); +static int16_t j(); +static uint32_t k(int8_t, const int32_t *, int64_t); +static uint32_t l() { + int32_t *m = &a[3]; + int32_t n = 0; + int8_t o = 0; + int32_t *p[] = {&n, &n, &n, &n}; + uint32_t q[6][1][2] = {}; + for (o = 0; o <= 1; o = 6) + if (h(j(k(3, 0, q[2][0][0]), &n), n) == p[3]) + *m = *e; + return 0; +} +int32_t *h(uint32_t, int32_t) { return ***g; } +int16_t j(uint32_t, int32_t *r) { **f = r; return 0;} +uint32_t k(int8_t, const int32_t *, int64_t) { *e = 3; return 0;} +int main() { + int i = 0; + l(); + for (i = 0; i < 6; i++){ + if (i == 3 && a[i] != 3) + __builtin_abort (); + } + return 0; +} diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pta-callused.c b/gcc/testsuite/gcc.dg/tree-ssa/pta-callused.c index aa639b45dc2..b9a57d8d135 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/pta-callused.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/pta-callused.c @@ -22,5 +22,5 @@ int bar (int b) return *foo (&q); } -/* { dg-final { scan-tree-dump "CALLUSED\\(\[0-9\]+\\) = { NONLOCAL f.* i q }" "alias" } } */ +/* { dg-final { scan-tree-dump "CALLUSED\\(\[0-9\]+\\) = { ESCAPED NONLOCAL f.* i q }" "alias" } } */ diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c index 153ddf57a61..34fd47fdf47 100644 --- a/gcc/tree-ssa-structalias.c +++ b/gcc/tree-ssa-structalias.c @@ -4996,7 +4996,7 @@ find_func_aliases_for_call (struct function *fn, gcall *t) reachable from their arguments, but they are not an escape point for reachable memory of their arguments. */ else if (flags & (ECF_PURE|ECF_LOOPING_CONST_OR_PURE)) - handle_rhs_call (t, &rhsc, implicit_pure_eaf_flags, true, false); + handle_rhs_call (t, &rhsc, implicit_pure_eaf_flags, false, true); /* If the call is to a replaceable operator delete and results from a delete expression as opposed to a direct call to such operator, then the effects for PTA (in particular