From patchwork Mon Oct 24 11:39:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 78930 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp2528276qge; Mon, 24 Oct 2016 04:40:16 -0700 (PDT) X-Received: by 10.98.21.138 with SMTP id 132mr27864274pfv.38.1477309216114; Mon, 24 Oct 2016 04:40:16 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id a11si14984307pgd.80.2016.10.24.04.40.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Oct 2016 04:40:16 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-439381-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-439381-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-439381-patch=linaro.org@gcc.gnu.org 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:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=GGo41dEIB/icn+lTdeJP72lWPGY6QL6VV34GUljOVQji4JENEHZsi zKd9A5VlEnkfskQ9KuBq+vjYOW9yD2CnMM8TgPLeqvZboCFJgJXCTbVLfubIdSw4 Sxx2GKVg/1iAiPOZhSS+r6MGe/iMtFNKCJBKbI0tX1ty3x1UUck2sc= 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:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; s=default; bh=rdJlSjTNBd17rYWP0IvMfZUlj50=; b=HFkNSzBUeiRaYR3Nf+0Lywi/l8Nz o2ghNOWVNSzHND6Y7kitxyoZmK0tZkM/WkIZQUAn3IKxSWK3Nwqy+u8yfbKToxyB kJAaIViqot/Qj5+kKpSRsfzXswUpOXbdgDcU+DOAwZNkxNTdDrWVuNEiSn9604Ax IMfpVC5TrrnzAgo= Received: (qmail 3841 invoked by alias); 24 Oct 2016 11:40:01 -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 3761 invoked by uid 89); 24 Oct 2016 11:39:58 -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=MIN, avoids, Stores, to_widest 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; Mon, 24 Oct 2016 11:39:57 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 85981812E2; Mon, 24 Oct 2016 13:39:54 +0200 (CEST) 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 dMreCkZpSJHM; Mon, 24 Oct 2016 13:39:54 +0200 (CEST) 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 4C3B4812D8; Mon, 24 Oct 2016 13:39:54 +0200 (CEST) From: Eric Botcazou To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: Re: [patch] Fix PHI optimization issue with boolean types Date: Mon, 24 Oct 2016 13:39:53 +0200 Message-ID: <1842011.oP9bEcZBzd@polaris> User-Agent: KMail/4.14.10 (Linux/3.16.7-42-desktop; KDE/4.14.9; x86_64; ; ) In-Reply-To: References: <10860828.opkyFOrRK6@polaris> <1477302822.fqTdhpRWXH@polaris> MIME-Version: 1.0 > > But integer_truep is just integer_onep for BOOLEAN_TYPEs. > > Yes, but it's more descriptive IMHO. At the cost of consistency with fits_to_tree_p though. > fits_to_tree_p avoids creating an INTEGER_CST in ggc memory and thus is the > prefered way to test if you have a wide-int but not yet an INTEGER_CST. OK, I was confused by int_fits_type_p, which calls it on an INTEGER_CST (which now breaks with the additional test in the function). The attached fix seems to work and passes regression testing (all languages). * tree.h (wi::fits_to_tree_p): Accept only 0 and 1 for boolean types. * tree.c (int_fits_type_p): Likewise. Pass the integer constant as a widest_int to above. -- Eric Botcazou Index: tree.c =================================================================== --- tree.c (revision 241437) +++ tree.c (working copy) @@ -9065,8 +9065,8 @@ get_narrower (tree op, int *unsignedp_pt return win; } -/* Returns true if integer constant C has a value that is permissible - for type TYPE (an INTEGER_TYPE). */ +/* Return true if integer constant C has a value that is permissible + for TYPE, an integral type. */ bool int_fits_type_p (const_tree c, const_tree type) @@ -9075,6 +9075,11 @@ 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. */ + if (TREE_CODE (type) == BOOLEAN_TYPE) + return integer_zerop (c) || integer_truep (c); + retry: type_low_bound = TYPE_MIN_VALUE (type); type_high_bound = TYPE_MAX_VALUE (type); @@ -9154,7 +9159,7 @@ retry: } /* Or to fits_to_tree_p, if nothing else. */ - return wi::fits_to_tree_p (c, type); + return wi::fits_to_tree_p (wi::to_widest (c), type); } /* Stores bounds of an integer TYPE in MIN and MAX. If TYPE has non-constant Index: tree.h =================================================================== --- tree.h (revision 241437) +++ tree.h (working copy) @@ -5295,6 +5295,11 @@ 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. */ + if (TREE_CODE (type) == BOOLEAN_TYPE) + return x == 0 || x == 1; + if (TYPE_SIGN (type) == UNSIGNED) return eq_p (x, zext (x, TYPE_PRECISION (type))); else