From patchwork Wed Nov 23 09:59:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 698123 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 3tNyWn2sgZz9sXx for ; Wed, 23 Nov 2016 21:00:37 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="yqBzy8kK"; 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 :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=F0iUDOhHlpk3yLOd Nk9TfmXO4SuTKPmrdj15y9gqdGhg0DsdLGxdFu7k8Nu2ARulmoSlxWhxi9wBP2Su NyJnkQRdcRpKiXuS/Wi0FFkBm6hEQYDq3eGTMIf7AnVM5s8iufk9CC92E5djVjWN HMQ4smDgkbnQTp/QzmOoBybkEi0= 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 :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=DalcFllCk5l1b4wQtyPPhJ CQRIs=; b=yqBzy8kKb16Xkoe2oQtrkE9njtQ2cBHabx+QxCwHdVLvShgOLxWytU LKBRUQDG2e1B36FIRU6KOpFXggcs1AByWLpbGdai6YsVz9fuQCAyFhYETFRs/TNn +xmqRtHl8HJw+Q6m9qdFygYo2X6mxjcHE3kUhvaDns+qmAgMGn0d4= Received: (qmail 63123 invoked by alias); 23 Nov 2016 10:00:24 -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 62881 invoked by uid 89); 23 Nov 2016 10:00:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=AWL, BAYES_00, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=no version=3.3.2 spammy=Nonstandard, Non-standard, botcazou, Testcase X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 23 Nov 2016 09:59:59 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 266F981355 for ; Wed, 23 Nov 2016 10:59:57 +0100 (CET) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jaimeF5hB2M6 for ; Wed, 23 Nov 2016 10:59:57 +0100 (CET) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id F1B4681354 for ; Wed, 23 Nov 2016 10:59:56 +0100 (CET) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [patch] Fix PR middle-end/78429 Date: Wed, 23 Nov 2016 10:59:56 +0100 Message-ID: <73997113.6Wmqtae7MJ@polaris> User-Agent: KMail/4.14.10 (Linux/3.16.7-48-desktop; KDE/4.14.9; x86_64; ; ) MIME-Version: 1.0 Hi, this is an ICE present on the mainline and 6 branch, a regression introduced by r241529 which added the consistency check for boolean values. So it turns out that Ada is not the only producer of non-standard boolean types, there is even a helper function to do it in tree.c (build_nonstandard_boolean_type) and it builds even weirder boolean types than Ada since they are signed. The problem is that -1 is not considered as a valid value for them any more and this confuses VRP. Therefore the attached patch adjusts the consistency check to accept -1 instead of +1 for them. Tested on x86_64-suse-linux, OK for the mainline and 6 branch? 2016-11-23 Eric Botcazou PR middle-end/78429 * tree.h (wi::fits_to_boolean_p): New predicate. (wi::fits_to_tree_p): Use it for boolean types. * tree.c (int_fits_type_p): Likewise. 2016-11-23 Eric Botcazou * gcc.c-torture/compile/20161123-1.c: New test. Index: tree.h =================================================================== --- tree.h (revision 242632) +++ tree.h (working copy) @@ -5294,6 +5294,9 @@ wi::extended_tree ::get_len () const namespace wi { template + bool fits_to_boolean_p (const T &x, const_tree); + + template bool fits_to_tree_p (const T &x, const_tree); wide_int min_value (const_tree); @@ -5303,14 +5306,21 @@ namespace wi template bool +wi::fits_to_boolean_p (const T &x, const_tree type) +{ + return eq_p (x, 0) || eq_p (x, TYPE_UNSIGNED (type) ? 1 : -1); +} + +template +bool wi::fits_to_tree_p (const T &x, const_tree type) { - /* Short-circuit boolean types since various transformations assume that - they can only take values 0 and 1. */ + /* Non-standard boolean types can have arbitrary precision but various + transformations assume that they can only take values 0 and +/-1. */ if (TREE_CODE (type) == BOOLEAN_TYPE) - return eq_p (x, 0) || eq_p (x, 1); + return fits_to_boolean_p (x, type); - if (TYPE_SIGN (type) == UNSIGNED) + if (TYPE_UNSIGNED (type)) return eq_p (x, zext (x, TYPE_PRECISION (type))); else return eq_p (x, sext (x, TYPE_PRECISION (type))); Index: tree.c =================================================================== --- tree.c (revision 242632) +++ tree.c (working copy) @@ -9092,10 +9092,10 @@ int_fits_type_p (const_tree c, const_tre bool ok_for_low_bound, ok_for_high_bound; signop sgn_c = TYPE_SIGN (TREE_TYPE (c)); - /* Short-circuit boolean types since various transformations assume that - they can only take values 0 and 1. */ + /* Non-standard boolean types can have arbitrary precision but various + transformations assume that they can only take values 0 and +/-1. */ if (TREE_CODE (type) == BOOLEAN_TYPE) - return integer_zerop (c) || integer_onep (c); + return wi::fits_to_boolean_p (c, type); retry: type_low_bound = TYPE_MIN_VALUE (type);