From patchwork Fri Jun 21 13:01:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1950786 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=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OhyyRdJL; 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 4W5HZb1Gdtz20X4 for ; Fri, 21 Jun 2024 23:02:31 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6F736389901B for ; Fri, 21 Jun 2024 13:02:29 +0000 (GMT) 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 7197C3898C45 for ; Fri, 21 Jun 2024 13:02:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7197C3898C45 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7197C3898C45 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718974927; cv=none; b=MjyuLLvsTNU/0VyCKw9V4tZUsfSkjeH6EZBz6qotahGc9UG9QekNMgi9lAcE73yVj3iEjtqeOnRvRY40Q2YkG/yIqjwNbfR64i5Dn7XWxpcTtP1K9rQc1I7OS7y8oKA1xrqAbyTPgp2JDZIPfd6ZNHmMWcpxfgOlT46w9J3TEZY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718974927; c=relaxed/simple; bh=zWlwPRJeBUqyF6rokvMtPyiLcci2YlDXsLr7/imHjk0=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=VXIdEMX/C3W/hPT0MxMgEpCt9Y9y6P2XJhdBzw92M2TaXLDiM9XvfK2BSnCnjdnGhe0RVVJEJgcIgM2cRxpImsUUwYks/1AJNSk36w3/2fo9K5d50uf9vFmJyyRT9KkjZx5uKnWrI1n/3EfTrl5ecr8e8YNqFQKsSujq48d0BQo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718974925; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=FBxz6HXfKBpKZ4Q8dumQmaZRVG4eM3st9qNngmeecps=; b=OhyyRdJLiqNKNn2Y3n3FDopvCLlk6HotWy8kaOKgZj4lEk0xz8F1KyP/lDSA0/iWP9Zdwd yd1bNV5Ww6+779VH0stZNhFoXHirT3C44sWlYT0Uqv632+NBSy627FvngpBiMebMwf9P3h sBzY1oxn1mMTo7vz8+UQZHG8XbHESkA= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-642--PWd4bF8PfWEWUN4fIWpZA-1; Fri, 21 Jun 2024 09:02:02 -0400 X-MC-Unique: -PWd4bF8PfWEWUN4fIWpZA-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-79784eb58cdso205775285a.0 for ; Fri, 21 Jun 2024 06:02:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718974921; x=1719579721; 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=qnCYrow8ldmgsFeMwvkFvIKaA9nzjUIwVrqPMFRPmLE=; b=pvQLLoroaw+L3S4g+0+gcj1+V3IvJNc0SYFg10RcD71zz7CV085x1P6WR8iv1Y7FKD uhIyqkC7mejgt3+3CEWwVtYg2aetifUZTF4Q2RrSybJDe2gFy5pron1smnmUvvxjWoo7 jE1d1JqhvBzFIG71OOg16/VMLykQ8bd0gF0zK+tKpiNYbbhvg3KDsuOus+sPXECdZyzc knsHPOmiI2YyeIlMXbN7UuVXJBSB/PhPRLlRQZMFReYsCP1zQaZtfBg/vhUM2pqPmjCI 2bjad5puSNRvbe+hkj7V5MoaBCvqoUOtsepYsxN985NNWvJd53/JFqyDQnduFLZJVOPR kCqQ== X-Gm-Message-State: AOJu0YzHnT6JaTI1d976oqDfT9uQyDggjnbmaFYfG0nooWeIdaJV8a00 hCDYS3y2rHSUzJkt/UyF+cNjk61pecj+r8NEACjfRyPoDFRmXLDKEfuBsWHsStChFIDBIQOEeem zDZHq4wjcwWcPJEX7bDP6F306rGTmkfdANuWV3FKsNyVzn2A1Ne0hsBhBueJ+cXyWXwDGvW0FlV V9QxRWHXzF6FhH79rlhYDXawHWwBsrWK/ai0m1qR4= X-Received: by 2002:a05:620a:4093:b0:79b:b6ad:e0b6 with SMTP id af79cd13be357-79bb6ade657mr755073585a.8.1718974921274; Fri, 21 Jun 2024 06:02:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHydAoiBxNK1du9/U2baIcBl6QlECP0H14LqqHQrm1N80/KxaLXww85NMSxu6u2OQgPh/vCiw== X-Received: by 2002:a05:620a:4093:b0:79b:b6ad:e0b6 with SMTP id af79cd13be357-79bb6ade657mr755070285a.8.1718974920799; Fri, 21 Jun 2024 06:02:00 -0700 (PDT) Received: from ?IPV6:2607:fea8:51de:a700::7158? ([2607:fea8:51de:a700::7158]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-444c2b989aasm10925791cf.49.2024.06.21.06.01.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 21 Jun 2024 06:02:00 -0700 (PDT) Message-ID: <37c1d0c2-a586-4e50-8334-e2eca978537e@redhat.com> Date: Fri, 21 Jun 2024 09:01:59 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: gcc-patches Cc: "hernandez, aldy" From: Andrew MacLeod Subject: [COMMITTED] Add builtin_unreachable processing for fast_vrp. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.6 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_H4, 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: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org With the earlier rework of VRP which removed the array_bounds pass, it is now possible to invoke a different VRP for any pass. This patch adds the ability to call fast_vrp with the final_pass flag set, and remove invoke the remove_unreachable object to remove __builtin_unreachable calls if it is the final pass. Bootstraps on  x86_64-pc-linux-gnu with no regressions.   Pushed. Andrew From 82c704c69fab610afcf4a1947577ed97dd72c429 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Mon, 17 Jun 2024 11:23:12 -0400 Subject: [PATCH 1/5] Add builtin_unreachable processing for fast_vrp. Add a remove_unreachable object to fast vrp, and honor the final_p flag. * tree-vrp.cc (remove_unreachable::remove): Export global range if builtin_unreachable dominates all uses. (remove_unreachable::remove_and_update_globals): Do not reset SCEV. (execute_ranger_vrp): Reset SCEV here instead. (fvrp_folder::fvrp_folder): Take final pass flag and create a remove_unreachable object when specified. (fvrp_folder::pre_fold_stmt): Register GIMPLE_CONDs with the remove_unreachcable object. (fvrp_folder::m_unreachable): New. (execute_fast_vrp): Process remove_unreachable object. (pass_vrp::execute): Add final_p flag to execute_fast_vrp. --- gcc/tree-vrp.cc | 52 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc index 5f5eb9b57e9..a3b1a5cd337 100644 --- a/gcc/tree-vrp.cc +++ b/gcc/tree-vrp.cc @@ -280,6 +280,25 @@ remove_unreachable::remove () gimple *s = gimple_outgoing_range_stmt_p (e->src); gcc_checking_assert (gimple_code (s) == GIMPLE_COND); + tree name = gimple_range_ssa_p (gimple_cond_lhs (s)); + if (!name) + name = gimple_range_ssa_p (gimple_cond_rhs (s)); + // Check if global value can be set for NAME. + if (name && fully_replaceable (name, src)) + { + value_range r (TREE_TYPE (name)); + if (gori_name_on_edge (r, name, e, &m_ranger) + && set_range_info (name, r) &&(dump_file)) + { + fprintf (dump_file, "Global Exported (via 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); + } + } + change = true; // Rewrite the condition. if (e->flags & EDGE_TRUE_VALUE) @@ -305,14 +324,10 @@ remove_unreachable::remove_and_update_globals () if (m_list.length () == 0) return false; - // If there is no import/export info, just remove unreachables if necessary. + // If there is no import/export info, Do basic removal. if (!m_ranger.gori_ssa ()) return remove (); - // Ensure the cache in SCEV has been cleared before processing - // globals to be removed. - scev_reset (); - bool change = false; tree name; unsigned i; @@ -1107,6 +1122,9 @@ execute_ranger_vrp (struct function *fun, bool final_p) rvrp_folder folder (ranger, final_p); phi_analysis_initialize (ranger->const_query ()); folder.substitute_and_fold (); + // Ensure the cache in SCEV has been cleared before processing + // globals to be removed. + scev_reset (); // Remove tagged builtin-unreachable and maybe update globals. folder.m_unreachable.remove_and_update_globals (); if (dump_file && (dump_flags & TDF_DETAILS)) @@ -1168,9 +1186,15 @@ execute_ranger_vrp (struct function *fun, bool final_p) class fvrp_folder : public substitute_and_fold_engine { public: - fvrp_folder (dom_ranger *dr) : substitute_and_fold_engine (), - m_simplifier (dr) - { m_dom_ranger = dr; } + fvrp_folder (dom_ranger *dr, bool final_p) : substitute_and_fold_engine (), + m_simplifier (dr) + { + m_dom_ranger = dr; + if (final_p) + m_unreachable = new remove_unreachable (*dr, final_p); + else + m_unreachable = NULL; + } ~fvrp_folder () { } @@ -1228,6 +1252,9 @@ public: value_range vr(type); m_dom_ranger->range_of_stmt (vr, s); } + if (m_unreachable && gimple_code (s) == GIMPLE_COND) + m_unreachable->maybe_register (s); + } bool fold_stmt (gimple_stmt_iterator *gsi) override @@ -1238,6 +1265,7 @@ public: return ret; } + remove_unreachable *m_unreachable; private: DISABLE_COPY_AND_ASSIGN (fvrp_folder); simplify_using_ranges m_simplifier; @@ -1248,16 +1276,18 @@ private: // Main entry point for a FAST VRP pass using a dom ranger. unsigned int -execute_fast_vrp (struct function *fun) +execute_fast_vrp (struct function *fun, bool final_p) { calculate_dominance_info (CDI_DOMINATORS); dom_ranger dr; - fvrp_folder folder (&dr); + fvrp_folder folder (&dr, final_p); gcc_checking_assert (!fun->x_range_query); fun->x_range_query = &dr; folder.substitute_and_fold (); + if (folder.m_unreachable) + folder.m_unreachable->remove (); fun->x_range_query = NULL; return 0; @@ -1325,7 +1355,7 @@ public: { // Check for fast vrp. if (&data == &pass_data_fast_vrp) - return execute_fast_vrp (fun); + return execute_fast_vrp (fun, final_p); return execute_ranger_vrp (fun, final_p); } -- 2.45.0