From patchwork Wed Aug 31 11:03:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 57202 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 7B78C3839DE1 for ; Wed, 31 Aug 2022 11:04:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7B78C3839DE1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661943843; bh=6UcNNrjo6JgwAxasHWyF+P3JB7DMgxLyWakm81hcGmY=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=RLptrrM4bt02dao4nucLK51IyWYCdkHT865JrdQxyunoIfTwSQf7zNKGGEbxErbPo fLjHwCRTWy2c+DoaBDuhHQqD8rYZOilUFam11SO2tbhfVXqrHP7OOmhdHjzNElwgKZ +f4yaTPH++bgEZjqXFt3xHNLUqGegKN7NaOdkw68= 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 F19F23857B88 for ; Wed, 31 Aug 2022 11:03:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F19F23857B88 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 CE7E91F8B4 for ; Wed, 31 Aug 2022 11:03:32 +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 B58C013A7C for ; Wed, 31 Aug 2022 11:03:32 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 3qEYKwRAD2PNcgAAMHmgww (envelope-from ) for ; Wed, 31 Aug 2022 11:03:32 +0000 Date: Wed, 31 Aug 2022 13:03:32 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/73550 - more switch handling improvements for uninit MIME-Version: 1.0 Message-Id: <20220831110332.B58C013A7C@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" The following makes predicate analysis handle case labels with a non-singleton contiguous range. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/73550 * gimple-predicate-analysis.cc (predicate::init_from_control_deps): Sanitize debug dumping. Handle case labels with a CASE_HIGH. (predicate::dump): Adjust for better readability. --- gcc/gimple-predicate-analysis.cc | 77 +++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 27 deletions(-) diff --git a/gcc/gimple-predicate-analysis.cc b/gcc/gimple-predicate-analysis.cc index 00c6bfc50a3..6b2e347536a 100644 --- a/gcc/gimple-predicate-analysis.cc +++ b/gcc/gimple-predicate-analysis.cc @@ -1674,6 +1674,10 @@ predicate::init_from_control_deps (const vec *dep_chains, if (num_chains == 0) return; + if (DEBUG_PREDICATE_ANALYZER && dump_file) + fprintf (dump_file, "init_from_control_deps {%s}:\n", + format_edge_vecs (dep_chains, num_chains).c_str ()); + /* Convert the control dependency chain into a set of predicates. */ m_preds.reserve (num_chains); @@ -1740,7 +1744,8 @@ predicate::init_from_control_deps (const vec *dep_chains, if (DEBUG_PREDICATE_ANALYZER && dump_file) { - fprintf (dump_file, "one_pred = "); + fprintf (dump_file, "%d -> %d: one_pred = ", + e->src->index, e->dest->index); dump_pred_info (one_pred); fputc ('\n', dump_file); } @@ -1773,24 +1778,41 @@ predicate::init_from_control_deps (const vec *dep_chains, } } /* If more than one label reaches this block or the case - label doesn't have a single value (like the default one) - fail. */ - if (!l - || !CASE_LOW (l) - || (CASE_HIGH (l) - && !operand_equal_p (CASE_LOW (l), CASE_HIGH (l), 0))) + label doesn't have a contiguous range of values (like the + default one) fail. */ + if (!l || !CASE_LOW (l)) { has_valid_pred = false; break; } - - pred_info one_pred; - one_pred.pred_lhs = gimple_switch_index (gs); - one_pred.pred_rhs = CASE_LOW (l); - one_pred.cond_code = EQ_EXPR; - one_pred.invert = false; - t_chain.safe_push (one_pred); - has_valid_pred = true; + else if (!CASE_HIGH (l) + || operand_equal_p (CASE_LOW (l), CASE_HIGH (l))) + { + pred_info one_pred; + one_pred.pred_lhs = gimple_switch_index (gs); + one_pred.pred_rhs = CASE_LOW (l); + one_pred.cond_code = EQ_EXPR; + one_pred.invert = false; + t_chain.safe_push (one_pred); + has_valid_pred = true; + } + else + { + /* Support a case label with a range with + two predicates. We're overcommitting on + the MAX_CHAIN_LEN budget by at most a factor + of two here. */ + pred_info one_pred; + one_pred.pred_lhs = gimple_switch_index (gs); + one_pred.pred_rhs = CASE_LOW (l); + one_pred.cond_code = GE_EXPR; + one_pred.invert = false; + t_chain.safe_push (one_pred); + one_pred.pred_rhs = CASE_HIGH (l); + one_pred.cond_code = LE_EXPR; + t_chain.safe_push (one_pred); + has_valid_pred = true; + } } else { @@ -1803,22 +1825,24 @@ predicate::init_from_control_deps (const vec *dep_chains, if (!has_valid_pred) break; else - m_preds.safe_push (t_chain); + m_preds.quick_push (t_chain); } - if (DEBUG_PREDICATE_ANALYZER && dump_file) + if (has_valid_pred) { - fprintf (dump_file, "init_from_control_deps {%s}:\n", - format_edge_vecs (dep_chains, num_chains).c_str ()); - dump (NULL, ""); + gcc_assert (m_preds.length () != 0); + if (DEBUG_PREDICATE_ANALYZER && dump_file) + dump (NULL, ""); } - - if (has_valid_pred) - gcc_assert (m_preds.length () != 0); else - /* Clear M_PREDS to indicate failure. */ - m_preds.release (); + { + if (DEBUG_PREDICATE_ANALYZER && dump_file) + fprintf (dump_file, "\tFAILED\n"); + /* Clear M_PREDS to indicate failure. */ + m_preds.release (); + } } + /* Store a PRED in *THIS. */ void @@ -1856,9 +1880,8 @@ predicate::dump (gimple *stmt, const char *msg) const else fprintf (dump_file, "\t("); dump_pred_chain (m_preds[i]); - fputc (')', dump_file); + fprintf (dump_file, ")\n"); } - fputc ('\n', dump_file); } /* Initialize USE_PREDS with the predicates of the control dependence chains