From patchwork Tue Dec 14 20:18:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 48916 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 2B2A23858426 for ; Tue, 14 Dec 2021 20:18:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2B2A23858426 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1639513128; bh=8btHIl9MyWRRoQ2nSW7eoKjfMGcvoI/oto+RrR7HsXs=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=mIWIIoJBSpaTkfjS0UPONN5rSqV39rFDjVW+aktGgNKzrRi4sJqdSl+j8EIc7Vxif gclrQ8QxzrRbHJtbZjZN4w23dggIi2K45ER+kSlIF92vTZYOBYPwHO1CYIiCjz35/Z 3IYq27feYhclqvSORCQDs8/t+O1el6q8bZmGtAno= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id D13E93858412 for ; Tue, 14 Dec 2021 20:18:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D13E93858412 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-382-3rB6bp3aNU60m43aZ6-NJg-1; Tue, 14 Dec 2021 15:18:15 -0500 X-MC-Unique: 3rB6bp3aNU60m43aZ6-NJg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BA5DB2F25; Tue, 14 Dec 2021 20:18:13 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.2.16.169]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F3F7B5F6C5; Tue, 14 Dec 2021 20:18:12 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 1BEKIA7F776956 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 14 Dec 2021 21:18:10 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 1BEKI9Id776955; Tue, 14 Dec 2021 21:18:09 +0100 Date: Tue, 14 Dec 2021 21:18:09 +0100 To: Jeff Law Subject: [PATCH] dwarf2cfi: Improve cfa_reg comparisons [PR103619] Message-ID: <20211214201809.GA2646553@tucnak> References: <20211209173202.1522247-1-abidh@codesourcery.com> <20211214165319.GY2646553@tucnak> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 Cc: ams@codesourcery.com, gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" On Tue, Dec 14, 2021 at 10:32:21AM -0700, Jeff Law wrote: > I think the attached testcase should trigger on c6x with -mbig-endian -O2 -g Thanks. Finally I see what's going on. c6x doesn't really need the CFA with span > 1 (and I bet neither does armbe), the only reason why dwf_cfa_reg is called is that the code in 13 cases just tries to compare the CFA against dwf_cfa_reg (some_reg). And that dwf_cfa_reg on some reg that usually isn't a CFA reg results in targetm.dwarf_register_span hook call, which on targets like c6x or armeb and others for some registers creates a PARALLEL with various REGs in it, then the loop with the assertion and finally operator== which just notes that the reg is different and fails. This seems compile time memory and time inefficient. The following so far untested patch instead adds an extra operator== and != for comparison of cfa_reg with rtx, which has the most common case where it is a different register number done early without actually invoking dwf_cfa_reg. This means the assertion in dwf_cfa_reg can stay as is (at least until some big endian target needs to have hard frame pointer or stack pointer with span > 1 as well). I've removed a different assertion there because it is redundant - dwf_regno already has exactly that assertion in it too. And I've included those 2 tweaks to avoid creating a REG in GC memory when we can use {stack,hard_frame}_pointer_rtx which is already initialized to the same REG we need by init_emit_regs. Ok for trunk if it passes bootstrap/regtest? 2021-12-14 Jakub Jelinek PR debug/103619 * dwarf2cfi.c (dwf_cfa_reg): Remove gcc_assert. (operator==, operator!=): New overloaded operators. (dwarf2out_frame_debug_adjust_cfa, dwarf2out_frame_debug_cfa_offset, dwarf2out_frame_debug_expr): Compare vars with cfa_reg type directly with REG rtxes rather than with dwf_cfa_reg results on those REGs. (create_cie_data): Use stack_pointer_rtx instead of gen_rtx_REG (Pmode, STACK_POINTER_REGNUM). (execute_dwarf2_frame): Use hard_frame_pointer_rtx instead of gen_rtx_REG (Pmode, HARD_FRAME_POINTER_REGNUM). Jakub --- gcc/dwarf2cfi.c.jj 2021-12-14 19:00:49.067607884 +0100 +++ gcc/dwarf2cfi.c 2021-12-14 20:29:19.138677618 +0100 @@ -1113,8 +1113,6 @@ dwf_cfa_reg (rtx reg) { struct cfa_reg result; - gcc_assert (REGNO (reg) < FIRST_PSEUDO_REGISTER); - result.reg = dwf_regno (reg); result.span = 1; result.span_width = 0; @@ -1144,6 +1142,25 @@ dwf_cfa_reg (rtx reg) return result; } +/* More efficient comparisons that don't call targetm.dwarf_register_span + unnecessarily. */ + +static bool +operator== (cfa_reg &cfa, rtx reg) +{ + unsigned int regno = dwf_regno (reg); + if (cfa.reg != regno) + return false; + struct cfa_reg other = dwf_cfa_reg (reg); + return cfa == other; +} + +static inline bool +operator!= (cfa_reg &cfa, rtx reg) +{ + return !(cfa == reg); +} + /* Compare X and Y for equivalence. The inputs may be REGs or PC_RTX. */ static bool @@ -1313,7 +1330,7 @@ dwarf2out_frame_debug_adjust_cfa (rtx pa switch (GET_CODE (src)) { case PLUS: - gcc_assert (dwf_cfa_reg (XEXP (src, 0)) == cur_cfa->reg); + gcc_assert (cur_cfa->reg == XEXP (src, 0)); cur_cfa->offset -= rtx_to_poly_int64 (XEXP (src, 1)); break; @@ -1346,11 +1363,11 @@ dwarf2out_frame_debug_cfa_offset (rtx se switch (GET_CODE (addr)) { case REG: - gcc_assert (dwf_cfa_reg (addr) == cur_cfa->reg); + gcc_assert (cur_cfa->reg == addr); offset = -cur_cfa->offset; break; case PLUS: - gcc_assert (dwf_cfa_reg (XEXP (addr, 0)) == cur_cfa->reg); + gcc_assert (cur_cfa->reg == XEXP (addr, 0)); offset = rtx_to_poly_int64 (XEXP (addr, 1)) - cur_cfa->offset; break; default: @@ -1797,7 +1814,7 @@ dwarf2out_frame_debug_expr (rtx expr) { /* Setting FP from SP. */ case REG: - if (cur_cfa->reg == dwf_cfa_reg (src)) + if (cur_cfa->reg == src) { /* Rule 1 */ /* Update the CFA rule wrt SP or FP. Make sure src is @@ -1828,7 +1845,7 @@ dwarf2out_frame_debug_expr (rtx expr) { gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM && fde->drap_reg != INVALID_REGNUM - && cur_cfa->reg != dwf_cfa_reg (src) + && cur_cfa->reg != src && fde->rule18); fde->rule18 = 0; /* The save of hard frame pointer has been deferred @@ -1852,8 +1869,7 @@ dwarf2out_frame_debug_expr (rtx expr) /* Adjusting SP. */ if (REG_P (XEXP (src, 1))) { - gcc_assert (dwf_cfa_reg (XEXP (src, 1)) - == cur_trace->cfa_temp.reg); + gcc_assert (cur_trace->cfa_temp.reg == XEXP (src, 1)); offset = cur_trace->cfa_temp.offset; } else if (!poly_int_rtx_p (XEXP (src, 1), &offset)) @@ -1886,7 +1902,7 @@ dwarf2out_frame_debug_expr (rtx expr) gcc_assert (frame_pointer_needed); gcc_assert (REG_P (XEXP (src, 0)) - && dwf_cfa_reg (XEXP (src, 0)) == cur_cfa->reg); + && cur_cfa->reg == XEXP (src, 0)); offset = rtx_to_poly_int64 (XEXP (src, 1)); if (GET_CODE (src) != MINUS) offset = -offset; @@ -1899,7 +1915,7 @@ dwarf2out_frame_debug_expr (rtx expr) /* Rule 4 */ if (REG_P (XEXP (src, 0)) - && dwf_cfa_reg (XEXP (src, 0)) == cur_cfa->reg + && cur_cfa->reg == XEXP (src, 0) && poly_int_rtx_p (XEXP (src, 1), &offset)) { /* Setting a temporary CFA register that will be copied @@ -1914,7 +1930,7 @@ dwarf2out_frame_debug_expr (rtx expr) /* Rule 5 */ else if (REG_P (XEXP (src, 0)) - && dwf_cfa_reg (XEXP (src, 0)) == cur_trace->cfa_temp.reg + && cur_trace->cfa_temp.reg == XEXP (src, 0) && XEXP (src, 1) == stack_pointer_rtx) { /* Setting a scratch register that we will use instead @@ -1945,7 +1961,7 @@ dwarf2out_frame_debug_expr (rtx expr) /* Rule 7 */ case IOR: gcc_assert (REG_P (XEXP (src, 0)) - && dwf_cfa_reg (XEXP (src, 0)) == cur_trace->cfa_temp.reg + && cur_trace->cfa_temp.reg == XEXP (src, 0) && CONST_INT_P (XEXP (src, 1))); cur_trace->cfa_temp.reg = dwf_cfa_reg (dest); @@ -1981,7 +1997,7 @@ dwarf2out_frame_debug_expr (rtx expr) dwarf2out_flush_queued_reg_saves (); gcc_assert (cur_trace->cfa_store.reg - == dwf_cfa_reg (XEXP (src, 0))); + == XEXP (src, 0)); fde->stack_realign = 1; fde->stack_realignment = INTVAL (XEXP (src, 1)); cur_trace->cfa_store.offset = 0; @@ -2109,8 +2125,7 @@ dwarf2out_frame_debug_expr (rtx expr) /* Rule 14 */ case POST_INC: - gcc_assert (cur_trace->cfa_temp.reg - == dwf_cfa_reg (XEXP (XEXP (dest, 0), 0))); + gcc_assert (cur_trace->cfa_temp.reg == XEXP (XEXP (dest, 0), 0)); offset = -cur_trace->cfa_temp.offset; cur_trace->cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest)); break; @@ -2128,7 +2143,7 @@ dwarf2out_frame_debug_expr (rtx expr) if (REG_P (src) && REGNO (src) != STACK_POINTER_REGNUM && REGNO (src) != HARD_FRAME_POINTER_REGNUM - && dwf_cfa_reg (src) == cur_cfa->reg) + && cur_cfa->reg == src) { /* We're storing the current CFA reg into the stack. */ @@ -3210,8 +3225,7 @@ create_cie_data (void) dw_cfa_location loc; dw_trace_info cie_trace; - dw_stack_pointer_regnum = dwf_cfa_reg (gen_rtx_REG (Pmode, - STACK_POINTER_REGNUM)); + dw_stack_pointer_regnum = dwf_cfa_reg (stack_pointer_rtx); memset (&cie_trace, 0, sizeof (cie_trace)); cur_trace = &cie_trace; @@ -3270,8 +3284,7 @@ static unsigned int execute_dwarf2_frame (void) { /* Different HARD_FRAME_POINTER_REGNUM might coexist in the same file. */ - dw_frame_pointer_regnum - = dwf_cfa_reg (gen_rtx_REG (Pmode, HARD_FRAME_POINTER_REGNUM)); + dw_frame_pointer_regnum = dwf_cfa_reg (hard_frame_pointer_rtx); /* The first time we're called, compute the incoming frame state. */ if (cie_cfi_vec == NULL)