From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x12b.google.com (mail-il1-x12b.google.com [IPv6:2607:f8b0:4864:20::12b]) by sourceware.org (Postfix) with ESMTPS id E625438582BC for ; Fri, 29 Sep 2023 20:17:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E625438582BC 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-il1-x12b.google.com with SMTP id e9e14a558f8ab-3515aad4a87so20109575ab.3 for ; Fri, 29 Sep 2023 13:17:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696018678; x=1696623478; darn=gcc.gnu.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=SliKCv0LI7I72uQX/wtjDF7ha6qIEZMnQCkaVMzFb6c=; b=hXtjucScSodP5b6RRnkNCxaldvBZ/tuNtZdHQft0e3CGt9bLR5pk2r0yy7WhXLUc/Y kzX4TJ4/sdHI8GpJggEWBbA99sMTtunBOcoWsrB8yYy0qXcw/AnuqOcRfmeAgxg62IHX 684Gof1/11fLQiaNT48vUxtqgRONz1rSoIjybXuRjI80f2jNosP+0zVCx1z1hqUbh3dD wWXhRLse/p/vFKUz6hCAFyRjR6fwPJxssjCql+ZjQP9JHyunyFzFddlpt4gy3FnkAmCo mgvS9sKlwtMbc3bx+AsVPdGkIS0jIWqATrdFUs2LfXvnPzvA6ClQJOMMGK/0yN4v9rIN +8jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696018678; x=1696623478; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SliKCv0LI7I72uQX/wtjDF7ha6qIEZMnQCkaVMzFb6c=; b=Y1arb/ldaLwTX1dJd8rS+vyMqljo+E2gGLj8G1cWwjgFK778FAgl6JDZQPKFkxEY06 V1WyexdqiwS8QkJjx34WnKYh0fTfoyQmloqbqVaRCV1TfWbWw/qynsolHTxyeSD7GJ7z mT5Aki+tXesuKkDHnm8CDwYXLLaa/ps5PcNqHQh9p6H/cOnWAFzgSxTSYfuo3MQ30wWz 4WSjwHD4J03uyxDT1HpJcE/IZCEZXx3YXnN4lwCoWU+1WOJi42AmwOQhkPVhAEmi4VKc mNz2fnuB6X4FB60OUdk1kTYEAZR15fww6LE3Ij9oV9kiAl8O4NucFL0KgnlZ3gJFj9D1 /AEA== X-Gm-Message-State: AOJu0Yyj+5RNl/TRAmxsQtT7Rk0h7GsR1Unjoi2ZMibs8JN80999kSoc olYf2Yp4z9hYLJcy1qp+E+A= X-Google-Smtp-Source: AGHT+IEPxz/w4aIhuldlR9c/VduIJ1aVAEuctFwghYEhk+BB4at1CERgBbZyJUh+cKv/ThONAB8TqQ== X-Received: by 2002:a05:6e02:11ae:b0:350:b7a9:514b with SMTP id 14-20020a056e0211ae00b00350b7a9514bmr4593696ilj.8.1696018677912; Fri, 29 Sep 2023 13:17:57 -0700 (PDT) Received: from [172.31.0.109] ([136.36.130.248]) by smtp.gmail.com with ESMTPSA id z3-20020a92d183000000b0034f1bb427dbsm5821086ilz.60.2023.09.29.13.17.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 29 Sep 2023 13:17:57 -0700 (PDT) Message-ID: Date: Fri, 29 Sep 2023 14:17:56 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/2] VR-VALUES: Rewrite test_for_singularity using range_op_handler Content-Language: en-US To: Andrew Pinski Cc: Andrew Pinski , gcc-patches@gcc.gnu.org References: <20230901173059.791894-1-apinski@marvell.com> <20230901173059.791894-2-apinski@marvell.com> <23a3e21c-eae5-44d0-8e66-65ada10a9c4d@gmail.com> From: Jeff Law In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,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 9/5/23 01:12, Andrew Pinski wrote: > On Mon, Sep 4, 2023 at 11:06 PM Jeff Law via Gcc-patches > wrote: >> >> >> >> On 9/1/23 11:30, Andrew Pinski via Gcc-patches wrote: >>> So it turns out there was a simplier way of starting to >>> improve VRP to start to fix PR 110131, PR 108360, and PR 108397. >>> That was rewrite test_for_singularity to use range_op_handler >>> and Value_Range. >>> >>> This patch implements that and >>> >>> OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. >>> >>> gcc/ChangeLog: >>> >>> * vr-values.cc (test_for_singularity): Add edge argument >>> and rewrite using range_op_handler. >>> (simplify_compare_using_range_pairs): Use Value_Range >>> instead of value_range and update test_for_singularity call. >>> >>> gcc/testsuite/ChangeLog: >>> >>> * gcc.dg/tree-ssa/vrp124.c: New test. >>> * gcc.dg/tree-ssa/vrp125.c: New test. >>> --- >> >>> diff --git a/gcc/vr-values.cc b/gcc/vr-values.cc >>> index 52ab4fe6109..2474e57ee90 100644 >>> --- a/gcc/vr-values.cc >>> +++ b/gcc/vr-values.cc >>> @@ -904,69 +904,33 @@ simplify_using_ranges::simplify_bit_ops_using_ranges >>> } >>> >>> /* We are comparing trees OP1 and OP2 using COND_CODE. OP1 has >>> - a known value range VR. >>> + a known value range OP1_RANGE. >>> >>> If there is one and only one value which will satisfy the >>> - conditional, then return that value. Else return NULL. >>> - >>> - If signed overflow must be undefined for the value to satisfy >>> - the conditional, then set *STRICT_OVERFLOW_P to true. */ >>> + conditional on the EDGE, then return that value. >>> + Else return NULL. */ >>> >>> static tree >>> test_for_singularity (enum tree_code cond_code, tree op1, >>> - tree op2, const value_range *vr) >>> + tree op2, const int_range_max &op1_range, bool edge) >>> { >>> - tree min = NULL; >>> - tree max = NULL; >>> - >>> - /* Extract minimum/maximum values which satisfy the conditional as it was >>> - written. */ >>> - if (cond_code == LE_EXPR || cond_code == LT_EXPR) >>> + /* This is already a singularity. */ >>> + if (cond_code == NE_EXPR || cond_code == EQ_EXPR) >>> + return NULL; >> I don't think this is necessarily the right thing to do for NE. >> >> Consider if op1 has the range [0,1] and op2 has the value 1. If the >> code is NE, then we should be able to return a singularity of 0 since >> that's the only value for x where x ne 1 is true given the range for x. > > The "false" edge singularity is already known when NE is supplied. I > don't think changing it to the "true" edge singularity will be helpful > all of the time; preferring the value of 0 is a different story. > But that is a different patch and for a different location rather than > inside VRP; it should be in either isel or expand (more likely isel). I forgot something critically important here. Specifically, this code is supposed to be subsumed by Ranger. The whole point of this routine is to rewrite to EQ/NE comparisons so that we can expose equivalences on the true/false arm of the conditional (and NE is just as important as EQ). It's not really about preferring any particular value like 0. The problem with this routine is it loses information after the code has been transformed. Let's say we had a test x < 4. If we assume that VRP is able to prove X doesn't have any of the values [MIN..3], then we can change the test to x == 4 and propagate 4 for any uses of X in the true arm. But on the false ARM we end up with x != 4 which is a wider range than [5..MAX]. So if we were to instantiate a new Ranger after the transformation we'd lose information on the false arm. More importantly, I think the transformation was bad for either SCEV or loop iteration analysis. When Andrew, Aldy and I kicked this problem around the consensus was that Ranger should find and propagate the equivalence, including making it visible to jump threading. That should make the rewriting totally unnecessary. So the net is we really ought to be doing here is looking for cases where this code actually helps code generation and if it does we need to understand how/why as this code is supposed to go away. Given you're already poking around in here, you might have such cases handy :-) If you do, I'm sure Andrew, Aldy and I would love to see them. jeff