From patchwork Tue Oct 29 20:56:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 99791 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 4B89C3858414 for ; Tue, 29 Oct 2024 20:56:54 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 8C4FD3858C60 for ; Tue, 29 Oct 2024 20:56:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8C4FD3858C60 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8C4FD3858C60 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730235389; cv=none; b=CyWuGTZ/a4+EmnT5BIO4+cwZTx9hzUwJv5AN9c2RLYgUIpV/HjVoLc6brWqxbAN16BV9DWG6jOmGB8STCP9Gi4Ho+Bh5Z64tTCIOKaKblVOnv6gZr9NLaHyuNhKYEsHdC3uUl122Jg+j5LFY1po2VcJ+PlFMv6GSoLCziEDLR14= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730235389; c=relaxed/simple; bh=e9aBCRlOaCX6zku/J+qF8kUx7t+ubZlmRHfneXDGZ5A=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=rVu9UbdyytLmpvqINa5SKxBOBbhQSQ4bDyxQVFT/yjPGKE//iHgUjzfql1LbTKq+wXx9t1kDtR1/FKh0IG+TtDeO07vRGG5em/F1IxLG1AX/ST4314XLknau/Gc4gsbelTq5GutfX6xJVU/rMymW+3NNltJk8U8Q9BPOBRn6LCw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-37d4fd00574so170075f8f.0 for ; Tue, 29 Oct 2024 13:56:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1730235385; x=1730840185; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=+ZnIPq7JHzk5dDjivl7lJe3DQjPgx5q1RFsWZzTSB/g=; b=gHI+X8Gny1P2dySBtXQqst/AyH+E4c2STU9mJ3do61c64g3OdzZpyURxw0FOeEbaHq +w9+8/gt+f4Su6aTLDPdrkQAq7XoTa3aluIPRQUqaz3D/cS6PAupnp1UzblMMeFrqy8h EZ6J7+hMNx8I6o3ZXYnxDrVPMmFbQI0D0myJmqg8iyq72kn4KTq5UF5f5qi/IV4Bph9l wYsPQl3VyDrv8CiCPw52GtR8pndXBV3eVPJa88Pc+f1FK9stgKx+X2R+bjOUVypj8iAS KOrGMy3AlOA12249uKDr4HbAdrRduIs7e9H+C8kXxMOJjobZjpuVxzhb31wxrVKVoZVV zRbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730235385; x=1730840185; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+ZnIPq7JHzk5dDjivl7lJe3DQjPgx5q1RFsWZzTSB/g=; b=TvOP+TEvFtrpxpaUKh+R6jgbKH3gPmuDzno+pS48LxpRmBecbt9t/kslxj2HnIUljG UOEsJLmgMSrbSwIltJHPx89dpjjZNEdxPG41ZmgfV0uNRk1fWhZuCvjGVcz/MBPZ+FdC T3Gv+QCq2zb81mr9cGjkmTED3mCK1D4YKDdyGHvQTCP/8fkR7kYbvS+V/HyFYpBQkePf pm23V9g8ftXQLvW0PZwFbbEwOCIMcLyyRP1x7W9dWC/RJahUdNkO9xUSiYL8WPLPRPCP VoZ1jxj04v1VFdPoD3Yp9s3XRQz+CkM1tn0OsHe0Xz/Tw4bS0RWLxSbnPsLxgfHLGlms C2lQ== X-Gm-Message-State: AOJu0YxE2KLTveOakbbBUQbesk5qSbYaiO9hDOMPIj/NwMfWaDdjfgks XRuNLYdw2PVXj/FqFvpXUpc3Il1zXi5CM9ytVd7mjdbQZe01Ys/ZMwOkDhYCiveu9txOnjeqGhg = X-Google-Smtp-Source: AGHT+IHKSh3CYqT/WP7JmvLmjN0BcENWBBjFQNySC4K280qS5HGcEy1XWz4RbPbjU4hvez8Mpcxb/A== X-Received: by 2002:adf:ec92:0:b0:374:c21a:9dd4 with SMTP id ffacd0b85a97d-3817d636ca4mr3336119f8f.20.1730235385107; Tue, 29 Oct 2024 13:56:25 -0700 (PDT) Received: from fomalhaut.localnet ([2a01:e0a:8d5:d990:e654:e8ff:fe8f:2ce6]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38058b928cesm13616901f8f.102.2024.10.29.13.56.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 13:56:24 -0700 (PDT) From: Eric Botcazou X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: Fix PR rtl-optimization/117327 Date: Tue, 29 Oct 2024 21:56:23 +0100 Message-ID: <4417140.UPlyArG6xL@fomalhaut> MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org This is a wrong-code generation on the SPARC for a function containing a call to __builtin_unreachable caused by the delay slot scheduling pass, and more specifically the find_end_label function which has these lines: /* Otherwise, see if there is a label at the end of the function. If there is, it must be that RETURN insns aren't needed, so that is our return label and we don't have to do anything else. */ The comment was correct 20 years ago but no longer is nowadays in the presence of RTL epilogues and calls to __builtin_unreachable, so the patch just removes the associated two lines of code: else if (LABEL_P (insn)) *plabel = as_a (insn); and otherwise contains just adjustments to the commentary. Bootstrapped/regtested on SPARC64/Solaris and applied on all active branches. 2024-10-29 Eric Botcazou PR rtl-optimization/117327 * reorg.cc (find_end_label): Do not return a dangling label at the end of the function and adjust commentary. 2024-10-29 Eric Botcazou * gcc.c-torture/execute/20241029-1.c: New test. diff --git a/gcc/reorg.cc b/gcc/reorg.cc index 51321ce7b80..68bf30801cf 100644 --- a/gcc/reorg.cc +++ b/gcc/reorg.cc @@ -336,13 +336,14 @@ insn_sets_resource_p (rtx insn, struct resources *res, return resource_conflicts_p (&insn_sets, res); } -/* Find a label at the end of the function or before a RETURN. If there - is none, try to make one. If that fails, returns 0. +/* Find a label before a RETURN. If there is none, try to make one; if this + fails, return 0. KIND is either ret_rtx or simple_return_rtx, indicating + which type of RETURN we're looking for. - The property of such a label is that it is placed just before the - epilogue or a bare RETURN insn, so that another bare RETURN can be - turned into a jump to the label unconditionally. In particular, the - label cannot be placed before a RETURN insn with a filled delay slot. + The property of the label is that it is placed just before a bare RETURN + insn, so that another bare RETURN can be turned into a jump to the label + unconditionally. In particular, the label cannot be placed before a + RETURN insn with a filled delay slot. ??? There may be a problem with the current implementation. Suppose we start with a bare RETURN insn and call find_end_label. It may set @@ -353,9 +354,7 @@ insn_sets_resource_p (rtx insn, struct resources *res, Note that this is probably mitigated by the following observation: once function_return_label is made, it is very likely the target of a jump, so filling the delay slot of the RETURN will be much more - difficult. - KIND is either simple_return_rtx or ret_rtx, indicating which type of - return we're looking for. */ + difficult. */ static rtx_code_label * find_end_label (rtx kind) @@ -375,10 +374,7 @@ find_end_label (rtx kind) if (*plabel) return *plabel; - /* Otherwise, see if there is a label at the end of the function. If there - is, it must be that RETURN insns aren't needed, so that is our return - label and we don't have to do anything else. */ - + /* Otherwise, scan the insns backward from the end of the function. */ insn = get_last_insn (); while (NOTE_P (insn) || (NONJUMP_INSN_P (insn) @@ -386,9 +382,8 @@ find_end_label (rtx kind) || GET_CODE (PATTERN (insn)) == CLOBBER))) insn = PREV_INSN (insn); - /* When a target threads its epilogue we might already have a - suitable return insn. If so put a label before it for the - function_return_label. */ + /* First, see if there is a RETURN at the end of the function. If so, + put the label before it. */ if (BARRIER_P (insn) && JUMP_P (PREV_INSN (insn)) && PATTERN (PREV_INSN (insn)) == kind) @@ -397,8 +392,8 @@ find_end_label (rtx kind) rtx_code_label *label = gen_label_rtx (); LABEL_NUSES (label) = 0; - /* Put the label before any USE insns that may precede the RETURN - insn. */ + /* Put the label before any USE insns that may precede the + RETURN insn. */ while (GET_CODE (temp) == USE) temp = PREV_INSN (temp); @@ -406,15 +401,12 @@ find_end_label (rtx kind) *plabel = label; } - else if (LABEL_P (insn)) - *plabel = as_a (insn); + /* If the basic block reordering pass has moved the return insn to some + other place, try to locate it again and put the label there. */ else { rtx_code_label *label = gen_label_rtx (); LABEL_NUSES (label) = 0; - /* If the basic block reorder pass moves the return insn to - some other place try to locate it again and put our - function_return_label there. */ while (insn && ! (JUMP_P (insn) && (PATTERN (insn) == kind))) insn = PREV_INSN (insn); if (insn)