From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 AB97B3858D32 for ; Mon, 26 Sep 2022 12:19:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AB97B3858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664194765; 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: content-transfer-encoding:content-transfer-encoding; bh=kAXtvAcMFDeg24YqUmgKVxJhMWRZW+kiSD/0Z6atjPc=; b=HQJMFxbK4Vjx6clf/RpCwxX0Qd9H5FqHpV0JKBtMTRFTgMY/jFn7Q4h6zVf4DricsqkoEM 6FkPLeJVjTNbSijzFEZ05mXONgLe3NoIOaWJHrot7iY3znIEYm5AGqmEXVuLj7ES7T7Og2 cR0PSCgVI/kF3SafAGPHWXKp3UO4AQY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-392-RSfeN8fmOFaOwrGjAD-qZA-1; Mon, 26 Sep 2022 08:19:24 -0400 X-MC-Unique: RSfeN8fmOFaOwrGjAD-qZA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E33D5185A7AD for ; Mon, 26 Sep 2022 12:19:23 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.195.74]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 041002166B26; Mon, 26 Sep 2022 12:19:22 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.17.1/8.17.1) with ESMTPS id 28QCJKiH3179821 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 26 Sep 2022 14:19:20 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 28QCJJvs3179820; Mon, 26 Sep 2022 14:19:19 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [PATCH] [PR107009] Set ranges from unreachable edges for all known ranges. Date: Mon, 26 Sep 2022 14:18:00 +0200 Message-Id: <20220926121759.3179767-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.5 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,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 List-Id: In the conversion of DOM+evrp to DOM+ranger, we missed that evrp was exporting ranges for unreachable edges for all SSA names for which we have ranges for. Instead we have only been exporting ranges for the SSA name in the final conditional to the BB involving the unreachable edge. This patch adjusts adjusts DOM to iterate over the exports, similarly to what evrp was doing. Note that I also noticed that we don't calculate the nonzero bit mask for op1, when 0 = op1 & MASK. This isn't needed for this PR, since maybe_set_nonzero_bits() is chasing the definition and parsing the bitwise and on its own. However, I'll be adding the functionality for completeness sake, plus we could probably drop the maybe_set_nonzero_bits legacy call entirely. Tested and benchmarked on x86-64 Linux. I'm going to push this as soon as a final round of testing is done, as I shuffled a few things (cleanups) at the last minute. PR tree-optimization/107009 gcc/ChangeLog: * tree-ssa-dom.cc (dom_opt_dom_walker::set_global_ranges_from_unreachable_edges): Iterate over exports. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr107009.c: New test. --- gcc/testsuite/gcc.dg/tree-ssa/pr107009.c | 15 ++++++++++ gcc/tree-ssa-dom.cc | 35 ++++++++++++------------ 2 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr107009.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr107009.c b/gcc/testsuite/gcc.dg/tree-ssa/pr107009.c new file mode 100644 index 00000000000..5010aed1723 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr107009.c @@ -0,0 +1,15 @@ +// { dg-do compile } +// { dg-options "-O2 -fdump-tree-dom2-alias" } + +typedef __SIZE_TYPE__ size_t; + +void saxpy(size_t n) +{ + if (n == 0 || n % 8 != 0) + __builtin_unreachable(); + + extern void foobar (size_t n); + foobar (n); +} + +// { dg-final { scan-tree-dump "NONZERO.*fff8" "dom2" } } diff --git a/gcc/tree-ssa-dom.cc b/gcc/tree-ssa-dom.cc index 513e0c88254..84bef798f52 100644 --- a/gcc/tree-ssa-dom.cc +++ b/gcc/tree-ssa-dom.cc @@ -1227,29 +1227,30 @@ void dom_opt_dom_walker::set_global_ranges_from_unreachable_edges (basic_block bb) { edge pred_e = single_pred_edge_ignoring_loop_edges (bb, false); - if (!pred_e) return; gimple *stmt = last_stmt (pred_e->src); + if (!stmt + || gimple_code (stmt) != GIMPLE_COND + || !assert_unreachable_fallthru_edge_p (pred_e)) + return; + tree name; - if (stmt - && gimple_code (stmt) == GIMPLE_COND - && (name = gimple_cond_lhs (stmt)) - && TREE_CODE (name) == SSA_NAME - && assert_unreachable_fallthru_edge_p (pred_e) - && all_uses_feed_or_dominated_by_stmt (name, stmt)) - { - Value_Range r (TREE_TYPE (name)); + gori_compute &gori = m_ranger->gori (); + FOR_EACH_GORI_EXPORT_NAME (gori, pred_e->src, name) + if (all_uses_feed_or_dominated_by_stmt (name, stmt)) + { + Value_Range r (TREE_TYPE (name)); - if (m_ranger->range_on_edge (r, pred_e, name) - && !r.varying_p () - && !r.undefined_p ()) - { - set_range_info (name, r); - maybe_set_nonzero_bits (pred_e, name); - } - } + if (m_ranger->range_on_edge (r, pred_e, name) + && !r.varying_p () + && !r.undefined_p ()) + { + set_range_info (name, r); + maybe_set_nonzero_bits (pred_e, name); + } + } } /* Record any equivalences created by the incoming edge to BB into -- 2.37.1