From patchwork Tue Feb 28 10:03:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 94605 Delivered-To: patch@linaro.org Received: by 10.140.20.113 with SMTP id 104csp1247515qgi; Tue, 28 Feb 2017 02:03:30 -0800 (PST) X-Received: by 10.99.1.20 with SMTP id 20mr1706115pgb.53.1488276210353; Tue, 28 Feb 2017 02:03:30 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id p24si1343039pli.285.2017.02.28.02.03.30 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Feb 2017 02:03:30 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-449224-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-449224-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-449224-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=c1rgGwvI6shLPsz+luXm+xnzAsPBnK1ewB+rQr7B+u/wI6 UfC188Oe/u+QmR3np2YXmUa6IW8Vb+TTataGA8aiHvoKucxO+d9MdOrURLs8PbcG 4fJUc0iUjsYvjzY8gktFiSgqj1UngDelPoYw71VFa5L+xFoRIem3aKcvsCH+A= 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 :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=+C7WFcLDp+szUg+2gLup5bLfxv8=; b=OB2Iu/26h1+P8l9kC7yI NSkT2KrAWVPGJZQnGTQA2SSrC7mHteA2Q8kKY4CAiti3asg+TPO9hZkl1/jHk6ow K4+9EhdfQDL06aWLCqDx8XJR2m0gduecY/2/b/Oc19V4Q7TqZcWvJeuhWhBFVwGJ Rb9vQi1yzozcb+6CimGiGQo= Received: (qmail 50446 invoked by alias); 28 Feb 2017 10:03:15 -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 50426 invoked by uid 89); 28 Feb 2017 10:03:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-it0-f42.google.com Received: from mail-it0-f42.google.com (HELO mail-it0-f42.google.com) (209.85.214.42) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 28 Feb 2017 10:03:13 +0000 Received: by mail-it0-f42.google.com with SMTP id y135so6069466itc.1 for ; Tue, 28 Feb 2017 02:03:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=07vkQDOlS52b0ygNlgHf1XAx1z97Lk/lU48zJBPp/3k=; b=paJ9XpABnuhEQ58m1sxRtd12c1RCaGLBXoO2+TmAX/2zQS7OxL/ldbmMXxaF3o9uxu 5Ac8kBLus7Wdp3e4vYSEVDLkQWA30hUBEDLjnMRQZDOKLPBymIY9gWTiBipI2UiNG3u2 duxGyxgq+did8eDTfcDgnSSLOo5sGQ8aQnVdhmcD4vOPYV9ah/6H9qsZ6Zj4Iq8ijanm uhGahd+9VdE+Ub/FxA8F3rNZ4GK+jzeAm+tV1sPzMa4cd80sPxUwDtA32Lf32N/3IbuY KuGQHDVJb7kaxd1KvgYKvN0xboDoqQP1QfsnLWe92y4phxNvNbshnW2QzKiv1ve3r7B0 rW7w== X-Gm-Message-State: AMke39lzfj4JVNVfZngySZwkwHCMbSC+YsjBQEeNaAf6zYFDHhFmfiY2q3B1NcH2Vj0sWYxWjv92xTEvnc3UR6Zm X-Received: by 10.36.53.210 with SMTP id k201mr1611879ita.21.1488276192710; Tue, 28 Feb 2017 02:03:12 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.162.13 with HTTP; Tue, 28 Feb 2017 02:03:11 -0800 (PST) From: Prathamesh Kulkarni Date: Tue, 28 Feb 2017 15:33:11 +0530 Message-ID: Subject: PR79715: Special case strcpy/strncpy for dse To: gcc Patches , Richard Biener , Martin Sebor X-IsSubscribed: yes Hi, The attached patch adds special-casing for strcpy/strncpy to dse pass. Bootstrapped+tested on x86_64-unknown-linux-gnu. OK for GCC 8 ? Thanks, Prathamesh diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr79715.c b/gcc/testsuite/gcc.dg/tree-ssa/pr79715.c new file mode 100644 index 0000000..1a832ca --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr79715.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-dse-details" } */ + +void f(const char *s) +{ + unsigned n = __builtin_strlen (s) + 1; + char *p = __builtin_malloc (n); + __builtin_strcpy (p, s); + __builtin_free (p); +} + +/* { dg-final { scan-tree-dump "Deleted dead call: __builtin_strcpy" "dse1" } } */ diff --git a/gcc/tree-ssa-dse.c b/gcc/tree-ssa-dse.c index 53feaf3..6d3c3c3 100644 --- a/gcc/tree-ssa-dse.c +++ b/gcc/tree-ssa-dse.c @@ -97,6 +97,8 @@ initialize_ao_ref_for_dse (gimple *stmt, ao_ref *write) case BUILT_IN_MEMCPY: case BUILT_IN_MEMMOVE: case BUILT_IN_MEMSET: + case BUILT_IN_STRNCPY: + case BUILT_IN_STRCPY: { tree size = NULL_TREE; if (gimple_call_num_args (stmt) == 3) @@ -395,6 +397,8 @@ maybe_trim_memstar_call (ao_ref *ref, sbitmap live, gimple *stmt) { case BUILT_IN_MEMCPY: case BUILT_IN_MEMMOVE: + case BUILT_IN_STRNCPY: + case BUILT_IN_STRCPY: { int head_trim, tail_trim; compute_trims (ref, live, &head_trim, &tail_trim, stmt); @@ -713,6 +717,7 @@ dse_dom_walker::dse_optimize_stmt (gimple_stmt_iterator *gsi) case BUILT_IN_MEMCPY: case BUILT_IN_MEMMOVE: case BUILT_IN_MEMSET: + case BUILT_IN_STRNCPY: { /* Occasionally calls with an explicit length of zero show up in the IL. It's pointless to do analysis @@ -723,7 +728,10 @@ dse_dom_walker::dse_optimize_stmt (gimple_stmt_iterator *gsi) delete_dead_call (gsi); return; } - + } + /* fallthru */ + case BUILT_IN_STRCPY: + { gimple *use_stmt; enum dse_store_status store_status; m_byte_tracking_enabled