From patchwork Fri Jun 9 16:37:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 70834 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E37903857708 for ; Fri, 9 Jun 2023 16:38:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E37903857708 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686328694; bh=4MLgvbgEJkq18bs0bw+ZikrmJ/AdAlRMd+aCykrbiLQ=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=rAIua6fUvDoJFlshCKOedQWTN0Bqm33zf8gEg8ziQktti1TaoaN9worKIb3JxAFY7 0kgaicelij3PTDGkc/IyXbB4+HpgZQ1o5+wjUNyBLOxxlPs8FzswsTAT38DheL2Md0 XRGoO/RDFvpU7//9c30Z+2SBtrylBH639tyy+JR0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 7AF4D3856609 for ; Fri, 9 Jun 2023 16:37:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7AF4D3856609 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-32-hCbYS1N3OUOlamnxcEOzSg-1; Fri, 09 Jun 2023 12:37:43 -0400 X-MC-Unique: hCbYS1N3OUOlamnxcEOzSg-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-626253ba086so21650216d6.2 for ; Fri, 09 Jun 2023 09:37:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686328662; x=1688920662; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zDcfYqF3/8QsdeV/TQoxIPRJVMxKVo4xbBhkIBcddnY=; b=ZyTd9rwvku+nc/tCKNeQMfWkxXrikTJtv6u48zSIDoz7BDJKethljDeJ77WwvUl1ML hGkMpoWzBr9hAgPvlTwx3NP/ZRZT30kCisekZyQ9Et51jdTPRW9kteBfY08NQAFfotHC B21HPAcHNv+cYdnt84erq77jqwr6tM0HEFEc4f1pW2hZlB7QZaUG1j9gQGw8667AJz1X xhu9OESl8ZfyuWFIQQ9Ya38I6dZ/b3sBhDgDlqO3M7UJpj3/IHagGevm8QKJ13DuaQ3/ 81A3UwwKpIA62YS5dhvPAu72tAro9SRSyDv5RlV1IVdjK6WmO23WHbTUprqupnEtzZK6 YaIg== X-Gm-Message-State: AC+VfDzc99PnvopE+DWbQQ5zyq13Mx++rKzCyo0tVZwd87gC+Pcu8t1o uqlKQznrbePjkcedJP7oAr7FYYv+QDxCRGD3rM/DhqyzJxmyKwsKxTH3XBNbZIpx0YR0d41V+Dl slFAFwJT+iVx/IT/XecrUDTTOSQudKqvgbGuW1RsoBzVDy0YJPgvIPz00DS2Wy9qu15xWNZUKvl inbQ== X-Received: by 2002:a05:6214:b62:b0:626:199e:1b7d with SMTP id ey2-20020a0562140b6200b00626199e1b7dmr2462405qvb.61.1686328662515; Fri, 09 Jun 2023 09:37:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4UGBJVohbMj/77Ve8UxzUtxOh1OKHz0FlNzKJiNsmob8XEVcMjdT/hhteLg8DFVR5fwDtZ3w== X-Received: by 2002:a05:6214:b62:b0:626:199e:1b7d with SMTP id ey2-20020a0562140b6200b00626199e1b7dmr2462387qvb.61.1686328662231; Fri, 09 Jun 2023 09:37:42 -0700 (PDT) Received: from ?IPV6:2607:fea8:51df:4200::ca58? ([2607:fea8:51df:4200::ca58]) by smtp.gmail.com with ESMTPSA id y13-20020a0cec0d000000b005dd8b934579sm1271318qvo.17.2023.06.09.09.37.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Jun 2023 09:37:41 -0700 (PDT) Message-ID: Date: Fri, 9 Jun 2023 12:37:40 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 To: gcc-patches Cc: "hernandez, aldy" Subject: [COMMITTED] Relocate range_cast to header, and add a generic version. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" THis patch moves range_cast into the header file and makes it inlinable.  I also added a trap so that if you try to cast into an unsupported type, it traps.  It can't return a value of the correct type, so the caller needs to be doing something else... Such as using the new variant of range_cast provided here which uses a Value_Range.  This is the malleable range type and it first sets the type appropriately.   This will also work for unsupported types, and will assist with things like  float to int casts and vice versa. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From de03afe3168db7e2eb2a594293c846188a1b5be8 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Wed, 31 May 2023 17:02:00 -0400 Subject: [PATCH 1/2] Relocate range_cast to header, and add a generic version. Make range_cast inlinable by moving it to the header file. Also trap if the destination is not capable of representing the cast type. Add a generic version which can change range classes.. ie float to int. * range-op.cc (range_cast): Move to... * range-op.h (range_cast): Here and add generic a version. --- gcc/range-op.cc | 18 ------------------ gcc/range-op.h | 44 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/gcc/range-op.cc b/gcc/range-op.cc index 4d122de3026..44a95b20ffa 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -4929,24 +4929,6 @@ pointer_table::pointer_table () set (BIT_XOR_EXPR, op_bitwise_xor); } -// Cast the range in R to TYPE. - -bool -range_cast (vrange &r, tree type) -{ - Value_Range tmp (r); - Value_Range varying (type); - varying.set_varying (type); - range_op_handler op (CONVERT_EXPR, type); - // Call op_convert, if it fails, the result is varying. - if (!op || !op.fold_range (r, type, tmp, varying)) - { - r.set_varying (type); - return false; - } - return true; -} - #if CHECKING_P #include "selftest.h" diff --git a/gcc/range-op.h b/gcc/range-op.h index 7af58736c3f..2abec3299ef 100644 --- a/gcc/range-op.h +++ b/gcc/range-op.h @@ -216,7 +216,49 @@ protected: range_operator *m_operator; }; -extern bool range_cast (vrange &, tree type); +// Cast the range in R to TYPE if R supports TYPE. + +inline bool +range_cast (vrange &r, tree type) +{ + gcc_checking_assert (r.supports_type_p (type)); + Value_Range tmp (r); + Value_Range varying (type); + varying.set_varying (type); + range_op_handler op (CONVERT_EXPR, type); + // Call op_convert, if it fails, the result is varying. + if (!op || !op.fold_range (r, type, tmp, varying)) + { + r.set_varying (type); + return false; + } + return true; +} + +// Range cast which is capable of switching range kinds. +// ie for float to int. + +inline bool +range_cast (Value_Range &r, tree type) +{ + Value_Range tmp (r); + Value_Range varying (type); + varying.set_varying (type); + + // Ensure we are in the correct mode for the call to fold. + r.set_type (type); + + range_op_handler op (CONVERT_EXPR, type); + // Call op_convert, if it fails, the result is varying. + if (!op || !op.fold_range (r, type, tmp, varying)) + { + r.set_varying (type); + return false; + } + return true; +} + + extern void wi_set_zero_nonzero_bits (tree type, const wide_int &, const wide_int &, wide_int &maybe_nonzero, -- 2.40.1