From patchwork Mon Aug 8 01:41:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 73401 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp2977651qga; Sun, 7 Aug 2016 18:42:45 -0700 (PDT) X-Received: by 10.66.158.104 with SMTP id wt8mr156975328pab.64.1470620550329; Sun, 07 Aug 2016 18:42:30 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id l29si34124955pfk.67.2016.08.07.18.42.30 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Aug 2016 18:42:30 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-433432-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-433432-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-433432-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=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:from :subject:to:message-id:date:mime-version:content-type; q=dns; s= default; b=MmHbaeXfO9PT89/e0xWVNz/ed4ZjFfzUdK5Mlx2f/oNSbzOb9UaJN bpHd5LNseK5LD2+ti8qy17ShUfe//7Gi5y2CmgmwMkpj4jqAK35pSfErgwOdvaCl Tu5qW/B7Qz0E5NIkCtTcolPA3PeMBTO6/moT7eSPmj3Hawt/nROmOo= 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 :subject:to:message-id:date:mime-version:content-type; s= default; bh=1VN1WRtWqNp3A6u9PByh4JuQHRk=; b=I1qtZE5F7Oj/A/G8gAIb fTwWd3F13fJXDkCUf0fDHtbYUZrhXnFaM+zLO6ZWxBTV2V6eSaIb3xOfJGzzkTKi FELFXlnoTQ56UChu1pyeRjK4/offKmjBWmgmha1aydf4peU+RruP56BEjEFFmPCd 9jlHGRs+jJ2pCSQFl/Hjtng= Received: (qmail 127303 invoked by alias); 8 Aug 2016 01:42:16 -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 127286 invoked by uid 89); 8 Aug 2016 01:42:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=2016-08-08, jumps, bit_and, bit_not X-HELO: mail-pf0-f169.google.com Received: from mail-pf0-f169.google.com (HELO mail-pf0-f169.google.com) (209.85.192.169) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 08 Aug 2016 01:42:02 +0000 Received: by mail-pf0-f169.google.com with SMTP id h186so113466379pfg.3 for ; Sun, 07 Aug 2016 18:42:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:message-id:date:user-agent :mime-version; bh=cQjFyVGJSxiWK7OuDB15k12JIqaUBVS9yw4gwNeNtXA=; b=PV/kjdwQSUDqRhnrnpAPHBZf4VO3B+oysI4iDWZoAN9sOI6weRU53jvy3paeen91rt iQy5KIVDksm2IU0QfcBYke5YPlBefWuFNiqWcrcE6SN5rPYK0eqXeiaykByua56YSz/P WBboZ6VhURpv08PqCidXykn8njW4o7oJuYR9MXGJIj+wGFtwCF7PpKYU0pUk6dSXxyH3 pghIjh4dukDlUD+P8E4N5Lh9FEB9sGkglIp5BC3fb17WI4v7R8j6qz83r22HrzqPGWC0 cLKCntvmdqVvVm7enHZ0U9XAvV420BSq3UQ1Qc7jX8qw7fF8RMSJVxckMrsGa5UeTtYe UosA== X-Gm-Message-State: AEkooutZx44Leqfd8IKiNd8uEpWHLbB8X8MeKd1GJYfR/k/4MVZs5FOA74xIrNXbecMxg+T8 X-Received: by 10.98.104.71 with SMTP id d68mr158566545pfc.163.1470620520453; Sun, 07 Aug 2016 18:42:00 -0700 (PDT) Received: from [10.1.1.4] (58-6-183-210.dyn.iinet.net.au. [58.6.183.210]) by smtp.gmail.com with ESMTPSA id g5sm43158949pfg.0.2016.08.07.18.41.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Aug 2016 18:41:59 -0700 (PDT) From: kugan Subject: [RFC] Use ccp mask and val to refine value_range To: "gcc-patches@gcc.gnu.org" , Richard Biener , Jeff Law Message-ID: <9f3e00ae-a0c7-0047-c2e7-6578d9300171@linaro.org> Date: Mon, 8 Aug 2016 11:41:32 +1000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi All, I was experimenting with using ccp mask and value to refine value_ranges for SSA_NAME. Attached patch does this. This might be particularly useful for early_vrp. Bootstrap on x86_64-linux-gnu is OK. However, there are some test-cases (as shown below) are failing. Is this worth investigating? Any thoughts? # Comparing directories ## Dir1=build-base/: 11 sum files ## Dir2=build: 11 sum files # Comparing 11 common sum files ## /bin/sh ./gcc/contrib/compare_tests /tmp/gxx-sum1.26167 /tmp/gxx-sum2.26167 Tests that now fail, but worked before: gcc.c-torture/execute/pr57124.c -O2 execution test gcc.c-torture/execute/pr57124.c -O2 -flto -fno-use-linker-plugin -flto-partition=none execution test gcc.c-torture/execute/pr57124.c -O3 -g execution test gcc.c-torture/execute/pr57124.c -Os execution test gcc.dg/Wstrict-overflow-12.c correct warning (test for warnings, line 13) gcc.dg/Wstrict-overflow-13.c correct warning (test for warnings, line 14) gcc.dg/Wstrict-overflow-21.c correct warning (test for warnings, line 8) gcc.dg/no-strict-overflow-6.c scan-tree-dump optimized "return 0" gcc.dg/tree-ssa/pr61743-1.c scan-tree-dump-times cunroll "loop with 4 iterations completely unrolled" 2 gcc.dg/tree-ssa/pr61743-1.c scan-tree-dump-times cunroll "loop with 8 iterations completely unrolled" 2 gcc.dg/tree-ssa/ssa-dom-thread-7.c scan-tree-dump thread3 "Jumps threaded: 3" ## Differences found: # 1 differences in 11 common sum files found Thanks, Kugan gcc/ChangeLog: 2016-08-08 Kugan Vivekanandarajah * tree-ssanames.c (refine_range_info): New. * tree-ssa-ccp.c (ccp_finalize): Call refine_range_info. * tree-ssanames.c (refine_range_info): Declare. diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c index ae120a8..e7326c7 100644 --- a/gcc/tree-ssa-ccp.c +++ b/gcc/tree-ssa-ccp.c @@ -940,8 +940,14 @@ ccp_finalize (bool nonzero_p) unsigned int precision = TYPE_PRECISION (TREE_TYPE (val->value)); wide_int nonzero_bits = wide_int::from (val->mask, precision, UNSIGNED) | val->value; + wide_int mask = wide_int::from (val->mask, TYPE_PRECISION (TREE_TYPE (name)), + TYPE_SIGN (TREE_TYPE (name))); + wide_int ones = wi::bit_and (val->value, wi::bit_not (mask)); + wide_int zeros = wi::bit_not (wi::bit_and (wi::bit_not (val->value), + wi::bit_not (mask))); nonzero_bits &= get_nonzero_bits (name); set_nonzero_bits (name, nonzero_bits); + refine_range_info (name, zeros, ones); } } diff --git a/gcc/tree-ssanames.c b/gcc/tree-ssanames.c index 91a8f97..a69d8e9 100644 --- a/gcc/tree-ssanames.c +++ b/gcc/tree-ssanames.c @@ -388,6 +388,36 @@ set_nonzero_bits (tree name, const wide_int_ref &mask) ri->set_nonzero_bits (mask); } +/* Refine value range of NAME based on allways ZEROS and always ONES bits. */ +void +refine_range_info (tree name, const wide_int_ref &zeros, + const wide_int_ref &ones) +{ + tree type = TREE_TYPE (name); + gcc_assert (!POINTER_TYPE_P (TREE_TYPE (name))); + if (SSA_NAME_RANGE_INFO (name) == NULL) + set_range_info (name, VR_RANGE, + TYPE_MIN_VALUE (type), + TYPE_MAX_VALUE (type)); + + if (SSA_NAME_RANGE_TYPE (name) != VR_RANGE) + return; + + wide_int min = wi::min_value (type); + wide_int max = wi::max_value (type); + + max &= zeros; + max |= ones; + min &= zeros; + min |= ones; + + range_info_def *ri = SSA_NAME_RANGE_INFO (name); + if (wi::cmp (ri->get_min(), min, TYPE_SIGN (TREE_TYPE (name))) == -1) + ri->set_min (min); + if (wi::cmp (max, ri->get_max(), TYPE_SIGN (TREE_TYPE (name))) == -1) + ri->set_max (max); +} + /* Return a widest_int with potentially non-zero bits in SSA_NAME NAME, or -1 if unknown. */ diff --git a/gcc/tree-ssanames.h b/gcc/tree-ssanames.h index c81b1a1..c18047a 100644 --- a/gcc/tree-ssanames.h +++ b/gcc/tree-ssanames.h @@ -74,6 +74,8 @@ extern void set_range_info (tree, enum value_range_type, const wide_int_ref &, extern enum value_range_type get_range_info (const_tree, wide_int *, wide_int *); extern void set_nonzero_bits (tree, const wide_int_ref &); +extern void refine_range_info (tree name, const wide_int_ref &zeros, + const wide_int_ref &ones); extern wide_int get_nonzero_bits (const_tree); extern bool ssa_name_has_boolean_range (tree); extern void init_ssanames (struct function *, int);