From patchwork Tue Apr 24 07:10:14 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 154615 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 22F82B6FBB for ; Tue, 24 Apr 2012 17:10:52 +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=1335856254; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To: References:MIME-Version:Content-Type:Content-Disposition: In-Reply-To:User-Agent:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=uXlB7aJwi0CcJUuezh3Bw7Se8rc=; b=aCoW+swMaWA7FXn ka9YHc/iDDvFnv1/G4RA3W1kl+cY5v7eAL/94K+faXFxFXOwpqo9re64KNn4UIzJ XgWBdp46hHlBRFZJELCXCaB44rneHSP6wZMmtjn+n+Q3w+PVMol6nvcw5gp48iIf jEGpOFQQVVbTS8M4VyW3PxIjdoCQ= 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:Cc:Subject:Message-ID:Reply-To:References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To:User-Agent:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=wqnYLeMUUrsz5sP3VaKH6DRxLwHB1ltGWrqYXLBOdKwDYQpr/ts7yqRXhnf++R evSp+VWx9nhZXArP8nQNOLVYy/GWI1l2o/6zNDR8MaLNjZTmSZ8V8uIwWDTSoLel m0EpgYTJLLnXeZma8/R+To6bP6/qlCRJ/lwE4TTrKIY14=; Received: (qmail 4916 invoked by alias); 24 Apr 2012 07:10:44 -0000 Received: (qmail 4863 invoked by uid 22791); 24 Apr 2012 07:10:42 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, SPF_HELO_PASS, T_RP_MATCHES_RCVD 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, 24 Apr 2012 07:10:18 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q3O7AHmO005315 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 24 Apr 2012 03:10:17 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q3O7AGw7023991 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 24 Apr 2012 03:10:17 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id q3O7AFgj030285; Tue, 24 Apr 2012 09:10:16 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id q3O7AFe6030284; Tue, 24 Apr 2012 09:10:15 +0200 Date: Tue, 24 Apr 2012 09:10:14 +0200 From: Jakub Jelinek To: Richard Guenther Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix VRP ICE on x >> cst1; if (x cmp cst2) (PR tree-optimization/53058, take 2) Message-ID: <20120424071014.GQ16117@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek References: <20120423230106.GN16117@tyan-ft48-01.lab.bos.redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: 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 On Tue, Apr 24, 2012 at 08:05:35AM +0200, Richard Guenther wrote: > On Tue, Apr 24, 2012 at 1:01 AM, Jakub Jelinek wrote: > I don't like using TYPE_MAX_VALUE in VRP - at least please use vrp_val_max. > For enums this can be not what you expect(?) > > Please consider adding a double_int_max_value (unsigned prec, bool sign) > and double_int_min_value. So like this instead? 2012-04-24 Jakub Jelinek PR tree-optimization/53058 * double-int.h (double_int_max_value, double_int_min_value): New functions. * tree-vrp.c (register_edge_assert_for_2): Compare mask for LE_EXPR or GT_EXPR with double_int_max_value instead of double_int_mask. * gcc.c-torture/compile/pr53058.c: New test. Jakub --- gcc/double-int.h.jj 2012-04-19 11:09:13.000000000 +0200 +++ gcc/double-int.h 2012-04-24 08:42:42.655756406 +0200 @@ -1,5 +1,5 @@ /* Operations with long integers. - Copyright (C) 2006, 2007, 2008, 2010 Free Software Foundation, Inc. + Copyright (C) 2006, 2007, 2008, 2010, 2012 Free Software Foundation, Inc. This file is part of GCC. @@ -280,6 +280,26 @@ double_int_equal_p (double_int cst1, dou return cst1.low == cst2.low && cst1.high == cst2.high; } +/* Returns a maximum value for signed or unsigned integer + of precision PREC. */ + +static inline double_int +double_int_max_value (unsigned int prec, bool uns) +{ + return double_int_mask (prec - (uns ? 0 : 1)); +} + +/* Returns a minimum value for signed or unsigned integer + of precision PREC. */ + +static inline double_int +double_int_min_value (unsigned int prec, bool uns) +{ + if (uns) + return double_int_zero; + return double_int_lshift (double_int_one, prec - 1, prec, false); +} + /* Legacy interface with decomposed high/low parts. */ --- gcc/tree-vrp.c.jj 2012-04-23 11:11:21.000000000 +0200 +++ gcc/tree-vrp.c 2012-04-24 09:06:29.116624564 +0200 @@ -4565,6 +4565,7 @@ register_edge_assert_for_2 (tree name, e && INTEGRAL_TYPE_P (TREE_TYPE (name2)) && IN_RANGE (tree_low_cst (cst2, 1), 1, prec - 1) && prec <= 2 * HOST_BITS_PER_WIDE_INT + && prec == GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (val))) && live_on_edge (e, name2) && !has_single_use (name2)) { @@ -4598,8 +4599,10 @@ register_edge_assert_for_2 (tree name, e new_val = val2; else { + double_int maxval + = double_int_max_value (prec, TYPE_UNSIGNED (TREE_TYPE (val))); mask = double_int_ior (tree_to_double_int (val2), mask); - if (double_int_minus_one_p (double_int_sext (mask, prec))) + if (double_int_equal_p (mask, maxval)) new_val = NULL_TREE; else new_val = double_int_to_tree (TREE_TYPE (val2), mask); --- gcc/testsuite/gcc.c-torture/compile/pr53058.c.jj 2012-04-23 15:53:41.489982650 +0200 +++ gcc/testsuite/gcc.c-torture/compile/pr53058.c 2012-04-23 15:53:13.000000000 +0200 @@ -0,0 +1,12 @@ +/* PR tree-optimization/53058 */ + +int a, b, c; + +void +foo () +{ + c = b >> 16; + if (c > 32767) + c = 0; + a = b; +}