From patchwork Fri Dec 16 01:55:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 706311 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3tfthd1Wfdz9snm for ; Fri, 16 Dec 2016 12:56:33 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="hGFJNhN6"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:message-id:date:mime-version:content-type; q=dns; s= default; b=jNVCjgqUBeqoDeCkGSljUSMsqivVol1S+PMxPtzcOWlm4oB+psNgi IhUmt4Bcxy/ETqJVjcCXPKQvD6nEVea07iD6SDtzbZgixLjkiEGe7/+GrZaOAuV1 kDm9Hj52mMrG+KfoOu4hyy+Ox+4kNK3nUUrHnToi1xJm1T94gntozM= 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:from :to:subject:message-id:date:mime-version:content-type; s= default; bh=6fXy3nzABEDH+qes42qx3WQpZ48=; b=hGFJNhN6igJBRY9UyL+/ a1p9Og9NLsQX31c+ll+BU1/ws+vB+ETVy5arQa3zusONLLiNtv9zemamlC3GuUa3 GgJmsPlH2wEtHmCxtzjPIO5ETvzubzVpcPM5lmC6G0uqVS3Tju59IHvCLkRAHydh OiLXDrP8bgFaRSuN+/Ocpbs= Received: (qmail 121645 invoked by alias); 16 Dec 2016 01:55:23 -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 115755 invoked by uid 89); 16 Dec 2016 01:55:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-5.0 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=our X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 16 Dec 2016 01:55:03 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2193C81236 for ; Fri, 16 Dec 2016 01:55:02 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-182.phx2.redhat.com [10.3.116.182]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uBG1t1cq028857 for ; Thu, 15 Dec 2016 20:55:01 -0500 From: Jeff Law To: gcc-patches Subject: [RFA] [PATCH 4/4] Ignore reads of "dead" memory locations in DSE Message-ID: <8d9f9db6-d697-0d3e-909c-fff9fcb2fadb@redhat.com> Date: Thu, 15 Dec 2016 18:55:01 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 X-IsSubscribed: yes This is the final patch in the kit to improve our DSE implementation. It's based on a observation by Richi. Namely that a read from bytes of memory that are dead can be ignored. By ignoring such reads we can sometimes find additional stores that allow us to either eliminate or trim an earlier store more aggressively. This only hit (by hit I mean the ability to ignore resulted in finding a full or partially dead store that we didn't otherwise find) once during a bootstrap, but does hit often in the libstdc++ testsuite. There's nothing in the BZ database on this issue and I can't reasonably call it a bugfix. I wouldn't lose sleep if this deferred to gcc-8. Bootstrapped and regression tested on x86-64-linux-gnu. OK for the trunk or defer to gcc-8? * tree-ssa-dse.c (dse_possible_dead_store_p): Ignore reads of dead bytes. * testsuite/gcc.dg/tree-ssa/ssa-dse-XX.c: New test. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/dse-2.c b/gcc/testsuite/gcc.dg/tree-ssa/dse-2.c new file mode 100644 index 0000000..6605dfe --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/dse-2.c @@ -0,0 +1,33 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-dse1-details" } */ + +enum constraint_expr_type +{ + SCALAR, DEREF, ADDRESSOF +}; +typedef struct constraint_expr +{ + enum constraint_expr_type type; + unsigned int var; + long offset; +} constraint_expr ; +typedef struct constraint +{ + struct constraint_expr lhs; + struct constraint_expr rhs; +} constraint; +static _Bool +constraint_expr_equal (struct constraint_expr x, struct constraint_expr y) +{ + return x.type == y.type && x.var == y.var && x.offset == y.offset; +} + +_Bool +constraint_equal (struct constraint a, struct constraint b) +{ + return constraint_expr_equal (a.lhs, b.lhs) + && constraint_expr_equal (a.rhs, b.rhs); +} + +/* { dg-final { scan-tree-dump-times "Deleted dead store" 2 "dse1" } } */ + diff --git a/gcc/tree-ssa-dse.c b/gcc/tree-ssa-dse.c index a868f11..1482c7f 100644 --- a/gcc/tree-ssa-dse.c +++ b/gcc/tree-ssa-dse.c @@ -439,6 +439,50 @@ dse_possible_dead_store_p (ao_ref *ref, gimple *stmt, gimple **use_stmt) /* If the statement is a use the store is not dead. */ else if (ref_maybe_used_by_stmt_p (use_stmt, ref)) { + /* Handle common cases where we can easily build a ao_ref + structure for USE_STMT and in doing so we find that the + references hit non-live bytes and thus can be ignored. */ + if (live_bytes) + { + if (is_gimple_assign (use_stmt)) + { + /* Other cases were noted as non-aliasing by + the call to ref_maybe_used_by_stmt_p. */ + ao_ref use_ref; + ao_ref_init (&use_ref, gimple_assign_rhs1 (use_stmt)); + if (valid_ao_ref_for_dse (&use_ref) + && use_ref.base == ref->base + && use_ref.size == use_ref.max_size) + { + size_t start = use_ref.offset / BITS_PER_UNIT; + size_t end = use_ref.size / BITS_PER_UNIT; + bitmap z = BITMAP_ALLOC (NULL); + bitmap_set_range (z, start, end); + bitmap_and_into (z, live_bytes); + if (bitmap_empty_p (z)) + { + BITMAP_FREE (z); + if (gimple_vdef (use_stmt)) + { + /* If we have already seen a store and + this is also a store, then we have to + fail. */ + if (temp) + { + fail = true; + BREAK_FROM_IMM_USE_STMT (ui); + } + + /* Otherwise walk through this store. */ + temp = use_stmt; + } + continue; + } + BITMAP_FREE (z); + } + } + } + fail = true; BREAK_FROM_IMM_USE_STMT (ui); }