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: 775 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp105650wro; Thu, 25 Aug 2022 23:56:18 -0700 (PDT) X-Google-Smtp-Source: AA6agR5p97PEmYcGiC3Wb5T+aZPsIWPvnq0RlxuLWpXe4oEDyUaCHew5BRIi9wHe9DdZNe55P3KV X-Received: by 2002:a17:906:9b09:b0:73d:7c69:4d83 with SMTP id eo9-20020a1709069b0900b0073d7c694d83mr4729881ejc.441.1661496978075; Thu, 25 Aug 2022 23:56:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661496978; cv=none; d=google.com; s=arc-20160816; b=cw/cq/JVYvPCVBnhZVYMyl7oeQjdqjRbRFNQT3EM5ClCLYEDVB3CXLngF5vKNocsZr EiTnec2ZfAaMktbMbir9g8T08sVswDT6QJoqv4XuoQbyUk+wxKFFe79jgUa2aoTMMLFJ XLiidMyUazsRg0OM9k5MJNKwXRdzW1F9OwIzvrIrkvZI1pHTQTwdR3Qv4Espy6M9UDQb aqe04PPWrcIJhH1w9J8DCmJek6blRaIYqUTTlHygpHlgPQhRFbI2zLpzYuPLBwvOOp8M htscn/u3wMUBk3DrS2Nv8I8mzxI4SMnSS67JhwclNYL1Ct/SmNC8QdvMLPFeOVtR8rb+ rXiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:message-id :mime-version:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=yr3ysrHM/dfDfESCKdZWmVQOWIjv2f9YmVWJ+Sk4rjI=; b=s6XchBEqz8loejjGSpDWD5iDXubz75S7llGhZ/slwh6zOldsqYqYAcTm9uz6rCePU1 UpKVF8g/B+Ad87Yn37fZs48gHaVm3WylESAks9X3e2VvryPxEDRq9m1ADArtPuILV6BD LQBacrEujkGvMMUQHcJsK06uKfdQ/T6fRVAFVyhre2GarTlZMrAf5ZKVvqhrZCj0ooOh S+cn0HJntx1XUOC0mosK6HzUocGRj1n9dNvYcljAmQROiqueWFcJsEALw9nWZHy2dEYp jtwrq5WmuvBEnLD2RK0iCJVAI9a+w/BDeFjgzortyhwqp3qwhyN8wfDcXd3OTjdNsUqQ WxFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DD93XsfN; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id hd16-20020a170907969000b007413469b5a2si152394ejc.257.2022.08.25.23.56.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Aug 2022 23:56:18 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DD93XsfN; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E2DB838362F1 for ; Fri, 26 Aug 2022 06:55:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E2DB838362F1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661496954; 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=DD93XsfNtOZeBe4a5f8HEW9OPi40nNzi8khlv7vTCZNYNnHN2+aIZeTYf5w3dev0c UiP1sa0CDHLA498Pe/Gnkw3NtYXMOgnahZ+WYzDSHkeXXah9SCN+Ky6MmzQjATVA5s UepLpL70FZO4JWafLGMJFXgQpt8vZnFikKKHd/H4= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1742205855158570686?= X-GMAIL-MSGID: =?utf-8?q?1742205855158570686?= 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 *);