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.129.124]) by sourceware.org (Postfix) with ESMTPS id 580983858D28 for ; Fri, 12 Aug 2022 13:38:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 580983858D28 Received: from mail-io1-f69.google.com (mail-io1-f69.google.com [209.85.166.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-615-GOG6BKnbOmybV3uGOlnPQw-1; Fri, 12 Aug 2022 09:38:27 -0400 X-MC-Unique: GOG6BKnbOmybV3uGOlnPQw-1 Received: by mail-io1-f69.google.com with SMTP id v5-20020a5d9405000000b0067c98e0011dso554690ion.1 for ; Fri, 12 Aug 2022 06:38:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=JN0gfqLSx0y1SLOcw+yZhwtcne8FXYRkvxZnNpsNAFo=; b=xW+PxacyGkimP6RFG0stImxvwrhJ+ERhnKsdaiXmcPjJtsGFez1tRx2aQTJ1C6fVIG 8x/452Wz4to7HDxaYEaU2b/lff9oqrj40W5Yxis6vc/drutanAAXctE0fuKFp+N3y6sj U5e9VBb9akxScE1gqPGk6D6Mtl8AHzLm/kYnBPNrq0z2hJSCw+hNv6+FN9ovL40JWHCu 3JjL/ecZOiOU9/N/Gt6AGt8AGZ0xQ1N6++g3I65jg+1nH8vRDuH7JvOpay6fCxqaGJMF xYi/7W3hU9Oq70fm58RB9FtoN1qqv02zZ58GLMhYZdstD80juk2nLjdhs42ySRypknke pXmw== X-Gm-Message-State: ACgBeo0ZA1Id93oqu42E3pN4DZeb4s+xxkxitiEDbuEQLNLKD3xnYZvQ EQ6+OEkpTmH0HD5jubrcx8LgJVhTlVhdblL6uc1XE89H9cZx60aazwfndKfNxV8bar/iciN/I30 lHo8lzzYnyaqrR+lZhQ== X-Received: by 2002:a05:6e02:1d0f:b0:2dd:fae5:b63b with SMTP id i15-20020a056e021d0f00b002ddfae5b63bmr1861298ila.49.1660311506495; Fri, 12 Aug 2022 06:38:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR7ejD5H+N2IJ2a39VmRUemHyjpEkPAVSN0alY8J4KTWKXeRXejwAPwHSYF/g/2/zyvT+LJ3cg== X-Received: by 2002:a05:6e02:1d0f:b0:2dd:fae5:b63b with SMTP id i15-20020a056e021d0f00b002ddfae5b63bmr1861276ila.49.1660311506062; Fri, 12 Aug 2022 06:38:26 -0700 (PDT) Received: from [192.168.0.135] ([192.24.49.145]) by smtp.gmail.com with ESMTPSA id ca18-20020a0566381c1200b003428b9ba483sm1002499jab.21.2022.08.12.06.38.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Aug 2022 06:38:24 -0700 (PDT) Message-ID: <1d535caf-2451-b648-08ad-51776bc35ab8@redhat.com> Date: Fri, 12 Aug 2022 09:38:25 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH] tree-optimization/106593 - fix ICE with backward threading To: Aldy Hernandez , Richard Biener Cc: gcc-patches References: <20220812105937.227C413305@imap2.suse-dmz.suse.de> From: Andrew MacLeod In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, 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-List-Received-Date: Fri, 12 Aug 2022 13:38:34 -0000 On 8/12/22 07:31, Aldy Hernandez wrote: > On Fri, Aug 12, 2022 at 12:59 PM Richard Biener wrote: >> With the last re-org I failed to make sure to not add SSA names >> nor supported by ranger into m_imports which then triggers an >> ICE in range_on_path_entry because range_of_expr returns false. I've >> noticed that range_on_path_entry does mightly complicated things >> that don't make sense to me and the commentary might just be >> out of date. For the sake of it I replaced it with range_on_entry >> and statistics show we thread _more_ jumps with that, so better >> not do magic there. > Hang on, hang on. range_on_path_entry was written that way for a > reason. Andrew and I had numerous discussions about this. For that > matter, my first implementation did exactly what you're proposing, but > he had reservations about using range_on_entry, which IIRC he thought > should be removed from the (public) API because it had a tendency to > blow up lookups. > > Let's wait for Andrew to chime in on this. If indeed the commentary > is out of date, I would much rather use range_on_entry like you > propose, but he and I have fought many times about this... over > various versions of the path solver :). The original issue with range-on-entry is one needed to be very careful with it.  If you ask for range-on-entry of something which is not dominated by the definition, then the cache filling walk was getting filled all the way back to the top of the IL, and that was both a waste of time and memory., and in some pathological cases was outrageous.  And it was happening more frequently than one imagines... even if accidentally.  I think the most frequent accidental misuse we saw was calling range on entry for a def within the block, or a PHI for the block. Its a legitimate issue for used before defined cases, but there isnt much we can do about those anyway, range_of_expr on any stmt within a block, when the definition comes from outside he block causes ranger to trigger its internal range-on-entry "more safely", which is why it didn't need to be part of the API... but i admit it does cause some conniptions when for instance there is no stmt in the block. That said, the improvements since then to the cache to be able to always use dominators, and selectively update the cache at strategic locations probably removes most issues with it. That plus we're more careful about timing things these days to make sure something horrid isn't introduced.  I also notice all my internal range_on_entry and _exit routines have evolved and are much cleaner than they once were. So. now that we are sufficiently mature in this space...  I think we can promote range_on_entry and range_on_exit to full public API..  It does seem that there is some use practical use for them. Andrew PS. It might even be worthwhile to add an assert to make sure it isnt being called on the def block.. just to avoid that particular stupidty :-)   I'll take care of doing this. > For now I would return VARYING in range_on_path_entry if range_of_expr > returns false. We shouldn't be ICEing when we can gracefully handle > things. This gcc_unreachable was there to catch implementation issues > during development. > > I would keep your gimple_range_ssa_p check regardless. No sense doing > extra work if we're absolutely sure we won't handle it. > > Aldy > >> Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. >> >> Will push if that succeeds. >> >> PR tree-optimization/106593 >> * tree-ssa-threadbackward.cc (back_threader::find_paths): >> If the imports from the conditional do not satisfy >> gimple_range_ssa_p don't try to thread anything. >> * gimple-range-path.cc (range_on_path_entry): Just >> call range_on_entry. >> --- >> gcc/gimple-range-path.cc | 33 +-------------------------------- >> gcc/tree-ssa-threadbackward.cc | 6 +++++- >> 2 files changed, 6 insertions(+), 33 deletions(-) >> >> diff --git a/gcc/gimple-range-path.cc b/gcc/gimple-range-path.cc >> index b6148eb5bd7..a7d277c31b8 100644 >> --- a/gcc/gimple-range-path.cc >> +++ b/gcc/gimple-range-path.cc >> @@ -153,38 +153,7 @@ path_range_query::range_on_path_entry (vrange &r, tree name) >> { >> gcc_checking_assert (defined_outside_path (name)); >> basic_block entry = entry_bb (); >> - >> - // Prefer to use range_of_expr if we have a statement to look at, >> - // since it has better caching than range_on_edge. >> - gimple *last = last_stmt (entry); >> - if (last) >> - { >> - if (m_ranger->range_of_expr (r, name, last)) >> - return; >> - gcc_unreachable (); >> - } > I >> - >> - // If we have no statement, look at all the incoming ranges to the >> - // block. This can happen when we're querying a block with only an >> - // outgoing edge (no statement but the fall through edge), but for >> - // which we can determine a range on entry to the block. >> - Value_Range tmp (TREE_TYPE (name)); >> - bool changed = false; >> - r.set_undefined (); >> - for (unsigned i = 0; i < EDGE_COUNT (entry->preds); ++i) >> - { >> - edge e = EDGE_PRED (entry, i); >> - if (e->src != ENTRY_BLOCK_PTR_FOR_FN (cfun) >> - && m_ranger->range_on_edge (tmp, e, name)) >> - { >> - r.union_ (tmp); >> - changed = true; >> - } >> - } >> - >> - // Make sure we don't return UNDEFINED by mistake. >> - if (!changed) >> - r.set_varying (TREE_TYPE (name)); >> + m_ranger->range_on_entry (r, entry, name); >> } >> >> // Return the range of NAME at the end of the path being analyzed. >> diff --git a/gcc/tree-ssa-threadbackward.cc b/gcc/tree-ssa-threadbackward.cc >> index 0a992213dad..669098e4ec3 100644 >> --- a/gcc/tree-ssa-threadbackward.cc >> +++ b/gcc/tree-ssa-threadbackward.cc >> @@ -525,7 +525,11 @@ back_threader::find_paths (basic_block bb, tree name) >> bitmap_clear (m_imports); >> ssa_op_iter iter; >> FOR_EACH_SSA_TREE_OPERAND (name, stmt, iter, SSA_OP_USE) >> - bitmap_set_bit (m_imports, SSA_NAME_VERSION (name)); >> + { >> + if (!gimple_range_ssa_p (name)) >> + return; >> + bitmap_set_bit (m_imports, SSA_NAME_VERSION (name)); >> + } >> >> // Interesting is the set of imports we still not have see >> // the definition of. So while imports only grow, the >> -- >> 2.35.3 >>