From patchwork Tue Jan 3 10:28:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 38358 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4540598wrt; Tue, 3 Jan 2023 02:29:30 -0800 (PST) X-Google-Smtp-Source: AMrXdXtnoHUE1bcjilvYlzdfXliI39m2Yo7ltUCtAGiWryBMolWFQE020+mPomZX4WMb0W25kcBl X-Received: by 2002:a17:906:a14c:b0:7c0:b4bb:919 with SMTP id bu12-20020a170906a14c00b007c0b4bb0919mr42242489ejb.10.1672741770753; Tue, 03 Jan 2023 02:29:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672741770; cv=none; d=google.com; s=arc-20160816; b=g1mnKcCRCb3S6ggzO/HtiEYujvgwHLooJa1LShirGHG+55vQfay8L7JuGQTIGQ2NEX oju5s4IgJG48HOyzbobIFo9WDvyMAbGyfGMMgW8c1GSHGfsU/KE0KTKRmo5jGmzxC2fJ pfB8oqapVJ/1QkDuRniRpsoVnYhshC/Y2v+Dx9Uq04M7TKvZDTzkxvSSiDoAfx/tX8mZ kKa5GclF6Ps+sFejQlaU2puHSf8+rsq8L6gMfpfEKJwhF8Kx655ZjNNCAvyotIzIX15/ FixUYTII6XbsvoMPg5yhaZk1Pkk+HlxiksXcMvtWSj2ZBE7raI9mdmtc3mi/q8XeX84z vscg== 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 :delivered-to:dkim-signature:dkim-filter; bh=JsGAANcad8mvo/CljYmR/OGKTxJsSimi4lZPIngyNqE=; b=boH3/VmKFhHIDy9wCZUvPESRhD1TswKyRmW2EoVAIyBvXyVmWm1gzHSKH/fVXd/lC5 LaPgHR+fQ2Mjhb/Xcir8qNRk3aNhfqN6OfJC9ueGI+X/h4IBfYGLJ/+ZCk5G9i4LNKaL OhMXHKQgJt9jsa/RmpUM43wzakd7HF4x92JprPabOC+nG+hgLXbvyZXb96D0Z4y0l99z cPZbu9NZ+ldTAgI8qpUpet82i2AYL6BU4eVGWTExk2gK4rMNlXXcd84dTypB4tyx43N6 ZKiKIWFL8Bf3dmsr+7Sy2abrfMOCWRIXyxK2V1U/SgynTq2KhJw8CafJFr/ifC0godQa jMow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=mP1iU1dO; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id cr11-20020a170906d54b00b00787ad97302asi25702444ejc.863.2023.01.03.02.29.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 02:29:30 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=mP1iU1dO; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 BB3C23858D37 for ; Tue, 3 Jan 2023 10:29:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BB3C23858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1672741769; bh=JsGAANcad8mvo/CljYmR/OGKTxJsSimi4lZPIngyNqE=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=mP1iU1dOuVPPQoVCyK4FarkhUZAh8X1SQnh+BpdKiE+GTdPoRHTnI8DvFIjBnNBwQ rJVQp7fpVTGmkePCkQodOFadwaxMoFqq8O0NtIGmM7ZEoTgz7KhG2D/Kzi1NKMxxFE Vt9wYE3drD2yojSM/R4u7QIHxrIktvViskKgGUIA= 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 6C32E3858D1E for ; Tue, 3 Jan 2023 10:28:47 +0000 (GMT) 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-595-Caprhu_9Ooy-WRjns8RhYQ-1; Tue, 03 Jan 2023 05:28:44 -0500 X-MC-Unique: Caprhu_9Ooy-WRjns8RhYQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 98D0D3C14844; Tue, 3 Jan 2023 10:28:43 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 57AB6C15BA0; Tue, 3 Jan 2023 10:28:43 +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 303ASeTg278945 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 3 Jan 2023 11:28:40 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 303ASdvq278944; Tue, 3 Jan 2023 11:28:39 +0100 Date: Tue, 3 Jan 2023 11:28:39 +0100 To: Richard Biener , Jeff Law Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] cfgrtl: Don't try to redirect asm goto to EXIT [PR108263] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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?1753996874983573373?= X-GMAIL-MSGID: =?utf-8?q?1753996874983573373?= Hi! The following testcase distilled from Linux kernel on ppc64le ICEs, because fixup_reorder_chain sees a bb with a single fallthru edge falling into a bb with simple return and decides to redirect that fallthru edge to EXIT. That is possible if the bb ending in the fallthru edge doesn't end with a jump or ends with a normal unconditional jump, but not when the bb ends with asm goto which can despite a single fallthru have multiple labels to the fallthrough basic block. The following patch makes sure we never try to redirect such cases to EXIT. Bootstrapped/regtested on x86_64-linux, i686-linux and s390x-linux, ok for trunk? 2023-01-03 Jakub Jelinek PR rtl-optimization/108263 * cfgrtl.cc (fixup_reorder_chain): Avoid trying to redirect asm goto to EXIT. * gcc.dg/pr108263.c: New test. Jakub --- gcc/cfgrtl.cc.jj 2023-01-02 09:32:32.000000000 +0100 +++ gcc/cfgrtl.cc 2023-01-02 14:13:40.658338194 +0100 @@ -3910,6 +3910,7 @@ fixup_reorder_chain (void) rtx ret_label = NULL_RTX; basic_block nb; edge_iterator ei; + bool asm_goto = false; if (EDGE_COUNT (bb->succs) == 0) continue; @@ -4016,7 +4017,9 @@ fixup_reorder_chain (void) || e_fall->dest == EXIT_BLOCK_PTR_FOR_FN (cfun)) continue; - /* Otherwise we'll have to use the fallthru fixup below. */ + /* Otherwise we'll have to use the fallthru fixup below. + But avoid redirecting asm goto to EXIT. */ + asm_goto = true; } else { @@ -4048,7 +4051,8 @@ fixup_reorder_chain (void) return rather than a jump to the return block. */ rtx_insn *ret, *use; basic_block dest; - if (bb_is_just_return (e_fall->dest, &ret, &use) + if (!asm_goto + && bb_is_just_return (e_fall->dest, &ret, &use) && ((PATTERN (ret) == simple_return_rtx && targetm.have_simple_return ()) || (PATTERN (ret) == ret_rtx && targetm.have_return ()))) { --- gcc/testsuite/gcc.dg/pr108263.c.jj 2023-01-02 14:09:49.381614027 +0100 +++ gcc/testsuite/gcc.dg/pr108263.c 2023-01-02 14:07:16.899772608 +0100 @@ -0,0 +1,25 @@ +/* PR rtl-optimization/108263 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +int v, *p; + +void +foo (void) +{ + int i; + for (i = 0; ; i++) + { + if (v) + { + __label__ l1; + asm goto ("" : : : : l1); + l1: + return; + } + if (p[i]) + break; + } + asm goto ("" : : "r" (i) : : l2); +l2:; +}