From patchwork Thu May 17 12:13:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 915397 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-477850-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="WedAS+TL"; 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 40mqvm1B9Kz9s0y for ; Thu, 17 May 2018 22:13:21 +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:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=eggGNRJ65WRIXjFp3piZAHijdAyRCIwqXjTxAafxrL8GkcoxtPGd2 wWzWmCVUHrD08ylh68iq3eBQBC5o2tUmhMZ3kWdz2DJe5cETCb07FdgeAGkqp8wH YPAnug6NjY4EcHTHtNiW9vfoUd+rJnEkjBBC3lIq6VnxArneh05UMk= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=hY0xGvhahUS7Bw3TP7HEiTMpDk0=; b=WedAS+TL+zMuvvS+X6TW 0zPddeZ0fYXmULwRECvsHFEGVCFmGkiNfpGQMHB4Dl7TEKUeuh6eJldaisaWFY0B ixqvJDAvr5qjFgmhLz9lpfHZtqOGuSbBa5KGiphxhZwa7hjuewCGGggcTfjJt6Of 3/ITqbKHJo15ckCc1oGcVfw= Received: (qmail 30586 invoked by alias); 17 May 2018 12:13:13 -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 30570 invoked by uid 89); 17 May 2018 12:13:13 -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, SPF_PASS autolearn=ham version=3.3.2 spammy=omax X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 17 May 2018 12:13:12 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id D44A2AAB2 for ; Thu, 17 May 2018 12:13:09 +0000 (UTC) Date: Thu, 17 May 2018 14:13:09 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Improve get_ref_base_and_extent with range-info Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 The following makes use of range-info to improve the basic building block of the alias-oracle so we can tell that in a[0] = 1; for (int i = 5; i < 17; ++i) a[i] = i; a[0] = 2; the ao_ref for a[i] does not alias the a[0] acceses. Given range-info is not always going to improve things over knowledge gained from the type size of the access I'm only improving it over information gathered from the size. For the above this allows us to DSE the first store with another DSE improvement I'm testing separately. Bootstrap & regtest in progress on x86_64-unknown-linux-gnu. Richard. 2018-05-17 Richard Biener * tree-dfa.c (get_ref_base_and_extent): Use range-info to refine results when processing array refs with variable index. * gcc.dg/tree-ssa/ssa-dse-35.c: New testcase. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-35.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-35.c new file mode 100644 index 00000000000..1f21670406f --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-35.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-dse1-details" } */ + +int a[256]; +void foo (void) +{ + a[0] = 1; + for (int i = 5; i < 17; ++i) + a[i] = i; + a[0] = 2; +} + +/* { dg-final { scan-tree-dump-times "Deleted dead store" 1 "dse1" } } */ diff --git a/gcc/tree-dfa.c b/gcc/tree-dfa.c index a121b880bb0..993ac49554d 100644 --- a/gcc/tree-dfa.c +++ b/gcc/tree-dfa.c @@ -529,6 +529,48 @@ get_ref_base_and_extent (tree exp, poly_int64_pod *poffset, /* Remember that we have seen an array ref with a variable index. */ seen_variable_array_ref = true; + + wide_int min, max; + if (TREE_CODE (index) == SSA_NAME + && (low_bound = array_ref_low_bound (exp), + poly_int_tree_p (low_bound)) + && (unit_size = array_ref_element_size (exp), + TREE_CODE (unit_size) == INTEGER_CST) + && get_range_info (index, &min, &max) == VR_RANGE) + { + poly_offset_int lbound = wi::to_poly_offset (low_bound); + /* Try to constrain maxsize with range information. */ + offset_int omax + = offset_int::from (max, TYPE_SIGN (TREE_TYPE (index))); + if (known_lt (lbound, omax)) + { + poly_offset_int rmaxsize; + rmaxsize = (omax - lbound + 1) + * wi::to_offset (unit_size) << LOG2_BITS_PER_UNIT; + if (!known_size_p (maxsize) + || known_lt (rmaxsize, maxsize)) + { + maxsize = rmaxsize; + /* Given we know an upper bound this is no + longer variable. */ + seen_variable_array_ref = false; + } + } + /* Try to adjust bit_offset with range information. */ + offset_int omin + = offset_int::from (min, TYPE_SIGN (TREE_TYPE (index))); + if (known_le (lbound, omin)) + { + poly_offset_int woffset + = wi::sext (omin - lbound, + TYPE_PRECISION (TREE_TYPE (index))); + woffset *= wi::to_offset (unit_size); + woffset <<= LOG2_BITS_PER_UNIT; + bit_offset += woffset; + if (known_size_p (maxsize)) + maxsize -= woffset; + } + } } } break;