From patchwork Wed Aug 21 17:23:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: kamlesh kumar X-Patchwork-Id: 1150996 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-507462-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="qtsiyvko"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="cg99PxCL"; 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 46DF0D1JN2z9s3Z for ; Thu, 22 Aug 2019 03:24:42 +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 :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=bMo7mw+QXF7IIOfDLPMhY5GhJephNyWPJjytgsqf4gNNQS IKiygopjh3h8gAbyrPl7SbSprbxE0ApORaiAEJoj9LpO7dC8mZP3Z8oyTxnUfMGO PDmQmggBzsteWCgYA/owC1AU6eok7UqMmqz/HcoguWiTyr81SVrkiSHo74olc= 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=3Jlq+sGVvnw0V+6U+evp6Qj1DnI=; b=qtsiyvko9aWH9kH1ejoN V+Bz/Ez98/Ehysg75RhYCc+PpuCqjjcT2/Vf9fh3GRmsV0a5e1XIJKv5qlWFLq1y NZ0OE+gboFkWjbi0S3UjltcaPQNx4dEFrMeOXPjQSesHjIc89bD6k3xv9I8fDkan l3Y6oDzuACa9n1g1QwAb4ZA= Received: (qmail 103265 invoked by alias); 21 Aug 2019 17:24:32 -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 103168 invoked by uid 89); 21 Aug 2019 17:24:15 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.3 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=Kumar, kumar, HTo:U*rguenth, il X-HELO: mail-io1-f50.google.com Received: from mail-io1-f50.google.com (HELO mail-io1-f50.google.com) (209.85.166.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 21 Aug 2019 17:24:13 +0000 Received: by mail-io1-f50.google.com with SMTP id 18so6108678ioe.10; Wed, 21 Aug 2019 10:24:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=CaV3geyTLDe7vuKVdOO4sOPqvQdNDi4iHNvRkfSZsW8=; b=cg99PxCL+24t8EU9wRC0Z/q4RChvag7w/99RyRK1AAOU+FmReIhD3vvbf8/+vM6Dm6 00N6i7s5AIrR1VabH5xarv7r+HoVsmTKdh4+wQbvuMLXLU3nycQkPA0IiGSBYcrrzrZD pb/b4XQSsLgNe8DJ3aS6uslF2+TPh+BFAToeL6MWubC7kO9lZLSklRu7Nnm0jIj+YqnY qEpaZpvWkwnI+jmLfOj/B7aZ8jLWyBcY5p3EbfuiGsq+8HZE/JhfXOlG/R9UdyhH1ozB 4GraiHJq4BbBt/EtRYnVRWwNCsNcZ5CMB7Yw+Gn6N0yETMEh0+i8l7Aaxw0iKucnjveL NYJg== MIME-Version: 1.0 From: kamlesh kumar Date: Wed, 21 Aug 2019 22:53:50 +0530 Message-ID: Subject: [PATCH] [PR81810] unused strcpy to a local buffer not eliminated To: gcc-patches@gcc.gnu.org, rguenth@gcc.gnu.org X-IsSubscribed: yes Hi , This patch include fix for PR81810 Bootstrapped/regtested on x86_64-linux, ok for trunk? Thanks ./Kamlesh 2019-08-21 Kamlesh Kumar PR tree-optimization/81810 * tree-ssa-dse.c (dse_dom_walker::dse_optimize_stmt): Added BUILT_IN_STRCPY to consider for dse. (maybe_trim_memstar_call): Likewise. (initialize_ao_ref_for_dse): Likewise. * gcc.dg/tree-ssa/pr81810.c: New testcase. diff --git a/gcc/tree-ssa-dse.c b/gcc/tree-ssa-dse.c index ba67884a825..dc4da4c9730 100644 --- a/gcc/tree-ssa-dse.c +++ b/gcc/tree-ssa-dse.c @@ -115,8 +115,11 @@ initialize_ao_ref_for_dse (gimple *stmt, ao_ref *write) case BUILT_IN_MEMSET_CHK: case BUILT_IN_STRNCPY: case BUILT_IN_STRNCPY_CHK: + case BUILT_IN_STRCPY: { - tree size = gimple_call_arg (stmt, 2); + tree size = NULL; + if (gimple_call_num_args (stmt) > 2) + size = gimple_call_arg (stmt, 2); tree ptr = gimple_call_arg (stmt, 0); ao_ref_init_from_ptr_and_size (write, ptr, size); return true; @@ -470,6 +473,7 @@ 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: case BUILT_IN_MEMCPY_CHK: case BUILT_IN_MEMMOVE_CHK: case BUILT_IN_STRNCPY_CHK: @@ -966,6 +970,7 @@ dse_dom_walker::dse_optimize_stmt (gimple_stmt_iterator *gsi) case BUILT_IN_MEMCPY: case BUILT_IN_MEMMOVE: case BUILT_IN_STRNCPY: + case BUILT_IN_STRCPY: case BUILT_IN_MEMSET: case BUILT_IN_MEMCPY_CHK: case BUILT_IN_MEMMOVE_CHK: @@ -975,11 +980,14 @@ dse_dom_walker::dse_optimize_stmt (gimple_stmt_iterator *gsi) /* Occasionally calls with an explicit length of zero show up in the IL. It's pointless to do analysis on them, they're trivially dead. */ - tree size = gimple_call_arg (stmt, 2); - if (integer_zerop (size)) + if (gimple_call_num_args (stmt) > 2) { - delete_dead_or_redundant_call (gsi, "dead"); - return; + tree size = gimple_call_arg (stmt, 2); + if (integer_zerop (size)) + { + delete_dead_or_redundant_call (gsi, "dead"); + return; + } } /* If this is a memset call that initializes an object diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr81810.c b/gcc/testsuite/gcc.dg/tree-ssa/pr81810.c new file mode 100644 index 00000000000..89cf36a1367 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr81810.c @@ -0,0 +1,25 @@ +/* PR tree-optimization/81810 + { dg-do compile } + { dg-options "-O2 -fdump-tree-optimized" } */ + +void f (const void *p, unsigned n) +{ + char a[8]; + __builtin_memcpy (a, p, n); +} + +void g (const char *s) +{ + char a[8]; + __builtin_strcpy (a, s); +} + +void h (const char *s) +{ + char a[8]; + __builtin_strncpy (a, s, sizeof a); +} + +/* { dg-final { scan-tree-dump-not "__builtin_memcpy" "optimized" } } + { dg-final { scan-tree-dump-not "__builtin_strcpy" "optimized" } } + { dg-final { scan-tree-dump-not "__builtin_strncpy" "optimized" } } */