From patchwork Tue Apr 9 01:54:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 234930 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 2E1D62C00AD for ; Tue, 9 Apr 2013 11:54:55 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=U3kTRJDCVgawtuSFQxQhK92kaRXDquXQnQww/aifn5qpaM 1racEE9igoK9qY0T3xHEdtosEOXlTCGYbG+sgDxkMroEIZc2gffy2U0xI26FX6+t 8wWBVIbrF/p2G+dXeuGq0whLzuKrRKCvX5Jumf6VfQfFYdJAwVOJAez5kEyvo= 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 :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=EzzFp3ebyXP93iHkEWbGg5fBZKU=; b=NIP+4sXGgdcIIC08a9nd Ydqrj23P7XW9Xo+UQ9H3U+m4rnY5wAgyAmdRGPY2e72TI9mZv4wlgxEAWTxK9cSc +jtxqe6BSbxJVs0R1H2EVRYGwjM/eajc1aKAItAWHxUOpgUHJzSujkNwOBRG2Wc+ Bm5koV00K0iIo2YRDmsZFfk= Received: (qmail 15205 invoked by alias); 9 Apr 2013 01:54:48 -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 14887 invoked by uid 89); 9 Apr 2013 01:54:47 -0000 X-Spam-SWARE-Status: No, score=-7.9 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS, TW_TM autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Tue, 09 Apr 2013 01:54:46 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r391sieB025464 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 8 Apr 2013 21:54:45 -0400 Received: from stumpy.slc.redhat.com (ovpn-113-84.phx2.redhat.com [10.3.113.84]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r391sivX019279 for ; Mon, 8 Apr 2013 21:54:44 -0400 Message-ID: <516374E3.8080800@redhat.com> Date: Mon, 08 Apr 2013 19:54:43 -0600 From: Jeff Law User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130402 Thunderbird/17.0.5 MIME-Version: 1.0 To: gcc-patches Subject: [RFA][PATCH] Improve VRP of COND_EXPR_CONDs -- v2 X-Virus-Found: No This incorporates the concrete suggestions from Steven & Richi -- it doesn't do any refactoring of the VRP code. There's still stuff I'm looking at that might directly lead to some refactoring. In the mean time I'm submitting the obvious small improvements. Bootstrapped and regression tested on x86_64-unknown-linux-gnu. OK for trunk? Jeff commit d6d1e36561b9022bbcdf157a886895f5bb0ef2ae Author: Jeff Law Date: Sat Apr 6 06:46:58 2013 -0600 * tree-vrp.c (simplify_cond_using_ranges): Simplify test of boolean when the boolean was created by converting a wider object which had a boolean range. * gcc.dg/tree-ssa/vrp87.c: New test diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6ee7d9c..110f61e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -16,8 +16,14 @@ 2013-04-08 Jeff Law + * tree-vrp.c (simplify_cond_using_ranges): Simplify test of boolean + when the boolean was created by converting a wider object which + had a boolean range. + +2013-04-08 Jeff Law + * gimple.c (canonicalize_cond_expr_cond): Rewrite x ^ y into x != y. - + 2013-04-08 Richard Biener * gimple-pretty-print.c (debug_gimple_stmt): Do not print diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp87.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp87.c new file mode 100644 index 0000000..7feff81 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp87.c @@ -0,0 +1,81 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-vrp2-details -fdump-tree-cddce2-details" } */ + +struct bitmap_head_def; +typedef struct bitmap_head_def *bitmap; +typedef const struct bitmap_head_def *const_bitmap; + + +typedef unsigned long BITMAP_WORD; +typedef struct bitmap_element_def +{ + struct bitmap_element_def *next; + unsigned int indx; + BITMAP_WORD bits[((128 + (8 * 8 * 1u) - 1) / (8 * 8 * 1u))]; +} bitmap_element; + + + + + + +typedef struct bitmap_head_def +{ + bitmap_element *first; + +} bitmap_head; + + + +static __inline__ unsigned char +bitmap_elt_ior (bitmap dst, bitmap_element * dst_elt, + bitmap_element * dst_prev, const bitmap_element * a_elt, + const bitmap_element * b_elt, unsigned char changed) +{ + + if (a_elt) + { + + if (!changed && dst_elt) + { + changed = 1; + } + } + else + { + changed = 1; + } + return changed; +} + +unsigned char +bitmap_ior_into (bitmap a, const_bitmap b) +{ + bitmap_element *a_elt = a->first; + const bitmap_element *b_elt = b->first; + bitmap_element *a_prev = ((void *) 0); + unsigned char changed = 0; + + while (b_elt) + { + + if (!a_elt || a_elt->indx == b_elt->indx) + changed = bitmap_elt_ior (a, a_elt, a_prev, a_elt, b_elt, changed); + else if (a_elt->indx > b_elt->indx) + changed = 1; + b_elt = b_elt->next; + + + } + + return changed; +} + +/* Verify that VRP simplified an "if" statement. */ +/* { dg-final { scan-tree-dump "Folded into: if.*" "vrp2"} } */ +/* Verify that DCE after VRP2 eliminates a dead conversion + to a (Bool). */ +/* { dg-final { scan-tree-dump "Deleting.*_Bool.*;" "cddce2"} } */ +/* { dg-final { cleanup-tree-dump "vrp2" } } */ +/* { dg-final { cleanup-tree-dump "cddce2" } } */ + diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index 250a506..4520c89 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -8584,6 +8584,45 @@ simplify_cond_using_ranges (gimple stmt) } } + /* If we have a comparison of a SSA_NAME boolean against + a constant (which obviously must be [0..1]), see if the + SSA_NAME was set by a type conversion where the source + of the conversion is another SSA_NAME with a range [0..1]. + + If so, we can replace the SSA_NAME in the comparison with + the RHS of the conversion. This will often make the type + conversion dead code which DCE will clean up. */ + if (TREE_CODE (op0) == SSA_NAME + && (TREE_CODE (TREE_TYPE (op0)) == BOOLEAN_TYPE + || (INTEGRAL_TYPE_P (TREE_TYPE (op)) + && TYPE_PRECISION (TREE_TYPE (op0)) == 1)) + && TREE_CODE (op1) == INTEGER_CST) + { + gimple def_stmt = SSA_NAME_DEF_STMT (op0); + tree innerop; + + if (!is_gimple_assign (def_stmt) + || !CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def_stmt))) + return false; + + innerop = gimple_assign_rhs1 (def_stmt); + + if (TREE_CODE (innerop) == SSA_NAME) + { + value_range_t *vr = get_value_range (innerop); + + if (range_int_cst_p (vr) + && operand_equal_p (vr->min, integer_zero_node, 0) + && operand_equal_p (vr->max, integer_one_node, 0)) + { + tree newconst = fold_convert (TREE_TYPE (innerop), op1); + gimple_cond_set_lhs (stmt, innerop); + gimple_cond_set_rhs (stmt, newconst); + return true; + } + } + } + return false; }