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: 656516 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 3s70XK4YnHz9t0q for ; Mon, 8 Aug 2016 11:42:24 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=J79+eOLJ; 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 :subject:to:message-id:date:mime-version:content-type; q=dns; s= default; b=qI2a8qKrxGh7ZHK58g748NYue1Cg9GQxhb9mP9dyzIjSZTT/9lPNY bXRGRq4X5XCzLy9UBzvPINXEigFZG1OyPWE121niJaODdteh0NBt5zhSlLRE2eY+ mr2zKALhBg+WRtlJmh9hyjXZAa7FrzoOOwxRK3O7MXu9F+xJ32MXio= 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=J79+eOLJGjkUVauSwIDE 7nagDZjUbK8wOK9e+F5CJF5IqHT5T1oLMjWZscTyJqRPQeyEokxBiuS8S2yW4Ad8 wubW23QUiFYWMTLG0QDYRXdo+NuggLdmBU1Vzv3LXY6n8uzvOCntLQDZPK5aJE/F jomaAvCusIFEXUAuuQYWz4c= 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);