From patchwork Sat Feb 25 08:40:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 94510 Delivered-To: patch@linaro.org Received: by 10.140.20.113 with SMTP id 104csp66055qgi; Sat, 25 Feb 2017 00:41:30 -0800 (PST) X-Received: by 10.98.79.150 with SMTP id f22mr8709066pfj.55.1488012090049; Sat, 25 Feb 2017 00:41:30 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id u14si9701181pfk.93.2017.02.25.00.41.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 Feb 2017 00:41:30 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-449124-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-449124-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-449124-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=iXYxwOzcZwMXGcEiZKhnc3yMvsfs/zriOZSCJoXBFUOR0W eWiJpkQpbMSN2VEyUp62Zf0p2U63zUWSZsOVNN7hZfFIZmrX43up2ao3ARfJeSEz nzvmFua6QZcq88IAybH++WGofK5rJlwqVSi1bWS3BfHq4W5OTs+xOal90/32I= 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=H7ro5t1uxuo0RcjPHH+uZhaFmgU=; b=rNJYj739w8w1kKBOY9bI WZrV9bh+CjJlaHhkSXuzM3rqTYwHdrumOTfW6xv2EAm704w5RKwhe5efmi8grV8e O/PhfJib2tWZ9xdz/PVTpkD2uEKlsgZJ9QF0JY11D66M0NfPx/wZwj2mUHrQTIGy 1Ibc5lVRq9gZzWChXcfkXX8= Received: (qmail 11137 invoked by alias); 25 Feb 2017 08:41:12 -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 10722 invoked by uid 89); 25 Feb 2017 08:41:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-io0-f176.google.com Received: from mail-io0-f176.google.com (HELO mail-io0-f176.google.com) (209.85.223.176) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 25 Feb 2017 08:41:00 +0000 Received: by mail-io0-f176.google.com with SMTP id g18so7344508ioe.0 for ; Sat, 25 Feb 2017 00:41:00 -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=39RQMlK3OQrb8QZNSxrFVUvO/l+GiQacan5YD+95MtU=; b=eB6fBZ3NrXKXGPU7e4Go/fJaL9Qjt4TfXqNZ4DkNWBZ9qmD+yJeXgugWpWbtWoQz5m XtrDWq6KDmL8u5bBShxQd7GDr4lx0VLY6Pgz/Y/fiOGtPtOGUrTFyUd/GWBpCRD40alp 2SE5a1VgdINCvSyneRzZ5Po0aKkaz8aJsIR6ahX6T075UBT/wXEIIvPfmr97vHRwOIDn UsDcAbaUXEOpPTnYI+fGXH9EoApZ6lyOs1m9Fpkdajx2doEGh2rk8Qlb2QxujHDjwE43 e8wvv8kXtW5fl7PitmwW3gSaL4J9Z7dhglrVMh1VeWjqSqT0ziVL5WTIxC6tdSMmNaUh AnBA== X-Gm-Message-State: AMke39l8WQwPb2gsVOeo4kWaGHwz6ipfkfxgyrjlhEJkLDUXMVsFhgClD8CEdINRJ8igvG77cz1OAUDRSksap7Sn X-Received: by 10.107.14.78 with SMTP id 75mr5870535ioo.76.1488012058749; Sat, 25 Feb 2017 00:40:58 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.162.13 with HTTP; Sat, 25 Feb 2017 00:40:58 -0800 (PST) From: Prathamesh Kulkarni Date: Sat, 25 Feb 2017 14:10:58 +0530 Message-ID: Subject: PR79697: Delete calls to strdup, strndup, realloc if there is no lhs To: gcc Patches , Richard Biener X-IsSubscribed: yes Hi, The attached patch deletes calls to strdup, strndup if it's return-value is unused, and same for realloc if the first arg is NULL. Bootstrap+tested on x86_64-unknown-linux-gnu. OK for GCC 8 ? Thanks, Prathamesh 2017-02-25 Prathamesh Kulkarni PR tree-optimization/79697 * tree-ssa-dce.c (mark_stmt_if_obviously_necessary): Check if callee is BUILT_IN_STRDUP, BUILT_IN_STRNDUP, BUILT_IN_REALLOC. testsuite/ * gcc.dg/tree-ssa/pr79697.c: New test. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr79697.c b/gcc/testsuite/gcc.dg/tree-ssa/pr79697.c new file mode 100644 index 0000000..a6e75a6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr79697.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-cddce-details" } */ + +void f(void) +{ + __builtin_strdup ("abc"); +} + +void g(void) +{ + __builtin_strndup ("abc", 3); +} + +void h(void) +{ + __builtin_realloc (0, 10); +} + +/* { dg-final { scan-tree-dump "Deleting : __builtin_strdup" "cddce1" } } */ +/* { dg-final { scan-tree-dump "Deleting : __builtin_strndup" "cddce1" } } */ +/* { dg-final { scan-tree-dump "Deleting : __builtin_realloc" "cddce1" } } */ diff --git a/gcc/tree-ssa-dce.c b/gcc/tree-ssa-dce.c index 5ebe57b..b0f62b0 100644 --- a/gcc/tree-ssa-dce.c +++ b/gcc/tree-ssa-dce.c @@ -233,8 +233,17 @@ mark_stmt_if_obviously_necessary (gimple *stmt, bool aggressive) case BUILT_IN_CALLOC: case BUILT_IN_ALLOCA: case BUILT_IN_ALLOCA_WITH_ALIGN: + case BUILT_IN_STRDUP: + case BUILT_IN_STRNDUP: return; + case BUILT_IN_REALLOC: + { + tree arg0 = gimple_call_arg (stmt, 0); + if (operand_equal_p (arg0, null_pointer_node, 0)) + return; + break; + } default:; } /* Most, but not all function calls are required. Function calls that