From patchwork Tue Sep 25 11:23:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 186778 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]) by ozlabs.org (Postfix) with SMTP id 344B12C008F for ; Tue, 25 Sep 2012 21:24:26 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1349177067; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Subject:Message-ID:Reply-To: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=2MIJQ1e4ZWv0k9Jm6nB1 bDkB1XE=; b=QyWutpMmjhNpm8SaCRsNQ1S9Cck6rzy+pdiWqGKpS6U4Nxgy566w T8dlseH7e448kVB75lCq8XGUf3TQ8Ci9BM6EjYZTEJwB12FyT8gYorRsMhjn2h4X utu3P/EYP5hgAI46b8lIR9v3y6t3cEckzk5Z4FIEnLPvPVBxJKQ8hik= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Date:From:To:Subject:Message-ID:Reply-To:MIME-Version:Content-Type:Content-Disposition:User-Agent:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=mvPcvjOyrKj4RoCO7OcfAzlLKaqgmCtN1JHsBt2yxYC6I6CQ50jAzr0QDW5ZNI b/ZlxS7wxrmicnrXmjGnFpKN5LO4TgNJgESk1b75CyGzQaXJdQRujwLL02aZ+8hB zgtTYph95aZ+pkSaIp1UKTbQiSxp5/Tyk7V3rl6hgdoI8=; Received: (qmail 23261 invoked by alias); 25 Sep 2012 11:24:24 -0000 Received: (qmail 23248 invoked by uid 22791); 25 Sep 2012 11:24:23 -0000 X-SWARE-Spam-Status: No, hits=-6.7 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 25 Sep 2012 11:24:00 +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 q8PBO0dN031334 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 25 Sep 2012 07:24:00 -0400 Received: from zalov.redhat.com (vpn1-7-190.ams2.redhat.com [10.36.7.190]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q8PBNvQx026917 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 25 Sep 2012 07:23:59 -0400 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.redhat.com (8.14.5/8.14.5) with ESMTP id q8PBNru1010472 for ; Tue, 25 Sep 2012 13:23:53 +0200 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id q8PBNrKr010471 for gcc-patches@gcc.gnu.org; Tue, 25 Sep 2012 13:23:53 +0200 Date: Tue, 25 Sep 2012 13:23:53 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix VRP single-bit signed precision handling (PR tree-optimization/54676) Message-ID: <20120925112353.GK1787@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 Hi! This patch fixes two spots where signed 1-bit precision isn't handled properly in VRP. With that type, build_int_cst (TREE_TYPE (min), 1) will overflow and thus adding it to something or subtracting leads to ICEs or bad code. In the first spot min is different from max, which for 1-bit precision implies either all values, or none (but we don't have empty ranges and fallback to varying for those anyway). In the second case we can optimize if the anti range is singleton, then the corresponding range is singleton too (the other value). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2012-09-25 Jakub Jelinek PR tree-optimization/54676 * tree-vrp.c (set_and_canonicalize_value_range): Handle one bit precision properly. * gcc.dg/pr54676.c: New test. Jakub --- gcc/tree-vrp.c.jj 2012-09-17 11:13:12.000000000 +0200 +++ gcc/tree-vrp.c 2012-09-24 10:06:10.814376659 +0200 @@ -501,8 +501,19 @@ set_and_canonicalize_value_range (value_ to adjust them. */ if (tree_int_cst_lt (max, min)) { - tree one = build_int_cst (TREE_TYPE (min), 1); - tree tmp = int_const_binop (PLUS_EXPR, max, one); + tree one, tmp; + + /* For one bit precision if max < min, then the swapped + range covers all values, so for VR_RANGE it is varying and + for VR_ANTI_RANGE empty range, so drop to varying as well. */ + if (TYPE_PRECISION (TREE_TYPE (min)) == 1) + { + set_value_range_to_varying (vr); + return; + } + + one = build_int_cst (TREE_TYPE (min), 1); + tmp = int_const_binop (PLUS_EXPR, max, one); max = int_const_binop (MINUS_EXPR, min, one); min = tmp; @@ -531,6 +542,24 @@ set_and_canonicalize_value_range (value_ set_value_range_to_varying (vr); return; } + else if (TYPE_PRECISION (TREE_TYPE (min)) == 1 + && !TYPE_UNSIGNED (TREE_TYPE (min)) + && (is_min || is_max)) + { + /* For signed 1-bit precision, one is not in-range and + thus adding/subtracting it would result in overflows. */ + if (operand_equal_p (min, max, 0)) + { + min = max = is_min ? vrp_val_max (TREE_TYPE (min)) + : vrp_val_min (TREE_TYPE (min)); + t = VR_RANGE; + } + else + { + set_value_range_to_varying (vr); + return; + } + } else if (is_min /* As a special exception preserve non-null ranges. */ && !(TYPE_UNSIGNED (TREE_TYPE (min)) --- gcc/testsuite/gcc.dg/pr54676.c.jj 2012-09-24 10:52:48.911691835 +0200 +++ gcc/testsuite/gcc.dg/pr54676.c 2012-09-24 10:52:30.000000000 +0200 @@ -0,0 +1,23 @@ +/* PR tree-optimization/54676 */ +/* { dg-do compile } */ +/* { dg-options "-O -fno-tree-ccp -fno-tree-copy-prop -fno-tree-fre -ftree-vrp" } */ + +struct S +{ + int s:1; +}; + +struct S bar (void); + +int a; + +void +foo (int x) +{ + struct S s = bar (); + while (!a) + { + int l = 94967295; + a = x || (s.s &= l); + } +}