From patchwork Fri Sep 14 10:42:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 969724 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-485643-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="X0H7uziv"; dkim-atps=neutral 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 42BXCS6pySz9s9h for ; Fri, 14 Sep 2018 20:42:27 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:message-id:date:mime-version:content-type; q=dns; s= default; b=b3W1TtO4bLh+qn4HZ0TfJ7YGogGls2gYeho0h+mVR2FCkYnuBOYLh urGN2HJAE3lZqTKhgRaTs+j9NCY4GXL4CmPm4ZboNwPPW5I/J5LWO0e41iGOQ/Zy 8eXYH81AP66tKGGn/7tnAZgwPH7n4JoAHsuVQr9eJ8Hv9zbZ0yO7Dg= 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 :subject:to:message-id:date:mime-version:content-type; s= default; bh=JttBqyql711ePDdfZvfwfrvPjl0=; b=X0H7uzivKvZHR+ovlVFj gFT0Mw8OA30DLn4ECg9mkGMpUmHlF9lpi8OZxAI12/uhctapa2d+OFOKhZKktAfQ NFuUDUVSTI6J2xQZeIbcmvUgiBNuFfBB9IMM8g1xSOVeEVo2gB/O8LVLYMNTyu3m bXmLs5DYOuzEbX0YMOtRaPg= Received: (qmail 26548 invoked by alias); 14 Sep 2018 10:42:19 -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 26535 invoked by uid 89); 14 Sep 2018 10:42:19 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy=wi, Hx-languages-length:1580, eq_p, HX-HELO:sk:mail-wm X-HELO: mail-wm1-f54.google.com Received: from mail-wm1-f54.google.com (HELO mail-wm1-f54.google.com) (209.85.128.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 14 Sep 2018 10:42:18 +0000 Received: by mail-wm1-f54.google.com with SMTP id q8-v6so1437256wmq.4 for ; Fri, 14 Sep 2018 03:42:17 -0700 (PDT) Received: from abulafia.quesejoda.com (247.red-79-147-188.dynamicip.rima-tde.net. [79.147.188.247]) by smtp.gmail.com with ESMTPSA id g2-v6sm14651478wrd.71.2018.09.14.03.42.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Sep 2018 03:42:15 -0700 (PDT) From: Aldy Hernandez Subject: VRP: allow unsigned truncating conversions that will fit To: gcc-patches Message-ID: Date: Fri, 14 Sep 2018 06:42:13 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 X-IsSubscribed: yes I'm still thinking about this one... Is there a subtle reason why we're avoiding unsigned truncating conversions of the form: [X, +INF] If the X fits in the new type, why can't we just build [X, +INF] in the new type? See attached patch. If there isn't, OK for trunk? commit b2e8c9baeeca3e321957d205b2c4c8b83b9bc754 Author: Aldy Hernandez Date: Fri Sep 14 12:02:42 2018 +0200 * wide-int-range.cc (wide_int_range_convert): Allow unsigned truncating conversions that will fit in the new type. diff --git a/gcc/wide-int-range.cc b/gcc/wide-int-range.cc index a85fe9f9ad7..4e323a63206 100644 --- a/gcc/wide-int-range.cc +++ b/gcc/wide-int-range.cc @@ -768,6 +768,24 @@ wide_int_range_convert (wide_int &min, wide_int &max, return (!wi::eq_p (min, wi::min_value (outer_prec, outer_sign)) || !wi::eq_p (max, wi::max_value (outer_prec, outer_sign))); } + /* Unsigned truncating conversions whose lower bound fits, but whose + upper bound is +INF can be handled straightforwardly. This will + handle things like: + + [1,+INF] (i.e. ~[0,0]) from long unsigned to unsigned short + [1000, +INF] from long unsigned to unsigned short. */ + if (inner_sign == UNSIGNED + && inner_sign == outer_sign + && inner_prec > outer_prec + && wi::le_p (vr0_min, + wi::mask (outer_prec, false, inner_prec), + UNSIGNED) + && vr0_max == wi::max_value (inner_prec, UNSIGNED)) + { + min = wide_int::from (vr0_min, outer_prec, inner_sign); + max = wi::mask (outer_prec, false, outer_prec); + return true; + } return false; }