From patchwork Fri Aug 26 06:55:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 57074 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 275C23836001 for ; Fri, 26 Aug 2022 06:55:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 275C23836001 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661496941; bh=yr3ysrHM/dfDfESCKdZWmVQOWIjv2f9YmVWJ+Sk4rjI=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Cyou461oScpw3+O9BZ7Q599MPFnjyqWm97RFpoB6jgKxFvzYUJ6nRb+3Nb9F7KDxb 9AOQTfD+SaqqAtg3FtfM3Q+irf/ePKh+Ssxlex1ZkKYyoFAES1Ke3VfKoQvfLCuKr8 0d/XQJ+a1ba+UtOUWLlYC3CGfHuaPVO878my3FkA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 42A633858004 for ; Fri, 26 Aug 2022 06:55:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 42A633858004 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 254181F934 for ; Fri, 26 Aug 2022 06:55:11 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1057F13421 for ; Fri, 26 Aug 2022 06:55:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id bm/SAk9uCGPVfgAAMHmgww (envelope-from ) for ; Fri, 26 Aug 2022 06:55:11 +0000 Date: Fri, 26 Aug 2022 08:55:10 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] Remove uninit_analysis::use_cannot_happen MIME-Version: 1.0 Message-Id: <20220826065511.1057F13421@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, 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-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" As written earlier uninit_analysis::use_cannot_happen is duplicate functionality implemented in a complement way, not adhering to the idea of disproving a may-uninit use and eventually (I have not yet found a testcase it helps to avoid false positives) avoiding false positives because of this or different ways it imposes limits on the predicate computations. This patch removes it. I've bootstrapped and tested this before, but re-bootstrap/test on x86_64-unknown-linux-gnu is running now. * gimple-predicate-analysis.h (uninit_analysis::use_cannot_happen): Remove. * gimple-predicate-analysis.cc (can_be_invalidated_p): Remove. (uninit_analysis::use_cannot_happen): Likewise. (uninit_analysis::is_use_guarded): Do not call use_cannot_happen. --- gcc/gimple-predicate-analysis.cc | 179 ------------------------------- gcc/gimple-predicate-analysis.h | 1 - 2 files changed, 180 deletions(-) diff --git a/gcc/gimple-predicate-analysis.cc b/gcc/gimple-predicate-analysis.cc index e395c1b7052..9d95e9db922 100644 --- a/gcc/gimple-predicate-analysis.cc +++ b/gcc/gimple-predicate-analysis.cc @@ -1242,180 +1242,6 @@ compute_control_dep_chain (basic_block dom_bb, const_basic_block dep_bb, return found_cd_chain; } -/* Return true if PRED can be invalidated by any predicate in GUARD. */ - -static bool -can_be_invalidated_p (const pred_info &pred, const pred_chain &guard) -{ - if (dump_file && dump_flags & TDF_DETAILS) - { - fprintf (dump_file, "Testing if predicate: "); - dump_pred_info (pred); - fprintf (dump_file, "\n...can be invalidated by a USE guard of: "); - dump_pred_chain (guard); - fputc ('\n', dump_file); - } - - unsigned n = guard.length (); - for (unsigned i = 0; i < n; ++i) - { - if (pred_neg_p (pred, guard[i])) - { - if (dump_file && dump_flags & TDF_DETAILS) - { - fprintf (dump_file, " Predicate invalidated by: "); - dump_pred_info (guard[i]); - fputc ('\n', dump_file); - } - return true; - } - } - - return false; -} - -/* Return true if all predicates in PREDS are invalidated by GUARD being - true. */ - -static bool -can_be_invalidated_p (const pred_chain_union &preds, const pred_chain &guard) -{ - if (preds.is_empty ()) - return false; - - if (dump_file && dump_flags & TDF_DETAILS) - dump_predicates (NULL, preds, - "Testing if anything here can be invalidated: "); - - for (unsigned i = 0; i < preds.length (); ++i) - { - const pred_chain &chain = preds[i]; - unsigned j; - for (j = 0; j < chain.length (); ++j) - if (can_be_invalidated_p (chain[j], guard)) - break; - - /* If we were unable to invalidate any predicate in C, then there - is a viable path from entry to the PHI where the PHI takes - an interesting value and continues to a use of the PHI. */ - if (j == chain.length ()) - return false; - } - return true; -} - -/* Return true if none of the PHI arguments in OPNDS is used given - the use guards in *THIS that guard the PHI's use. */ - -bool -uninit_analysis::use_cannot_happen (gphi *phi, unsigned opnds, const predicate &use_preds) -{ - if (!m_eval.phi_arg_set (phi)) - return false; - - /* PHI_USE_GUARDS are OR'ed together. If we have more than one - possible guard, there's no way of knowing which guard was true. - In that case compute the intersection of all use predicates - and use that. */ - const predicate &phi_use_guards = use_preds; - const pred_chain *use_guard = &phi_use_guards.chain() [0]; - pred_chain phi_use_guard_intersection = vNULL; - if (phi_use_guards.chain ().length () != 1) - { - phi_use_guard_intersection = use_guard->copy (); - for (unsigned i = 1; i < phi_use_guards.chain ().length (); ++i) - { - for (unsigned j = 0; j < phi_use_guard_intersection.length ();) - { - unsigned k; - for (k = 0; k < phi_use_guards.chain ()[i].length (); ++k) - if (pred_equal_p (phi_use_guards.chain ()[i][k], - phi_use_guard_intersection[j])) - break; - if (k == phi_use_guards.chain ()[i].length ()) - phi_use_guard_intersection.unordered_remove (j); - else - j++; - } - } - if (phi_use_guard_intersection.is_empty ()) - { - phi_use_guard_intersection.release (); - return false; - } - use_guard = &phi_use_guard_intersection; - } - - basic_block phi_bb = gimple_bb (phi); - /* Find the closest dominating bb to be the control dependence root. */ - basic_block cd_root = get_immediate_dominator (CDI_DOMINATORS, phi_bb); - if (!cd_root) - return false; - - /* Look for the control dependencies of all the interesting operands - and build guard predicates describing them. */ - unsigned n = gimple_phi_num_args (phi); - for (unsigned i = 0; i < n; ++i) - { - if (!MASK_TEST_BIT (opnds, i)) - continue; - - edge e = gimple_phi_arg_edge (phi, i); - auto_vec dep_chains[MAX_NUM_CHAINS]; - auto_vec cur_chain; - unsigned num_chains = 0; - unsigned num_calls = 0; - - /* Build the control dependency chain for the PHI argument... */ - if (!compute_control_dep_chain (cd_root, - e->src, dep_chains, &num_chains, - cur_chain, &num_calls)) - { - gcc_assert (num_chains == 0); - /* If compute_control_dep_chain bailed out due to limits - build a partial sparse path using dominators. Collect - only edges whose predicates are always true when reaching E. */ - simple_control_dep_chain (dep_chains[0], cd_root, e); - num_chains++; - } - /* Update the chains with the phi operand edge. */ - else if (EDGE_COUNT (e->src->succs) > 1) - { - for (unsigned j = 0; j < num_chains; j++) - dep_chains[j].safe_push (e); - } - - if (DEBUG_PREDICATE_ANALYZER && dump_file) - { - fprintf (dump_file, "predicate::use_cannot_happen (...) " - "dep_chains for arg %u:\n\t", i); - dump_dep_chains (dep_chains, num_chains); - } - - /* ...and convert it into a set of predicates guarding its - definition. */ - predicate def_preds; - def_preds.init_from_control_deps (dep_chains, num_chains); - if (def_preds.is_empty ()) - /* If there's no predicate there's no basis to rule the use out. */ - return false; - - def_preds.simplify (); - def_preds.normalize (); - - /* Can the guard for this PHI argument be negated by the one - guarding the PHI use? */ - if (!can_be_invalidated_p (def_preds.chain (), *use_guard)) - { - phi_use_guard_intersection.release (); - return false; - } - } - - phi_use_guard_intersection.release (); - return true; -} - /* Implemented simplifications: 1) ((x IOR y) != 0) AND (x != 0) is equivalent to (x != 0); @@ -2391,11 +2217,6 @@ uninit_analysis::is_use_guarded (gimple *use_stmt, basic_block use_bb, return true; } - /* We might be able to prove that if the control dependencies for OPNDS - are true, the control dependencies for USE_STMT can never be true. */ - if (use_cannot_happen (phi, opnds, use_preds)) - return true; - if (m_phi_def_preds.is_empty ()) { /* Lazily initialize *THIS from PHI. */ diff --git a/gcc/gimple-predicate-analysis.h b/gcc/gimple-predicate-analysis.h index b4aa5de7e7b..1ca6ab1f7e4 100644 --- a/gcc/gimple-predicate-analysis.h +++ b/gcc/gimple-predicate-analysis.h @@ -137,7 +137,6 @@ private: bool prune_phi_opnds (gphi *, unsigned, gphi *, tree, tree_code, hash_set *, bitmap *); bool overlap (gphi *, unsigned, hash_set *, const predicate &); - bool use_cannot_happen (gphi *, unsigned, const predicate &); void collect_phi_def_edges (gphi *, basic_block, vec *, hash_set *);