From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 033493833031 for ; Thu, 13 May 2021 18:02:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 033493833031 Received: from mail-vs1-f69.google.com (mail-vs1-f69.google.com [209.85.217.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-550-p301PwUMOWCGOtKbdODorg-1; Thu, 13 May 2021 14:02:22 -0400 X-MC-Unique: p301PwUMOWCGOtKbdODorg-1 Received: by mail-vs1-f69.google.com with SMTP id l6-20020a67d5060000b0290228235bc72dso12324474vsj.13 for ; Thu, 13 May 2021 11:02:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=5KlNe6VCWHLr29hMPWPcrpoYcNGvG1T3zt8KeoHcr4I=; b=oJzYoLv0nQbMdnH4/ccRG3VYedYfFkn8Z4Uvr6K2ra5XO4wxFjt0DoxBEGGO1bNf+w 4qekL5b3vqHwYwqrTiEtuRQ5iJWwNRhGFMePv/7wFd2dev30gCAw5rcXdtckbzue4iQf CdN4n+mQOzfm38cSEPNHfi+JtPZKper6+XG5pYHf4acAAroF+B0enNaEx1d5BlkBYihr kY918eLu0IphEv7lnB+uoxIYXsyWeq7dv548ZxDGrdCQMMHtElKxzdM+QElfHwV1mFQ8 8mE9XRJy9g3sgmTCzyXIOmwhBSswQQvRXl8JhWBqg8GxE9EavEsyphPuc8GlKSptKvQZ jy3w== X-Gm-Message-State: AOAM532VIrQC6N/wgGs33VYqD6bp4fFihKaeydMp+acwVU1e41932761 z8JoS7RKomAYJcpcRsyZBkYELH+c9R6vWyd+JPOQKVac3/7ZtDLl+8M5LpjCtB4lN45ZCoArgK3 O7SykC0NRCbDYQ+hTxyTKDhofi8pz1sUW/P9ucLcposaIUo1kNmRCiFThk+Jki9WbcQ== X-Received: by 2002:a67:df85:: with SMTP id x5mr32128067vsk.9.1620928940673; Thu, 13 May 2021 11:02:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyyZ0OXnU8SK4yv7d11G5vA4BR8PyeiPrHQ27rQFX5yS1lDRCg0MgxWyyx8I0OCS9IT50lrNw== X-Received: by 2002:a67:df85:: with SMTP id x5mr32128029vsk.9.1620928940382; Thu, 13 May 2021 11:02:20 -0700 (PDT) Received: from abulafia.quesejoda.com (c-66-176-109-152.hsd1.fl.comcast.net. [66.176.109.152]) by smtp.gmail.com with ESMTPSA id f18sm442070uac.10.2021.05.13.11.00.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 May 2021 11:00:51 -0700 (PDT) Subject: Re: [PUSHED] Skip out on processing __builtin_clz when varying. To: Jakub Jelinek Cc: GCC patches References: <20210512210059.301816-1-aldyh@redhat.com> <20210512210848.GB1179226@tucnak> From: Aldy Hernandez Message-ID: <2c4fba96-62e7-7059-493f-a6be479754c0@redhat.com> Date: Thu, 13 May 2021 14:00:50 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210512210848.GB1179226@tucnak> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="------------6496E7007EA4900B9DC4431C" Content-Language: en-US X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-List-Received-Date: Thu, 13 May 2021 18:02:25 -0000 This is a multi-part message in MIME format. --------------6496E7007EA4900B9DC4431C Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 5/12/21 5:08 PM, Jakub Jelinek wrote: > On Wed, May 12, 2021 at 05:01:00PM -0400, Aldy Hernandez via Gcc-patches wrote: >> >> PR c/100521 >> * gimple-range.cc (range_of_builtin_call): Skip out on >> processing __builtin_clz when varying. >> --- >> gcc/gimple-range.cc | 2 +- >> gcc/testsuite/gcc.dg/pr100521.c | 8 ++++++++ >> 2 files changed, 9 insertions(+), 1 deletion(-) >> create mode 100644 gcc/testsuite/gcc.dg/pr100521.c >> >> --- /dev/null >> +++ b/gcc/testsuite/gcc.dg/pr100521.c >> @@ -0,0 +1,8 @@ >> +/* { dg-do compile } */ >> +/* { dg-options "-O2" } */ >> + >> +int >> +__builtin_clz (int a) > > Is this intentional? People shouldn't be redefining builtins... Ughhh. I don't think that's intentional. For that matter, the current nor the old code is designed to deal with this, especially in this case when the builtin is being redefined with incompatible arguments. That is, the above "builtin" has a signed integer as an argument, whereas the original builtin had an unsigned one. In looking at the original vr-values code, I think this could use a cleanup. First, ranges from range_of_expr are always numeric so we should adjust. Also, the checks for non-zero were assuming the argument was unsigned, which in the above redirect is clearly not. I've cleaned this up, so that it works either way, though perhaps we should _also_ bail on non-builtins. I don't know...this is before my time. BTW, I've removed the following annoying idiom: - int newmini = prec - 1 - wi::floor_log2 (r.upper_bound ()); - if (newmini == prec) This is really a check for r.upper_bound() == 0, as floor_log2(0) returns -1. It's confusing. How does this look? For reference, the original code where this all came from is 82b6d25d289195. Thanks for pointing this out. Aldy --------------6496E7007EA4900B9DC4431C Content-Type: text/x-patch; charset=UTF-8; name="0001-Cleanup-clz-and-ctz-code-in-range_of_builtin_call.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Cleanup-clz-and-ctz-code-in-range_of_builtin_call.patch" >From f8a958e8028ed129558f9ad7ccf423c834d377bd Mon Sep 17 00:00:00 2001 From: Aldy Hernandez Date: Thu, 13 May 2021 13:47:41 -0400 Subject: [PATCH] Cleanup clz and ctz code in range_of_builtin_call. gcc/ChangeLog: * gimple-range.cc (range_of_builtin_call): Cleanup clz and ctz code. --- gcc/gimple-range.cc | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc index 5b288d8e6a7..b33ba1c8099 100644 --- a/gcc/gimple-range.cc +++ b/gcc/gimple-range.cc @@ -736,33 +736,29 @@ range_of_builtin_call (range_query &query, irange &r, gcall *call) } query.range_of_expr (r, arg, call); - // From clz of minimum we can compute result maximum. - if (r.constant_p () && !r.varying_p ()) + if (!r.undefined_p ()) { - int newmaxi = prec - 1 - wi::floor_log2 (r.lower_bound ()); - // Argument is unsigned, so do nothing if it is [0, ...] range. - if (newmaxi != prec) + // From clz of minimum we can compute result maximum. + if (wi::gt_p (r.lower_bound (), 0, TYPE_SIGN (r.type ()))) + { + maxi = prec - 1 - wi::floor_log2 (r.lower_bound ()); + if (mini == -2) + mini = 0; + } + else if (!range_includes_zero_p (&r)) { mini = 0; - maxi = newmaxi; + maxi = prec - 1; } - } - else if (!range_includes_zero_p (&r)) - { - maxi = prec - 1; - mini = 0; - } - if (mini == -2) - break; - // From clz of maximum we can compute result minimum. - if (r.constant_p ()) - { - int newmini = prec - 1 - wi::floor_log2 (r.upper_bound ()); - if (newmini == prec) + if (mini == -2) + break; + // From clz of maximum we can compute result minimum. + wide_int max = r.upper_bound (); + int newmini = prec - 1 - wi::floor_log2 (max); + if (max == 0) { - // Argument range is [0, 0]. If CLZ_DEFINED_VALUE_AT_ZERO - // is 2 with VALUE of prec, return [prec, prec], otherwise - // ignore the range. + // If CLZ_DEFINED_VALUE_AT_ZERO is 2 with VALUE of prec, + // return [prec, prec], otherwise ignore the range. if (maxi == prec) mini = prec; } @@ -803,7 +799,8 @@ range_of_builtin_call (range_query &query, irange &r, gcall *call) query.range_of_expr (r, arg, call); if (!r.undefined_p ()) { - if (r.lower_bound () != 0) + // If arg is non-zero, then use [0, prec - 1]. + if (!range_includes_zero_p (&r)) { mini = 0; maxi = prec - 1; -- 2.31.1 --------------6496E7007EA4900B9DC4431C--