From patchwork Fri Dec 16 09:10:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 61990 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 5798B3873863 for ; Fri, 16 Dec 2022 09:11:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5798B3873863 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671181894; bh=DNAoV3/DW5ENsa7ClF1bAH2KFcHcmUoAQ58W7O04ES0=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=L2aiFyt8efQ5Rvjd71c9XH18cGsVMQftzMuuRfb1oEACuaa25sdKPrOmeA4DFTnIj fPzJTCsqrzMhfghcuL+E6J0hZ5HB+0coX2fgYBK/hjsw76XIlvK3fv+vPK0eG3K2Ds MXPdxG7eGmQJSBJQqkDRlk4g/VL5AJrWf58/Mg6c= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 1BF65383B6BE for ; Fri, 16 Dec 2022 09:11:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1BF65383B6BE Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-7-hiXqc-lvOTenZpDmYXr3FA-1; Fri, 16 Dec 2022 04:10:59 -0500 X-MC-Unique: hiXqc-lvOTenZpDmYXr3FA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BDB2C1C09040; Fri, 16 Dec 2022 09:10:58 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.114]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7857E492C14; Fri, 16 Dec 2022 09:10:58 +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 2BG9At9K2488267 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 16 Dec 2022 10:10:56 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2BG9AsdC2488266; Fri, 16 Dec 2022 10:10:54 +0100 Date: Fri, 16 Dec 2022 10:10:54 +0100 To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] loop-invariant: Split preheader edge if the preheader bb ends with jump [PR106751] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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 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: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi! The RTL loop passes only request simple preheaders, but don't require fallthru preheaders, while move_invariant_reg apparently assumes the latter, that it can just append instruction(s) to the end of the preheader basic block. The following patch fixes that by splitting the preheader edge if the preheader bb ends with a JUMP_INSN (asm goto in this case). Without that we get control flow in the middle of a bb. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2022-12-16 Jakub Jelinek PR rtl-optimization/106751 * loop-invariant.cc (move_invariant_reg): If preheader bb ends with a JUMP_INSN, split the preheader edge and emit invariants into the new preheader basic block. * gcc.c-torture/compile/pr106751.c: New test. Jakub --- gcc/loop-invariant.cc.jj 2022-01-18 11:58:59.683980614 +0100 +++ gcc/loop-invariant.cc 2022-12-15 17:14:32.906883258 +0100 @@ -1837,6 +1837,8 @@ move_invariant_reg (class loop *loop, un else if (dump_file) fprintf (dump_file, "Invariant %d moved without introducing a new " "temporary register\n", invno); + if (JUMP_P (BB_END (preheader))) + preheader = split_edge (loop_preheader_edge (loop)); reorder_insns (inv->insn, inv->insn, BB_END (preheader)); df_recompute_luids (preheader); --- gcc/testsuite/gcc.c-torture/compile/pr106751.c.jj 2022-12-15 17:44:35.602519711 +0100 +++ gcc/testsuite/gcc.c-torture/compile/pr106751.c 2022-12-15 17:44:21.789721827 +0100 @@ -0,0 +1,17 @@ +/* PR rtl-optimization/106751 */ + +int *foo (void); + +void +bar (void) +{ + asm goto ("" : : : : lab); + __builtin_unreachable (); +lab: + while (1) + { + int o; + asm ("" : "=r" (o) : "g" (1)); + *foo () = o; + } +}