From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by sourceware.org (Postfix) with ESMTPS id A64DB382EF35 for ; Tue, 15 Nov 2022 07:15:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A64DB382EF35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-x230.google.com with SMTP id z24so16366758ljn.4 for ; Mon, 14 Nov 2022 23:15:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=XHLUQvR0ypFuAdFFBO8H2Qx/Pg+SRltq7r8+nTvu3Dk=; b=BHEdYE7gLooCj8CnGzRX/vVlmXu/Ox2mhLHvmpC8QISL5+DWex6s6zQ1lWcV4W8HQS KqX/yNrfIhjUjmNY8acmMWjK+xMJ/lgUHCldkic77bDJkaFTEigwyBa4+PlIK3bgMsNz ASEHigDZTh9lBWyis7ltq2HIx4sb3GuGVWJW0odN+Z1we875h594mKikLqzC/O7e37XE wOIsbX2RTSdA4qglIRMKyJ1Bvwq++/kczssddvtloO9/d5HkS4v0LsFAaoaQeG/qqQkv 09bwuSj/VRv82LBpn2JQ9xdGEbMOyUjIYtPpYK0igY2ctLOKMEjW4/Vwfc/r+FoACRnu kv3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=XHLUQvR0ypFuAdFFBO8H2Qx/Pg+SRltq7r8+nTvu3Dk=; b=Nb4yDk1ZDGWWVZgU6UzTvDLV2EiLi33XTB5CCr8CeovFrducVOSZ3eFyRrHgYpf6hv 3RCHS4mW7TUqaiWcPGb3pHgPyfBw5fA/xIgonYXWezsdaSQhWo+UA1FM/Rc5YNaD2Bap R2e0JBEmgk+XVdCGx807nVhKhALbDkzFfKOYiYZBARNPSXb8J0C7PH0wQXVBy2UX9wQU +Rk9XrEMPKjou7c8qix+GlOla932Kyk+8F8Z/n9iH3rywX4/oIcpRUG7uXGD4QEh4xcy sZ3gwhTIX4RYXvMtt6lu4QGlp6oPCfGiVlv5Ksr7nPh7hWFipLjrxSXH7ARanDwEZ3A5 FI3g== X-Gm-Message-State: ANoB5pl6pdG2ph7onMJyRs2Uoa9Und7o6uty9GIujSQ+5FvTZ1wBKfBv 7ZmjCrYfwyf6TQ5ELHyuQcGr2WS+vjvsZwjXFSI= X-Google-Smtp-Source: AA0mqf6IuhPAfpY5pxAmrsnnLk9P1OnX+eFEwMta4y4q087WwQ35loaTz1qemK/V+YzXcRleLPvlQu7t3gKDxy1kh8o= X-Received: by 2002:a2e:94cb:0:b0:26e:2bda:1821 with SMTP id r11-20020a2e94cb000000b0026e2bda1821mr5701724ljh.241.1668496537665; Mon, 14 Nov 2022 23:15:37 -0800 (PST) MIME-Version: 1.0 References: <20221112183048.389811-1-aldyh@redhat.com> <1ea5fc0e-fcc4-a354-b71b-3da3008ea5f2@redhat.com> In-Reply-To: <1ea5fc0e-fcc4-a354-b71b-3da3008ea5f2@redhat.com> From: Richard Biener Date: Tue, 15 Nov 2022 08:15:25 +0100 Message-ID: Subject: Re: [PATCH] [PR68097] Try to avoid recursing for floats in tree_*_nonnegative_warnv_p. To: Aldy Hernandez Cc: GCC patches , Andrew MacLeod , richard.sandiford@arm.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 List-Id: On Mon, Nov 14, 2022 at 8:05 PM Aldy Hernandez wrote: > > > > On 11/14/22 10:12, Richard Biener wrote: > > On Sat, Nov 12, 2022 at 7:30 PM Aldy Hernandez wrote: > >> > >> It irks me that a PR named "we should track ranges for floating-point > >> hasn't been closed in this release. This is an attempt to do just > >> that. > >> > >> As mentioned in the PR, even though we track ranges for floats, it has > >> been suggested that avoiding recursing through SSA defs in > >> gimple_assign_nonnegative_warnv_p is also a goal. We can do this with > >> various ranger components without the need for a heavy handed approach > >> (i.e. a full ranger). > >> > >> I have implemented two versions of known_float_sign_p() that answer > >> the question whether we definitely know the sign for an operation or a > >> tree expression. > >> > >> Both versions use get_global_range_query, which is a wrapper to query > >> global ranges. This means, that no caching or propagation is done. > >> In the case of an SSA, we just return the global range for it (think > >> SSA_NAME_RANGE_INFO). In the case of a tree code with operands, we > >> also use get_global_range_query to resolve the operands, and then call > >> into range-ops, which is our lowest level component. There is no > >> ranger or gori involved. All we're doing is resolving the operation > >> with the ranges passed. > >> > >> This is enough to avoid recursing in the case where we definitely know > >> the sign of a range. Otherwise, we still recurse. > >> > >> Note that instead of get_global_range_query(), we could use > >> get_range_query() which uses a ranger (if active in a pass), or > >> get_global_range_query if not. This would allow passes that have an > >> active ranger (with enable_ranger) to use a full ranger. These passes > >> are currently, VRP, loop unswitching, DOM, loop versioning, etc. If > >> no ranger is active, get_range_query defaults to global ranges, so > >> there's no additional penalty. > >> > >> Would this be acceptable, at least enough to close (or rename the PR ;-))? > > > > I think the checks would belong to the gimple_stmt_nonnegative_warnv_p function > > only (that's the SSA name entry from the fold-const.cc ones)? > > That was my first approach, but I thought I'd cover the unary and binary > operators as well, since they had other callers. But I'm happy with > just the top-level tweak. It's a lot less code :). @@ -9234,6 +9235,15 @@ bool gimple_stmt_nonnegative_warnv_p (gimple *stmt, bool *strict_overflow_p, int depth) { + tree type = gimple_range_type (stmt); + if (type && frange::supports_p (type)) + { + frange r; + bool sign; + return (get_global_range_query ()->range_of_stmt (r, stmt) + && r.signbit_p (sign) + && sign == false); + } the above means we never fall through to the switch below if frange::supports_p (type) - that's eventually good enough, I don't think we ever call this very function directly but it gets invoked via recursion through operands only. But of course I wonder what types are not supported by frange and whether the manual processing we fall through to does anything meaningful for those? I won't ask you to thoroughly answer this now but please put in a comment reflecting the above before the switch stmt. switch (gimple_code (stmt)) Otherwise OK, in case you tree gets back to bootstrapping ;) > > > > I also notice the use of 'bool' for the "sign". That's not really > > descriptive. We > > have SIGNED and UNSIGNED (aka enum signop), not sure if that's the > > perfect match vs. NEGATIVE and NONNEGATIVE. Maybe the functions > > name is just bad and they should be known_float_negative_p? > > The bool sign is to keep in line with real.*, and was suggested by Jeff > (in real.* not here). I'm happy to change the entire frange API to use > sgnop. It is cleaner. If that's acceptable, I could do that as a > follow-up. > > How's this, pending tests once I figure out why my trees have been > broken all day :-/. > > Aldy > > p.s. First it was sphinx failure, now I'm seeing this: > /home/aldyh/src/clean/gcc/match.pd:7935:8 error: return statement not > allowed in C expression > return NULL_TREE; > ^ Supposedly somebody pushed and reverted this transient error? Yep, Tamar did. Richard.