From patchwork Fri Apr 21 13:36:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 1771956 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Y7UVyLmz; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q2wYK2Xlhz23tk for ; Fri, 21 Apr 2023 23:36:52 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9BB993857357 for ; Fri, 21 Apr 2023 13:36:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9BB993857357 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682084209; bh=SQkOBHjeYNNgE7J9yR4l0VUSYccqFBotvyN90RuaeM0=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Y7UVyLmzqBi+QRCvunMcAZNtEZTDXAv/pMTa8Yo69IL9XyOBzW9cS4ijZTxy8GCmo Xm4F1l5T08d9DrZbk5gbUKCtsA6DXGciSIr/VvgZ4cztT+bIOBDyFdGTmudbAfhgmr Jfak3y4l2WkPZAwqHOiIBZU7D/NBczg0q3vMezmo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nikam.ms.mff.cuni.cz (nikam.ms.mff.cuni.cz [195.113.20.16]) by sourceware.org (Postfix) with ESMTPS id 8B68F3858C83 for ; Fri, 21 Apr 2023 13:36:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8B68F3858C83 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 615E328A920; Fri, 21 Apr 2023 15:36:28 +0200 (CEST) Date: Fri, 21 Apr 2023 15:36:28 +0200 To: gcc-patches@gcc.gnu.org, kubanek0ondrej@gmail.com Subject: Fix loop-ch Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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: Jan Hubicka via Gcc-patches From: Jan Hubicka Reply-To: Jan Hubicka Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, Ondrej Kubanek implemented profiling of loop histograms which sould be useful to improve i.e. quality of loop peeling of verctorization. However it turns out that most of histograms are lost on the way from profiling to loop peeling pass (about 90%). One common case is the following latent bug in loop header copying which forgets to update the loop header pointer. Curiously enough it does work to make single latch and preheader edge by splitting basic blocks but it works with wrong edge. As a consequence every loop where loop header was copied is removed from loop tree and inserted again losing all metadata included. Patch correctly updates the loop structure and also add verification that the loop tree is OK after all transforms which is failing without the patch. Bootstrapped/regtested x86_64-linux, plan to insteall this as obvious. diff --git a/gcc/tree-ssa-loop-ch.cc b/gcc/tree-ssa-loop-ch.cc index 6b332719411..2c56b3b3c31 100644 --- a/gcc/tree-ssa-loop-ch.cc +++ b/gcc/tree-ssa-loop-ch.cc @@ -557,6 +557,17 @@ ch_base::copy_headers (function *fun) } } + /* Update header of the loop. */ + loop->header = header; + /* Find correct latch. We only duplicate chain of conditionals so + there should be precisely two edges to the new header. One entry + edge and one to latch. */ + FOR_EACH_EDGE (e, ei, loop->header->preds) + if (header != e->src) + { + loop->latch = e->src; + break; + } /* Ensure that the latch and the preheader is simple (we know that they are not now, since there was the loop exit condition. */ split_edge (loop_preheader_edge (loop)); @@ -583,6 +594,8 @@ ch_base::copy_headers (function *fun) if (changed) { + if (flag_checking) + verify_loop_structure (); update_ssa (TODO_update_ssa); /* After updating SSA form perform CSE on the loop header copies. This is esp. required for the pass before