From patchwork Thu Sep 22 19:08:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1681300 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=RrXMieFA; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MYPvZ4xtcz1yqH for ; Fri, 23 Sep 2022 05:08:42 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 76B143857827 for ; Thu, 22 Sep 2022 19:08:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 76B143857827 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663873720; bh=litkq4wwtsmrL4HfCABCHagnbXFQPBQqEbSmCS+JHdg=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=RrXMieFAwxkaR3C+zQDsgNfh1CM9LWEK+dKjtU2O66LyWoO9B0UZ/wcrgvcrOb35Q 8RinUCI09rFM3onLx1UYfWEVFreHDpIlc1o6pggx7sUnAkAWx8zUXKwgjPPdxBwfl9 V0P6HXUbDJOpCJ2HqE0VaHbjQv4mjJAyXYRurRPQ= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id D9F483857BBC for ; Thu, 22 Sep 2022 19:08:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D9F483857BBC Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-589-4pbwxBgJN4itRumFjyVsTw-1; Thu, 22 Sep 2022 15:08:19 -0400 X-MC-Unique: 4pbwxBgJN4itRumFjyVsTw-1 Received: by mail-io1-f72.google.com with SMTP id e15-20020a5d8acf000000b006a3ed059e49so1644084iot.14 for ; Thu, 22 Sep 2022 12:08:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:references:cc:to:from:content-language:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date; bh=hXuRE6j25LreGnEdkEwz1nVf8lScH46W15cf80Lmt+M=; b=upbmPTTvVsaRfoK2Z3THCH2MuulFQQnRxCfTE8vd3HDSxAjruZ1MS0vJGIv/moDjaz OYOV6XGOCyUpIYEtcLKpwPdGjIp3LJHJQ/bO5tT2UGDaLL95cRNqQPjvz30nXJ/C2BH+ PNJ33On5V84Xud18NT7H/ACYbTNe0ztINEh8ZqE0pp5bJFjVZM7CbECBw0H7BT3FHeRE MtF9Pv5vauAYsV5+iYK9tBrPU0eTCqXva4xXHLWwBBQ1gS72Q3Y62iUkoQhjqpkXzNZE ze0UBMqLAHpmANDPINH3jWlO0SpAN/gIdyni4i8xEq5Op9PyuhYl/Xu9BiCuAs0T4/vb 5igw== X-Gm-Message-State: ACrzQf3zaO7JWMuCHuFQiYb70FUr6UrcM4rCYXNlPcbhVnevRPubEM7E OgmQylwuALg/SleriHDtn1aOiiDUFXSQqvvuAZTQWy3wW8yWlUFWBYg1C7X9Fu/Ge0udLbIDZID j2t3v2dvbz0pZXL7+ukUbd+ke/xVbWylsiR/xTKTltXdY4LYP/BD39n7YmhqqAjcLJf1OIw== X-Received: by 2002:a05:6602:2d89:b0:6a3:8489:fef4 with SMTP id k9-20020a0566022d8900b006a38489fef4mr2432722iow.105.1663873698662; Thu, 22 Sep 2022 12:08:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Tz2aWgdM8NAIcnXNypt5CgxDW3q4sBrPMI5BpuduKW4AZ9BqXv+um+0q8OKCy/con2aIvIA== X-Received: by 2002:a05:6602:2d89:b0:6a3:8489:fef4 with SMTP id k9-20020a0566022d8900b006a38489fef4mr2432711iow.105.1663873698303; Thu, 22 Sep 2022 12:08:18 -0700 (PDT) Received: from ?IPV6:2607:fea8:a263:f600::3dbe? ([2607:fea8:a263:f600::3dbe]) by smtp.gmail.com with ESMTPSA id y30-20020a02731e000000b0035b0af5783dsm2472785jab.32.2022.09.22.12.08.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Sep 2022 12:08:17 -0700 (PDT) Message-ID: Date: Thu, 22 Sep 2022 15:08:16 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: [PATCH 15/17] Convert CFN_BUILT_IN_STRLEN to range-ops. To: gcc-patches References: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> In-Reply-To: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.7 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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From c750e675cb77f283ff991682db7740bc5f6d4cf4 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 20 Sep 2022 19:05:03 -0400 Subject: [PATCH 15/17] Convert CFN_BUILT_IN_STRLEN to range-ops. * gimple-range-fold.cc (range_of_builtin_int_call): Remove case for CFN_BUILT_IN_STRLEN. * gimple-range-op.cc (class cfn_strlen): New. (gimple_range_op_handler::maybe_builtin_call): Set arguments. --- gcc/gimple-range-fold.cc | 21 --------------------- gcc/gimple-range-op.cc | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index d445270417a..d22fb0e9352 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -908,27 +908,6 @@ fold_using_range::range_of_builtin_int_call (irange &r, gcall *call, return true; } - case CFN_BUILT_IN_STRLEN: - if (tree lhs = gimple_call_lhs (call)) - if (ptrdiff_type_node - && (TYPE_PRECISION (ptrdiff_type_node) - == TYPE_PRECISION (TREE_TYPE (lhs)))) - { - tree type = TREE_TYPE (lhs); - tree max = vrp_val_max (ptrdiff_type_node); - wide_int wmax - = wi::to_wide (max, TYPE_PRECISION (TREE_TYPE (max))); - tree range_min = build_zero_cst (type); - // To account for the terminating NULL, the maximum length - // is one less than the maximum array size, which in turn - // is one less than PTRDIFF_MAX (or SIZE_MAX where it's - // smaller than the former type). - // FIXME: Use max_object_size() - 1 here. - tree range_max = wide_int_to_tree (type, wmax - 2); - r.set (range_min, range_max); - return true; - } - break; default: break; } diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index 09b7dd2add3..f9161b5820f 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -611,6 +611,30 @@ cfn_ubsan op_cfn_ubsan_add (PLUS_EXPR); cfn_ubsan op_cfn_ubsan_sub (MINUS_EXPR); cfn_ubsan op_cfn_ubsan_mul (MULT_EXPR); + +// Implement range operator for CFN_BUILT_IN_STRLEN +class cfn_strlen : public range_operator +{ +public: + using range_operator::fold_range; + virtual bool fold_range (irange &r, tree type, const irange &, + const irange &, relation_kind) const + { + tree max = vrp_val_max (ptrdiff_type_node); + wide_int wmax + = wi::to_wide (max, TYPE_PRECISION (TREE_TYPE (max))); + tree range_min = build_zero_cst (type); + // To account for the terminating NULL, the maximum length + // is one less than the maximum array size, which in turn + // is one less than PTRDIFF_MAX (or SIZE_MAX where it's + // smaller than the former type). + // FIXME: Use max_object_size() - 1 here. + tree range_max = wide_int_to_tree (type, wmax - 2); + r.set (range_min, range_max); + return true; + } +} op_cfn_strlen; + // Set up a gimple_range_op_handler for any built in function which can be // supported via range-ops. @@ -711,6 +735,19 @@ gimple_range_op_handler::maybe_builtin_call () m_int = &op_cfn_ubsan_mul; break; + case CFN_BUILT_IN_STRLEN: + { + tree lhs = gimple_call_lhs (call); + if (lhs && ptrdiff_type_node && (TYPE_PRECISION (ptrdiff_type_node) + == TYPE_PRECISION (TREE_TYPE (lhs)))) + { + m_op1 = gimple_call_arg (call, 0); + m_valid = true; + m_int = &op_cfn_strlen; + } + break; + } + default: break; } -- 2.37.3