From patchwork Tue Jan 31 08:18:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 50675 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2625715wrn; Tue, 31 Jan 2023 00:19:13 -0800 (PST) X-Google-Smtp-Source: AMrXdXusbZKv1TxT5f1yV4ZyFvIG/7sHtpX0aijwbWOBTZ/3OymmBFr/e1LxJaFhKyvgzE59pnYS X-Received: by 2002:a05:6402:28ca:b0:499:c294:77af with SMTP id ef10-20020a05640228ca00b00499c29477afmr57750172edb.12.1675153153239; Tue, 31 Jan 2023 00:19:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675153153; cv=none; d=google.com; s=arc-20160816; b=tfFu3RrAtvBGh7xxCeLtffH3aoEP2mfBH0+IuRGx/JGEjvz/A7N5UVUFlwMIYo0iUV w64UEo3CfA855YuHnhXFKXq4zYiQFx8ZUx65BT1mmzhcATnqaPyqvhX5J3319oJ+rO6b YuuKRfezL3GanSObrHEl4JRTKbKrHrxHmcFpotmN1ENnOh1WSXlEej96nqIrHehRww9O uqoiQkYD/aURkDmAl18wWp+i63kIRgWQV1a/Q5P8Cf8iq9W8ytR4GkQ9c8CHqeVKagZK ZzuABEq+8ISxA3qwYhhrb8oYer0/YSrYTDGOOd+ipf2p2O596JSHVPcjByTjG65p6Im+ HfKA== 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=YMHZAHy/TXdZ2CyXrSFxergp6SIFoPAwxc1nfQ+eeOk=; b=dw/E/vXP2WEF7p5eruPvJPWXLBWVp2Nq8wCj1l89IGYxWPEfkrLLRQg+VUz6R2jmwN R44QkDrGU034QeG7lArAwe+93otQ9lNOEf/CYKkt4TkdTtGmqRwykyKWHyTJXbJrCfOS sQYjRl7FJwEsTCDk2oW4kmYYmQlt0Tr5EDXykhhyg0DJtFeSeUwdWli9zw9de9qhOmGp 7CLK9sjv+ZGriQ0ki4Ck8HPGVEAS1rMCxD1OoZUdqGh/hCPwAGx99zMV9ZMcYdF6W8jQ RtCZqygvcqw5DWk0n6CpFqnAW9XRL6bNWOl1hAs9xBFFFWFzN8Nu92EOjjcIPkw2gtOF tuGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pdL0Va7J; 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 u7-20020a50eac7000000b00489df0e67aasi17463426edp.549.2023.01.31.00.19.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 00:19:13 -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=pdL0Va7J; 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 09F063858CDA for ; Tue, 31 Jan 2023 08:19:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 09F063858CDA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675153152; bh=YMHZAHy/TXdZ2CyXrSFxergp6SIFoPAwxc1nfQ+eeOk=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=pdL0Va7Jgj+ydtp6q6hvg4rnS0qAxkRwe7mlA4M0DGRHT9uBymLxOdlnh5KGZUK+6 pg4QeCKUUPZZLNGsqhe+opaU7hDvAOUCvqNk5xNl6TQwup8zTP9Vn2DegahXkg9him r5lBzC0YK4OXKPqz9Sn999+NcbB0WzdGCl+Mdbdo= 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 6A8053858D1E for ; Tue, 31 Jan 2023 08:18:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6A8053858D1E 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-483-qMu22lQvPE-RdMD1LSEwtg-1; Tue, 31 Jan 2023 03:18:24 -0500 X-MC-Unique: qMu22lQvPE-RdMD1LSEwtg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 45F0085A588; Tue, 31 Jan 2023 08:18:24 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 00A1540C2064; Tue, 31 Jan 2023 08:18:23 +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 30V8ILHK1011645 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 31 Jan 2023 09:18:21 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 30V8IJVU1011644; Tue, 31 Jan 2023 09:18:19 +0100 Date: Tue, 31 Jan 2023 09:18:18 +0100 To: Jan Hubicka , Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] bbpart: Fix up ICE on asm goto [PR108596] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.5 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?1756525392973389735?= X-GMAIL-MSGID: =?utf-8?q?1756525392973389735?= Hi! On the following testcase we have asm goto in hot block with 2 successors, one cold to which it both falls through and has one of the label pointing to it and another hot successor with another label. Now, during bbpart we want to ensure that no blocks from one partition fall through into a block in a different partition. fix_up_fall_thru_edges does that by temporarily clearing the EDGE_CROSSING on the fallthrough edge, calling force_nonfallthru and then depending on whether it created a new bb either set EDGE_CROSSING on the single successor edge from the new bb (the new bb is kept in the same partition as the predecessor block), or if no new bb has been created setting EDGE_CROSSING back on the fallthru edge which has been forced non-EDGE_FALLTHRU. For asm goto this doesn't always work, force_nonfallthru can create a new bb and change the fallthrough edge to point to that, but if the original fallthru destination block has its label referenced among the asm goto labels, it will create a new non-fallthru edge for the label(s). But because we've temporarily cheated and cleared EDGE_CROSSING on the edge, it is cleared on the new edge as well, then the caller sees we've created a new bb and just sets EDGE_CROSSING on the single fallthru edge from the new bb. But the direct edge from cur_bb to fallthru edge's destination isn't handled and fails afterwards consistency checks, because it crosses partitions. The following patch notes the case and sets EDGE_CROSSING on that edge too. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-01-31 Jakub Jelinek PR rtl-optimization/108596 * bb-reorder.cc (fix_up_fall_thru_edges): Handle the case where cur_bb ends with asm goto and has a crossing fallthrough edge to the same bb that contains at least one of its labels by restoring EDGE_CROSSING flag even on possible edge from cur_bb to new_bb successor. * gcc.c-torture/compile/pr108596.c: New test. Jakub --- gcc/bb-reorder.cc.jj 2023-01-02 09:32:39.000000000 +0100 +++ gcc/bb-reorder.cc 2023-01-30 17:59:29.222096645 +0100 @@ -1998,6 +1998,7 @@ fix_up_fall_thru_edges (void) becomes EDGE_CROSSING. */ fall_thru->flags &= ~EDGE_CROSSING; + unsigned old_count = EDGE_COUNT (cur_bb->succs); basic_block new_bb = force_nonfallthru (fall_thru); if (new_bb) @@ -2009,7 +2010,25 @@ fix_up_fall_thru_edges (void) gcc_assert (BB_PARTITION (new_bb) == BB_PARTITION (cur_bb)); - single_succ_edge (new_bb)->flags |= EDGE_CROSSING; + edge e = single_succ_edge (new_bb); + e->flags |= EDGE_CROSSING; + if (EDGE_COUNT (cur_bb->succs) > old_count) + { + /* If asm goto has a crossing fallthrough edge + and at least one of the labels to the same bb, + force_nonfallthru can result in the fallthrough + edge being redirected and a new edge added for the + label or more labels to e->dest. As we've + temporarily cleared EDGE_CROSSING flag on the + fallthrough edge, we need to restore it again. + See PR108596. */ + rtx_insn *j = BB_END (cur_bb); + gcc_checking_assert (JUMP_P (j) + && asm_noperands (PATTERN (j))); + edge e2 = find_edge (cur_bb, e->dest); + if (e2) + e2->flags |= EDGE_CROSSING; + } } else { --- gcc/testsuite/gcc.c-torture/compile/pr108596.c.jj 2023-01-30 18:01:02.252730008 +0100 +++ gcc/testsuite/gcc.c-torture/compile/pr108596.c 2023-01-30 18:00:32.405168470 +0100 @@ -0,0 +1,26 @@ +/* PR rtl-optimization/108596 */ + +__attribute__((__cold__)) void foo (void); +void bar (void); + +void +baz (void) +{ + asm goto ("" : : : : l1, l0); + goto l0; +l1: + bar (); +l0: + foo (); +} + +void +qux (void) +{ + asm goto ("" : : : : l1, l0); + __builtin_unreachable (); +l1: + bar (); +l0: + foo (); +}