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: 912670 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-477618-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="KKL4zt6a"; 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 40kmcm1w29z9ryk for ; Mon, 14 May 2018 13:38:16 +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:cc:content-type; q=dns; s=default; b=hX3Lnc7ht4xmTaWJFuXSx9GD9NnYqIqMbQEHpMaf8kx fbkbSMsVtiIw0t31CDbgHANW76vqZIwD3b+j14IvznRkJiAW8RQlsQ09w4x7p/9a AOfl/4er23O9tdKRmg9QE5yHF7xwinTXzMF0CVUQZrUqKK4vH1bKQE8jrfG7HAAA = 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=KKL4zt6aLIzVXl6yI u73mbdWxCG4Wg5LXMny6KDzZ7qkPtUQJLrYfIkb3wcWJ9SQvyEElrZ+pNI5ld4OA zFB5gGL3I7aGYc5zLakVZTFW0+DDPT+zaP37nYm/I155c98JKgXkjMWWcc7pn5lJ EbWIq+By0UoWjPbBuEmYDT1BOI= 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-Google-Smtp-Source: AB8JxZpXRDKcgFzltfW4AO1gPbMX5HCu2xOjccFU6f6+kj2aSq5rbi3gyBBZArGvlEG+qYtjIX00JvoR5/sh/GJVelo= 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