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: 33913 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp857242wrn; Fri, 16 Dec 2022 01:11:51 -0800 (PST) X-Google-Smtp-Source: AA0mqf4jtohOddKX9BuGsNWTtuUT30Wq86WHtqom/n/r1+WfU3B4zO2WQnmO98S4K/9Blj2ak0by X-Received: by 2002:a17:906:49c2:b0:7ad:acdf:d08f with SMTP id w2-20020a17090649c200b007adacdfd08fmr27941980ejv.11.1671181911098; Fri, 16 Dec 2022 01:11:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671181911; cv=none; d=google.com; s=arc-20160816; b=qOtcf8azCV2zH/Gs/tuZftwBMzzQVvz1a7rsT9dxsaJRgRlIAETzz1yyLNJoEpZod5 S4gIO4Vhk2HSYSpwAzogNHHS/I5Bp7P/2bknyFYuvzDdVccI+53dhc61c+nODZ1wugMN rVONApMkI+MGPm7hZ/V9LflHhB7Spl5VQm9lxUy7U4JtMICyMGaBNlozlDAlxZuzuNVW n5gAd3djHTnnhvjLEHtX1vk3lM/pv7o7NL1MJTV2ffRKcgeYQEiO8LjOobOSTVGNVVg8 KMqH827V6iIjd0/a0VW2Z9XxofqFXFaKztnucxeZmMuRiIhEBo+qBlBQxWwxurXAEIH9 bUNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=DNAoV3/DW5ENsa7ClF1bAH2KFcHcmUoAQ58W7O04ES0=; b=uHE1WVN50O8/iXwMhbHmW/MhLMQOJbHXr1zKbwCbDClOcD6atjB82cIPCNaps7uT59 A4dHQDLhlUGNJeDN4bbf3FPtq9uHFXguRx9SBfoKcAR96zfvdy2fryGNggyt6zP3hk86 k1AIsd+csgXBtFRxSt+TihkbWKNF3gdyr/XF89JoSiyYqOM3DNTaNKTfO8ICNOkLN5QH jklCLyRGPn3YCoW1hYiYlrCDM0xDRga7dvgXVeH4+9qisfqGZW92C0xY6Q2xwCpXq2KP BIrEC5zgRaFn5/c1d3h1uPU+mWvuB0ewcQTA0pi/XmHg2SutMMdOrSQzZXcDDncdBEiB m3xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=auzAsdVL; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id cw11-20020a170906478b00b007b889a69895si2381799ejc.589.2022.12.16.01.11.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Dec 2022 01:11:51 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=auzAsdVL; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D8C03383F95C for ; Fri, 16 Dec 2022 09:11:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D8C03383F95C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671181909; 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=auzAsdVLlLbvX9Jfhw2bf6ZfUASfzKHryVhHD0oG1lhOVEo/XRJPKpkOCrxC5Nqe7 fRem9irKTc+K4gDfLYR6O5uxrnmP1QUCZiPIwwkn78h0yIgLNEFboKHwZ8ncacpAJ5 vJ1clJQBag48dzxuafBj8Ej4Dbnboi7AILx7drE4= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752361244079128971?= X-GMAIL-MSGID: =?utf-8?q?1752361244079128971?= 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; + } +}