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 ED1F33858D35 for ; Tue, 31 Jan 2023 15:59:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ED1F33858D35 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=1675180744; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=jj5zpYzA8Cl7bjIcSWg9NNSALTFQhobqQ54lHhX5EEo=; b=iFt1hMX5eYhShlDD8tI95pLQ63UPaYD3bxOuI+bHVSCuorVLsPu4mNjU33hdiHTvJMDemp rjrx0Ht8ogOjoMpVRaNwJW6rA9K9jV0pa3kZEgR/Yu9Qczbv22GradQWj3ljt0+i/kssMS geaXA1LU+rP9XoDyCUvLbm1nCmIjWlU= 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-580-L4WN6_tqOOK-CFYwNqonsg-1; Tue, 31 Jan 2023 10:59:01 -0500 X-MC-Unique: L4WN6_tqOOK-CFYwNqonsg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A6751101A55E; Tue, 31 Jan 2023 15:59:00 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 63D04492C3E; Tue, 31 Jan 2023 15:59:00 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 30VFwqQs1049744 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 31 Jan 2023 16:58:53 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 30VFwqJE1049743; Tue, 31 Jan 2023 16:58:52 +0100 Date: Tue, 31 Jan 2023 16:58:51 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] middle-end/108500 - replace recursive domtree DFS traversal Message-ID: Reply-To: Jakub Jelinek References: <20230131144544.452FD13585@imap2.suse-dmz.suse.de> MIME-Version: 1.0 In-Reply-To: <20230131144544.452FD13585@imap2.suse-dmz.suse.de> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-9.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,RCVD_IN_MSPIKE_H2,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: On Tue, Jan 31, 2023 at 03:45:43PM +0100, Richard Biener wrote: > The following replaces the recursive DFS traversal of the dominator > tree in assign_dfs_numbers with a tree traversal using the fact > that we have recorded parents. > > Bootstrapped and tested on x86_64-unknown-linux-gnu. > > This makes r13-5325 somewhat obsolete, though not computing the > DFS numbers at all is beneficial in the cases where we perform > immediate CFG manipulations. > > OK for trunk and later branch(es)? > > Thanks, > Richard. > > PR middle-end/108500 > * dominance.cc (assign_dfs_numbers): Replace recursive DFS > with tree traversal algorithm. LGTM. > diff --git a/gcc/dominance.cc b/gcc/dominance.cc > index 099b8fd3f24..34fabe40c18 100644 > --- a/gcc/dominance.cc > +++ b/gcc/dominance.cc > @@ -639,18 +639,25 @@ dom_info::calc_idoms () > static void > assign_dfs_numbers (struct et_node *node, int *num) > { > - struct et_node *son; > - > - node->dfs_num_in = (*num)++; > - > - if (node->son) > + et_node *n = node; > + while (1) > { > - assign_dfs_numbers (node->son, num); > - for (son = node->son->right; son != node->son; son = son->right) > - assign_dfs_numbers (son, num); > + n->dfs_num_in = (*num)++; > + if (n->son) > + n = n->son; > + else > + { > + while (!n->right || n->right == n->father->son) Am I right that we could replace !n->right with n == node here too (i.e. only node can have NULL father and in that case also NULL left/right? Though !n->right might result in better code because we need to load it anyway for the second comparison. > + { > + n->dfs_num_out = (*num)++; > + if (n == node) > + return; > + n = n->father; > + } > + n->dfs_num_out = (*num)++; > + n = n->right; > + } > } > - > - node->dfs_num_out = (*num)++; > } > Jakub