From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1725) id B03C23950CB9; Fri, 28 Aug 2020 20:03:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B03C23950CB9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1598645034; bh=Yc2eOhEoYfVX3u/CEGCclQ9iNwKh35a4i9pqMvg2qis=; h=From:To:Subject:Date:From; b=X/4jl1sgSpFY9JBlYdqfgkgdwCrBMuNsQ9mKjgCwqZZEefBndOsJYHZoV0xsAOaq0 7JCPSA7ldEvuaLOVmdr0Wsv6+xGcRdldLIU2aXSfJKz3WRiG++cWqVcSzOiKOgML55 QOqCEMGcITriqtBg947sblNMUx2fXDWbpFI5gyXg= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: William Schmidt To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/wschmidt/heads/builtins3)] tree-optimization/96565 - improve DSE with paths ending in noreturn X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/users/wschmidt/heads/builtins3 X-Git-Oldrev: 3ae0cd94abc15e33dc06ca7a5f76f14b1d74129f X-Git-Newrev: 989bc4ca2f2978baecff00f6d0532994b82897ef Message-Id: <20200828200354.B03C23950CB9@sourceware.org> Date: Fri, 28 Aug 2020 20:03:54 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Aug 2020 20:03:54 -0000 https://gcc.gnu.org/g:989bc4ca2f2978baecff00f6d0532994b82897ef commit 989bc4ca2f2978baecff00f6d0532994b82897ef Author: Richard Biener Date: Wed Aug 26 08:44:59 2020 +0200 tree-optimization/96565 - improve DSE with paths ending in noreturn This improves DSEs stmt walking by not considering a DEF without uses for further processing (and thus giving up when there's two paths to follow). 2020-08-26 Richard Biener PR tree-optimization/96565 * tree-ssa-dse.c (dse_classify_store): Remove defs with no uses from further processing. * gcc.dg/tree-ssa/ssa-dse-40.c: New testcase. * gcc.dg/builtin-object-size-4.c: Adjust. Diff: --- gcc/testsuite/gcc.dg/builtin-object-size-4.c | 3 +++ gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-40.c | 16 ++++++++++++++++ gcc/tree-ssa-dse.c | 11 +++++++++++ 3 files changed, 30 insertions(+) diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-4.c b/gcc/testsuite/gcc.dg/builtin-object-size-4.c index c22654dea2a..9f159e36a0f 100644 --- a/gcc/testsuite/gcc.dg/builtin-object-size-4.c +++ b/gcc/testsuite/gcc.dg/builtin-object-size-4.c @@ -170,6 +170,9 @@ test1 (void *q, int x) r = (char *) L"abcd\0efg"; if (__builtin_object_size (r + 2, 3) != sizeof (L"abcd\0efg") - 2) abort (); + /* Prevent DSE from removing calls that prevent bad combining of + addresses and offsets. */ + asm volatile ("" : : "g" (&a)); } size_t l1 = 1; diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-40.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-40.c new file mode 100644 index 00000000000..36f69c05d5b --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-40.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-dse1-details" } */ + +_Bool g(void); + +void f(int x) +{ + char arr[x]; + + arr[0] = 0; + + if (g()) + __builtin_abort(); +} + +/* { dg-final { scan-tree-dump "Deleted dead store" "dse1" } } */ diff --git a/gcc/tree-ssa-dse.c b/gcc/tree-ssa-dse.c index cc93f559286..76eed06f17f 100644 --- a/gcc/tree-ssa-dse.c +++ b/gcc/tree-ssa-dse.c @@ -898,6 +898,17 @@ dse_classify_store (ao_ref *ref, gimple *stmt, *by_clobber_p = false; defs.unordered_remove (i); } + /* If the path ends here we do not need to process it further. + This for example happens with calls to noreturn functions. */ + else if (gimple_code (def) != GIMPLE_PHI + && has_zero_uses (gimple_vdef (def))) + { + /* But if the store is to global memory it is definitely + not dead. */ + if (ref_may_alias_global_p (ref)) + return DSE_STORE_LIVE; + defs.unordered_remove (i); + } /* In addition to kills we can remove defs whose only use is another def in defs. That can only ever be PHIs of which we track a single for simplicity reasons (we fail for multiple