From patchwork Mon May 14 03:37:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 135658 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1211818lji; Sun, 13 May 2018 20:38:20 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp/KHD/7PFd+XlKTIEV9Ko/9t9P0sZJgWEwvG3GMTT5gG56C/HvoTfzEBIfrlzLaqqQ0pZn X-Received: by 2002:a17:902:4081:: with SMTP id c1-v6mr8013640pld.60.1526269100337; Sun, 13 May 2018 20:38:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526269100; cv=none; d=google.com; s=arc-20160816; b=nc5tlSYIi5Z94FcbrvMinYiGQ51TiI0Zw829IHMSFdjOFEk26gqW4ZbQqL+rBjM7BN VEJJlF9x5kMiTGjJFssCXIUD+hS6ZOmlVRYqSr1rWOxoDIOq0SYRyfIlGFx6PZAorE2p tApzTL5vOv33QsIvVvS875Rpnfr8Yzc3nRTGDGOG7U9EmVzp/gaD+guVd0YyOLJpzneQ MVOcyqsp/xp0w2GDTMRfKRvX3wrZXnwvQM54eVBAab7pCYG/xYkBekrAfbvV1oh2N3sA iVCz8ituAZ4UX/HqBAmAnq0/dYsnIkVNfdVz4MDQKI4/IGjeso1RbE15/GlvhkPbmfRf Zp1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:mime-version:delivered-to:sender :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=AuxtWh6+pihb/+Qp6Ye4tND/UFL8TzSTadMwK8R6J0Q=; b=eMnptJsgIFFSEgn5JF5FqVAufq368M1TscUAIvf7F3AnzB/BS4gJCdHSBORz/zm5aO L4ceh8T2Ih4e5I5M09Ab7YE7f1tQFGiNW5kuhenSH1qe3Our8bC5dPI5kvHbG40a+TxH VbmLogJi8FewUT13+V1E2smpgtD27A7aU8w1s80mceCBngoxoKIhr6Pc6WRn4nqf95j4 qmfpxPFjvfjlqXRsBHHR6AxGX7KvG0h25paoHYAJFv9sheaCLOxjPmwIuxC1wkClta3x b03Kwzi7s1QE9BeXt8nX1fUhSEcemhkRk3PYfRU4kxrnNusKE3sSy+jxyC6h7UHFONzF jObg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=T/02D8eb; spf=pass (google.com: domain of gcc-patches-return-477618-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-477618-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id z19-v6si8446120plo.174.2018.05.13.20.38.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 May 2018 20:38:20 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-477618-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 header.s=default header.b=T/02D8eb; spf=pass (google.com: domain of gcc-patches-return-477618-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-477618-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:cc:content-type; q=dns; s=default; b=XhelvkFWG8cxiIHvgCFdfjfMmseH2Iuf9j2xchT599L 1/xiUnqhJd+wqNjlqpuDwaVgbvYkyhRQTLJeZI4jNQS90fxhHnpnuI6Q2Dz5PXjC Af/9GaTo1XzRd7IQUk3TCx+NB+OF++neUwW2hRRnS93J4iRHYfNF0ElU8vFzdnf8 = 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:cc:content-type; s=default; bh=HNhDUXxFzLIu/G1gIALmyXgsTwk=; b=T/02D8ebdmleiQJae JHe5slEsKHW7yHHudXoIZtKw7WGVaKYx+tge6Jx4jjQwv5sBA6SugZNbETkxGCop UQA0s/6TS0brEoVh6SG3WUbRMqSh04vKYjwBqZlX3gGkdFVahroNKmq2ZZPUd/Zh ksUcap0YjlTQOSt6+x6NqtPTKc= Received: (qmail 3948 invoked by alias); 14 May 2018 03:38:09 -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 3923 invoked by uid 89); 14 May 2018 03:38:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=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-lf0-f46.google.com Received: from mail-lf0-f46.google.com (HELO mail-lf0-f46.google.com) (209.85.215.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 14 May 2018 03:38:06 +0000 Received: by mail-lf0-f46.google.com with SMTP id t129-v6so15739304lff.3 for ; Sun, 13 May 2018 20:38:06 -0700 (PDT) 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:cc; bh=NPOMRdFrnGT7lRnP3Q3d55llJJQKXXLZQXZY4Ui1A04=; b=WpYR4p6/xG6P/Vp7jGaH3HG61OA4RRkc6XF1GwUmBKJzQ9pPSAolbFjPXV5vgwfRsK n5SxZ6CurnWXPqgaB5PnHmfBhPJOSyFJV6yoLkICy8exRLIdIR5ppjp1/RbiGUC5zCmJ ZYdA/pIdC/gttShOKyTbKZdc38dq/2Nr9qeHkBPpBFn2Mea0AFaZ8d3iZp+BiGSFoOd5 z/wY38ZSwiuTKFH+AOZRJIfw41UR5JB5OMeJB8i4Q7AClRx1Fj6ao90zPxsHzSzqS/qI dMKSjCjoETTUUBhn0s+jguJYF/IKEyzsPs6p5BzP4YVmLSJlGb0eno8KoRXWKeaDxXvc ++fg== X-Gm-Message-State: ALKqPwc7NG1ePLxM6WXi7DOQMQKkKRuLEBEtACkrdS8G4I/vAA0vdPq6 Z5kMzmxCY4NdEmRTFOWyXDGiZgWuOyXPfUvuXWuuQSaSEaw= X-Received: by 2002:a19:d763:: with SMTP id o96-v6mr6950068lfg.89.1526269084392; Sun, 13 May 2018 20:38:04 -0700 (PDT) MIME-Version: 1.0 Received: by 10.46.41.129 with HTTP; Sun, 13 May 2018 20:37:23 -0700 (PDT) From: Kugan Vivekanandarajah Date: Mon, 14 May 2018 13:37:23 +1000 Message-ID: Subject: [PR63185][RFC] Improve DSE with branches To: GCC Patches Cc: Richard Biener , Jeff Law X-IsSubscribed: yes Hi, Attached patch handles PR63185 when we reach PHI with temp != NULLL. We could see the PHI and if there isn't any uses for PHI that is interesting, we could ignore that ? Bootstrapped and regression tested on x86_64-linux-gnu. Is this OK? Thanks, Kugan gcc/ChangeLog: 2018-05-14 Kugan Vivekanandarajah * tree-ssa-dse.c (phi_dosent_define_nor_use_p): New. (dse_classify_store): Use phi_dosent_define_nor_use_p. gcc/testsuite/ChangeLog: 2018-05-14 Kugan Vivekanandarajah * gcc.dg/tree-ssa/ssa-dse-33.c: New test. >From a69caa24d9c1914b7617a937e84c3b612ffe6d9b Mon Sep 17 00:00:00 2001 From: Kugan Vivekanandarajah Date: Wed, 9 May 2018 16:26:16 +1000 Subject: [PATCH] PR63185 Change-Id: I9d307884add10d5b5ff07aa31dd86cb83b2388ec --- gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-33.c | 13 +++++++++++++ gcc/tree-ssa-dse.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-33.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-33.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-33.c new file mode 100644 index 0000000..46cb7d1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-33.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-dse-details" } */ + +void g(); +void f(int n) +{ + char *p = malloc(1024); + memset (p, 8, 1024); + if (n) + g(); +} + +/* { dg-final { scan-tree-dump-times "Deleted dead calls" 1 "dse1"} } */ diff --git a/gcc/tree-ssa-dse.c b/gcc/tree-ssa-dse.c index 9220fea..e7a4637 100644 --- a/gcc/tree-ssa-dse.c +++ b/gcc/tree-ssa-dse.c @@ -515,6 +515,30 @@ live_bytes_read (ao_ref use_ref, ao_ref *ref, sbitmap live) return true; } +/* Return true if there isnt any VDEF or VUSE by following PHI. */ + +static bool +phi_dosent_define_nor_use_p (ao_ref *ref, gphi *phi) +{ + gimple *phi_use; + imm_use_iterator ui; + tree def = PHI_RESULT (phi); + bool ok = true; + + FOR_EACH_IMM_USE_STMT (phi_use, ui, def) + { + if (ref_maybe_used_by_stmt_p (phi_use, ref) + || gimple_vdef (phi_use) + || gimple_code (phi_use) == GIMPLE_PHI) + { + ok = false; + BREAK_FROM_IMM_USE_STMT (ui); + } + } + + return ok; +} + /* A helper of dse_optimize_stmt. Given a GIMPLE_ASSIGN in STMT that writes to REF, find a candidate statement *USE_STMT that may prove STMT to be dead. @@ -570,6 +594,9 @@ dse_classify_store (ao_ref *ref, gimple *stmt, gimple **use_stmt, else if (gimple_code (use_stmt) == GIMPLE_PHI) { if (temp + && phi_dosent_define_nor_use_p (ref, as_a (use_stmt))) + ; + else if (temp /* Make sure we are not in a loop latch block. */ || gimple_bb (stmt) == gimple_bb (use_stmt) || dominated_by_p (CDI_DOMINATORS, @@ -585,7 +612,8 @@ dse_classify_store (ao_ref *ref, gimple *stmt, gimple **use_stmt, /* Do not consider the PHI as use if it dominates the stmt defining the virtual operand we are processing, we have processed it already in this case. */ - if (gimple_bb (defvar_def) != gimple_bb (use_stmt) + if (!temp + && gimple_bb (defvar_def) != gimple_bb (use_stmt) && !dominated_by_p (CDI_DOMINATORS, gimple_bb (defvar_def), gimple_bb (use_stmt))) -- 2.7.4