From patchwork Fri Sep 15 14:44:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1834945 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=U/dx1xw0; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RnH6Z0V4Xz1ypK for ; Sat, 16 Sep 2023 00:45:24 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E33C43857700 for ; Fri, 15 Sep 2023 14:45:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E33C43857700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694789122; bh=SP845aRDhXqqHAZR2qCJ5VNvEJ0umSzTOuaq0doRwG4=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=U/dx1xw05jbjj64IL9WQFpV2vk5nQvGLPe/O1ChoskTJRNeh7cxlN5mSiv8moH/vh FDLYX/fdAS2DY006iMzH3gUd7PK/lPdhTLNT2n9yva/bS6DtsFPhSkZsh9eLc0vUwx wlxsypBX2IdWpgInPfyEkrqnE30xOgseGr9ABSMQ= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id 0F8F73858D1E for ; Fri, 15 Sep 2023 14:45:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0F8F73858D1E Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-202-hYk2uffmOWOFabV0sVGvYQ-1; Fri, 15 Sep 2023 10:44:59 -0400 X-MC-Unique: hYk2uffmOWOFabV0sVGvYQ-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-63d0c38e986so24817286d6.1 for ; Fri, 15 Sep 2023 07:44:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694789098; x=1695393898; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=D/ugX7tlpK23q5r2EY7no/bYBQQG44AnUdnPvEkHaM8=; b=R6zmc24VNAPirxrA117yrS15LCRzOre4aMGHPjAkVfgcxwLcEBEuUoGEvUPP8LW4s+ JJRVa7kxogeacTLi2scYdCEZoKwjLRnJz/jVFmzDwDOYSNNxzZSP2H5Td5DGlUQYLcjJ culMEWh/Ul6ae8jU4f7r9gndobysquv2XZT4pjUB3julK5RGNKDbP62fRVgaD1WKs0/F MeQwnBULrP/m2zkWbGjbU3131KJnBeEn01Gc3IZvbyNC4AmWH5npyRfg3JAgM9aT1Brf OWd+NG7v3zhiYKpMxf3bTUlaWq87TbAtQ+C3nQV4ny6OGhi07tHKQj6SbBruphgGJMEQ rQvw== X-Gm-Message-State: AOJu0YwGVanHmpzlYaDC1T9c48+i8P+hWOsTHF7TjzcjZPps2tH/t0cL hQQI2eDNHZ9VEgr0X7gYfZDtxxvvD276e5LtGWEKBhTceg8y5YhjBmfImMeTtuefzWiTXYqWy8j S9gkHWBpTX/yMQxorsn/MC/UDUwh18uv5gnrta6SSoFyn9ogMYq8CGnanoZy8zXkFsDFi2NO8U5 4Glg== X-Received: by 2002:a0c:ab4b:0:b0:635:e0dd:db4c with SMTP id i11-20020a0cab4b000000b00635e0dddb4cmr1636660qvb.25.1694789097995; Fri, 15 Sep 2023 07:44:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH6tAfk+DuoZoRze8pB2jM4CUhyviEm78GQ4YqD4Jc/Mc2YdFiGaa4u2XJFqH3u+z17EiejgA== X-Received: by 2002:a0c:ab4b:0:b0:635:e0dd:db4c with SMTP id i11-20020a0cab4b000000b00635e0dddb4cmr1636628qvb.25.1694789097517; Fri, 15 Sep 2023 07:44:57 -0700 (PDT) Received: from ?IPV6:2605:8d80:5e0:23ed:dc0e:d72:28b1:179f? ([2605:8d80:5e0:23ed:dc0e:d72:28b1:179f]) by smtp.gmail.com with ESMTPSA id g15-20020a0cf08f000000b0064f53943626sm1313626qvk.89.2023.09.15.07.44.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 15 Sep 2023 07:44:56 -0700 (PDT) Message-ID: Date: Fri, 15 Sep 2023 10:44:55 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 To: gcc-patches Cc: "hernandez, aldy" , Richard Biener Subject: [PATCH] [RFC] New early __builtin_unreachable processing. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.4 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_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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.30 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" Ive been looking at __builtin_unreachable () regressions.  The fundamental problem seems to be  a lack of consistent expectation for when we remove it earlier than the final pass of VRP.    After looking through them, I think this provides a sensible approach. Ranger is pretty good at providing ranges in blocks dominated by the __builtin_unreachable  branch, so removing it isn't quite a critical as it once was.  Its also pretty good at identifying what in the block can be affected by the branch. This patch provide an alternate removal algorithm for earlier passes.  it looks at *all* the exports from the block, and if the branch dominates every use of all the exports, AND none of those values access memory, VRP will remove the unreachable call, rewrite the branch, update all the values globally, and finally perform the simple DCE on the branch's ssa-name.   This is kind of what it did before, but it wasn't as stringent on the requirements. The memory access check is required because there are a couple of test cases for PRE in which there is a series of instruction leading to an unreachable call, and none of those ssa names are ever used in the IL again. The whole chunk is dead, and we update globals, however pointlessly.  However, one of ssa_names loads from memory, and a later passes commons this value with a later load, and then  the unreachable call provides additional information about the later load.    This is evident in tree-ssa/ssa-pre-34.c.   The only way I see to avoid this situation is to not remove the unreachable if there is a load feeding it. What this does is a more sophisticated version of what DOM does in all_uses_feed_or_dominated_by_stmt.  THe feeding instructions dont have to be single use, but they do have to be dominated by the branch or be single use within the branches block.. If there are multiple uses in the same block as the branch, this does not remove the unreachable call.  If we could be sure there are no intervening calls or side effects, it would be allowable, but this a more expensive checking operation.  Ranger gets the ranges right anyway, so with more passes using ranger, Im not sure we'd see much benefit from the additional analysis.   It could always be added later. This fixes at least 110249 and 110080 (and probably others).  The only regression is 93917 for which I changed the testcase to adjust expectations: // PR 93917 void f1(int n) {   if(n<0)     __builtin_unreachable();   f3(n); } void f2(int*n) {   if(*n<0)     __builtin_unreachable();   f3 (*n); } We were removing both unreachable calls in VRP1, but only updating the global values in the first case, meaning we lose information.   With the change in semantics, we only update the global in the first case, but we leave the unreachable call in the second case now (due to the load from memory).  Ranger still calculates the contextual range correctly as [0, +INF] in the second case, it just doesn't set the global value until VRP2 when it is removed. Does this seem reasonable? Bootstraps on x86_64-pc-linux-gnu with no regressions.  OK? Andrew From 87072ebfcd4f51276fc6ed1fb0557257d51ec446 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Wed, 13 Sep 2023 11:52:15 -0400 Subject: [PATCH 3/3] New early __builtin_unreachable processing. in VRP passes before __builtin_unreachable MUST be removed, only remove it if all exports affected by the unreachable can have global values updated, and do not involve loads from memory. PR tree-optimization/110080 PR tree-optimization/110249 gcc/ * tree-vrp.cc (remove_unreachable::final_p): New. (remove_unreachable::maybe_register): Rename from maybe_register_block and call early or final routine. (fully_replaceable): New. (remove_unreachable::handle_early): New. (remove_unreachable::remove_and_update_globals): Remove non-final processing. (rvrp_folder::rvrp_folder): Add final flag to constructor. (rvrp_folder::post_fold_bb): Remove unreachable registration. (rvrp_folder::pre_fold_stmt): Move unreachable processing to here. (execute_ranger_vrp): Adjust some call parameters. gcc/testsuite/ * g++.dg/pr110249.C: New. * gcc.dg/pr110080.c: New. * gcc.dg/pr93917.c: Adjust. Tweak vuse case Adjusted testcase 93917 --- gcc/testsuite/g++.dg/pr110249.C | 16 +++ gcc/testsuite/gcc.dg/pr110080.c | 27 +++++ gcc/testsuite/gcc.dg/pr93917.c | 7 +- gcc/tree-vrp.cc | 203 ++++++++++++++++++++++++++------ 4 files changed, 214 insertions(+), 39 deletions(-) create mode 100644 gcc/testsuite/g++.dg/pr110249.C create mode 100644 gcc/testsuite/gcc.dg/pr110080.c diff --git a/gcc/testsuite/g++.dg/pr110249.C b/gcc/testsuite/g++.dg/pr110249.C new file mode 100644 index 00000000000..2b737618bdb --- /dev/null +++ b/gcc/testsuite/g++.dg/pr110249.C @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-vrp1-alias" } */ + +#include +#include + +uint64_t read64r(const uint64_t &x) { + if ((uint64_t) &x % 8 ) { + __builtin_unreachable(); + } + uint64_t value; + memcpy( &value, &x, sizeof(uint64_t) ); + return value; +} + +/* { dg-final { scan-tree-dump "fff8" "vrp1" } } */ diff --git a/gcc/testsuite/gcc.dg/pr110080.c b/gcc/testsuite/gcc.dg/pr110080.c new file mode 100644 index 00000000000..c10afe07b1e --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr110080.c @@ -0,0 +1,27 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +void foo(void); +static unsigned char a = 131; +static int *b; +static int **c = &b; +static void d(int e, unsigned f) { + int *g; + if (f != 131) { + __builtin_unreachable(); + } + if (!e){ + for (; a; ++a) + for (e = 0; 0;) + ; + g = &e; + int **h = &g; + if (**h) { + foo(); + } + } + *c = &e; +} +int main() { d(4 & a, a); } + +/* { dg-final { scan-tree-dump-not "foo" "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/pr93917.c b/gcc/testsuite/gcc.dg/pr93917.c index 41d27fb9a8f..f09e1c41ae8 100644 --- a/gcc/testsuite/gcc.dg/pr93917.c +++ b/gcc/testsuite/gcc.dg/pr93917.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O2 -fdump-tree-vrp1" } */ +/* { dg-options "-O2 -fdump-tree-vrp1 -fdump-tree-vrp2" } */ void f3(int n); @@ -17,4 +17,7 @@ void f2(int*n) f3 (*n); } -/* { dg-final { scan-tree-dump-times "Global Exported" 2 "vrp1" } } */ +/* { dg-final { scan-tree-dump-times "Global Export.*0, \\+INF" 1 "vrp1" } } */ +/* { dg-final { scan-tree-dump-times "__builtin_unreachable" 1 "vrp1" } } */ +/* { dg-final { scan-tree-dump-times "Global Export.*0, \\+INF" 1 "vrp2" } } */ +/* { dg-final { scan-tree-dump-times "__builtin_unreachable" 0 "vrp2" } } */ diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc index 2d9f6273280..d7b194f5904 100644 --- a/gcc/tree-vrp.cc +++ b/gcc/tree-vrp.cc @@ -56,11 +56,17 @@ along with GCC; see the file COPYING3. If not see // This class is utilized by VRP and ranger to remove __builtin_unreachable // calls, and reflect any resulting global ranges. // -// maybe_register_block () is called on basic blocks, and if that block -// matches the pattern of one branch being a builtin_unreachable, register -// the resulting executable edge in a list. +// maybe_register() is called on condition statements , and if that +// matches the pattern of one branch being a builtin_unreachable, either check +// for early removal or register the resulting executable edge in a list. // -// After all blocks have been processed, remove_and_update_globals() will +// During early/non-final processing, we check to see if ALL exports from the +// block can be safely updated with a new global value. If they can, then +// we rewrite the condition and update those values immediately. Otherwise +// the unreachable condition is left in the IL until the final pass. +// +// During final processing, after all blocks have been registered, +// remove_and_update_globals() will // - check all exports from registered blocks // - ensure the cache entry of each export is set with the appropriate range // - rewrite the conditions to take the executable edge @@ -71,23 +77,25 @@ along with GCC; see the file COPYING3. If not see class remove_unreachable { public: - remove_unreachable (gimple_ranger &r) : m_ranger (r) { m_list.create (30); } + remove_unreachable (gimple_ranger &r, bool all) : m_ranger (r), final_p (all) + { m_list.create (30); } ~remove_unreachable () { m_list.release (); } - void maybe_register_block (basic_block bb); - bool remove_and_update_globals (bool final_p); + void handle_early (gimple *s, edge e); + void maybe_register (gimple *s); + bool remove_and_update_globals (); vec > m_list; gimple_ranger &m_ranger; + bool final_p; }; // Check if block BB has a __builtin_unreachable () call on one arm, and // register the executable edge if so. void -remove_unreachable::maybe_register_block (basic_block bb) +remove_unreachable::maybe_register (gimple *s) { - gimple *s = gimple_outgoing_range_stmt_p (bb); - if (!s || gimple_code (s) != GIMPLE_COND) - return; + gcc_checking_assert (gimple_code (s) == GIMPLE_COND); + basic_block bb = gimple_bb (s); edge e0 = EDGE_SUCC (bb, 0); basic_block bb0 = e0->dest; @@ -102,21 +110,150 @@ remove_unreachable::maybe_register_block (basic_block bb) if (un0 == un1) return; - if (un0) - m_list.safe_push (std::make_pair (e1->src->index, e1->dest->index)); + // Constant expressions are ignored. + if (TREE_CODE (gimple_cond_lhs (s)) != SSA_NAME + && TREE_CODE (gimple_cond_rhs (s)) != SSA_NAME) + return; + + edge e = un0 ? e1 : e0; + + if (!final_p) + handle_early (s, e); else - m_list.safe_push (std::make_pair (e0->src->index, e0->dest->index)); + m_list.safe_push (std::make_pair (e->src->index, e->dest->index)); } +// Return true if all uses of NAME are dominated by by block BB. 1 use +// is allowed in block BB, This is one we hope to remove. +// ie +// _2 = _1 & 7; +// if (_2 != 0) +// goto ; [0.00%] +// Any additional use of _1 or _2 in this block invalidates early replacement. + +static bool +fully_replaceable (tree name, basic_block bb) +{ + use_operand_p use_p; + imm_use_iterator iter; + bool saw_in_bb = false; + + // If a name loads from memory, we may lose information used in + // commoning opportunities later. See tree-ssa/ssa-pre-34.c. + gimple *def_stmt = SSA_NAME_DEF_STMT (name); + if (gimple_vuse (def_stmt)) + return false; + + FOR_EACH_IMM_USE_FAST (use_p, iter, name) + { + gimple *use_stmt = USE_STMT (use_p); + // Ignore debug stmts and the branch. + if (is_gimple_debug (use_stmt)) + continue; + basic_block use_bb = gimple_bb (use_stmt); + // Only one use in the block allowed to avoid complicated cases. + if (use_bb == bb) + { + if (saw_in_bb) + return false; + else + saw_in_bb = true; + } + else if (!dominated_by_p (CDI_DOMINATORS, use_bb, bb)) + return false; + } + return true; +} + +// This routine is called to check builtin_unreachable calls during any +// time before final removal. The only way we can be sure it does not +// provide any additional information is to expect that we can update the +// global values of all exports from a block. This means the branch +// to the unreachable call must dominate all uses of those ssa-names, with +// the exception that there can be a single use in the block containing +// the branch. IF the name used in the branch is defined in the block, it may +// contain the name of something else that will be an export. And likewise +// that may also use another name that is an export etc. +// +// As long as there is only a single use, we can be sure that there are no other +// side effects (like being passed to a call, or stored to a global, etc. +// This means we will miss cases where there are 2 or more uses that have +// no interveneing statements that may had side effects, but it catches most +// of the caes we care about, and prevents expensive in depth analysis. +// +// Ranger will still reflect the proper ranges at other places in these missed +// cases, we simply will not remove/set globals early. + +void +remove_unreachable::handle_early (gimple *s, edge e) +{ + bool lhs_p = TREE_CODE (gimple_cond_lhs (s)) == SSA_NAME; + bool rhs_p = TREE_CODE (gimple_cond_rhs (s)) == SSA_NAME; + // Do not remove __builtin_unreachable if it confers a relation, or + // that relation may be lost in subsequent passes. + if (lhs_p && rhs_p) + return; + // Do not remove addresses early. ie if (x == &y) + if (lhs_p && TREE_CODE (gimple_cond_rhs (s)) == ADDR_EXPR) + return; + + gcc_checking_assert (gimple_outgoing_range_stmt_p (e->src) == s); + gcc_checking_assert (!final_p); + + // Check if every export use is dominated by this branch. + tree name; + FOR_EACH_GORI_EXPORT_NAME (m_ranger.gori (), e->src, name) + { + if (!fully_replaceable (name, e->src)) + return; + } + + // Set the global value for each. + FOR_EACH_GORI_EXPORT_NAME (m_ranger.gori (), e->src, name) + { + Value_Range r (TREE_TYPE (name)); + m_ranger.range_on_entry (r, e->dest, name); + // Nothing at this late stage we can do if the write fails. + if (!set_range_info (name, r)) + continue; + if (dump_file) + { + fprintf (dump_file, "Global Exported (via early unreachable): "); + print_generic_expr (dump_file, name, TDF_SLIM); + fprintf (dump_file, " = "); + gimple_range_global (r, name); + r.dump (dump_file); + fputc ('\n', dump_file); + } + } + + tree ssa = lhs_p ? gimple_cond_lhs (s) : gimple_cond_rhs (s); + + // Rewrite the condition. + if (e->flags & EDGE_TRUE_VALUE) + gimple_cond_make_true (as_a (s)); + else + gimple_cond_make_false (as_a (s)); + update_stmt (s); + + // If the name on S is defined in this block, see if there is DCE work to do. + if (gimple_bb (SSA_NAME_DEF_STMT (ssa)) == e->src) + { + auto_bitmap dce; + bitmap_set_bit (dce, SSA_NAME_VERSION (ssa)); + simple_dce_from_worklist (dce); + } +} + + // Process the edges in the list, change the conditions and removing any // dead code feeding those conditions. Calculate the range of any // names that may have been exported from those blocks, and determine if // there is any updates to their global ranges.. -// FINAL_P indicates all builtin_unreachable calls should be removed. // Return true if any builtin_unreachables/globals eliminated/updated. bool -remove_unreachable::remove_and_update_globals (bool final_p) +remove_unreachable::remove_and_update_globals () { if (m_list.length () == 0) return false; @@ -140,19 +277,7 @@ remove_unreachable::remove_and_update_globals (bool final_p) edge e = find_edge (src, dest); gimple *s = gimple_outgoing_range_stmt_p (e->src); gcc_checking_assert (gimple_code (s) == GIMPLE_COND); - bool lhs_p = TREE_CODE (gimple_cond_lhs (s)) == SSA_NAME; - bool rhs_p = TREE_CODE (gimple_cond_rhs (s)) == SSA_NAME; - // Do not remove __builtin_unreachable if it confers a relation, or - // that relation will be lost in subsequent passes. Unless its the - // final pass. - if (!final_p && lhs_p && rhs_p) - continue; - // If this is already a constant condition, don't look either - if (!lhs_p && !rhs_p) - continue; - // Do not remove addresses early. ie if (x == &y) - if (!final_p && lhs_p && TREE_CODE (gimple_cond_rhs (s)) == ADDR_EXPR) - continue; + bool dominate_exit_p = true; FOR_EACH_GORI_EXPORT_NAME (m_ranger.gori (), e->src, name) { @@ -827,9 +952,10 @@ class rvrp_folder : public substitute_and_fold_engine { public: - rvrp_folder (gimple_ranger *r) : substitute_and_fold_engine (), - m_unreachable (*r), - m_simplifier (r, r->non_executable_edge_flag) + rvrp_folder (gimple_ranger *r, bool all) + : substitute_and_fold_engine (), + m_unreachable (*r, all), + m_simplifier (r, r->non_executable_edge_flag) { m_ranger = r; m_pta = new pointer_equiv_analyzer (m_ranger); @@ -883,8 +1009,6 @@ public: void post_fold_bb (basic_block bb) override { m_pta->leave (bb); - if (cfun->after_inlining) - m_unreachable.maybe_register_block (bb); } void pre_fold_stmt (gimple *stmt) override @@ -893,7 +1017,12 @@ public: // If this is the last stmt and there are inferred ranges, reparse the // block for transitive inferred ranges that occur earlier in the block. if (stmt == m_last_bb_stmt) - m_ranger->register_transitive_inferred_ranges (gimple_bb (stmt)); + { + m_ranger->register_transitive_inferred_ranges (gimple_bb (stmt)); + // Also check for builtin_unreachable calls. + if (cfun->after_inlining && gimple_code (stmt) == GIMPLE_COND) + m_unreachable.maybe_register (stmt); + } } bool fold_stmt (gimple_stmt_iterator *gsi) override @@ -928,11 +1057,11 @@ execute_ranger_vrp (struct function *fun, bool warn_array_bounds_p, set_all_edges_as_executable (fun); gimple_ranger *ranger = enable_ranger (fun, false); - rvrp_folder folder (ranger); + rvrp_folder folder (ranger, final_p); phi_analysis_initialize (ranger->const_query ()); folder.substitute_and_fold (); // Remove tagged builtin-unreachable and maybe update globals. - folder.m_unreachable.remove_and_update_globals (final_p); + folder.m_unreachable.remove_and_update_globals (); if (dump_file && (dump_flags & TDF_DETAILS)) ranger->dump (dump_file); -- 2.41.0