From patchwork Fri Aug 7 09:00:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Senthil Kumar Selvaraj X-Patchwork-Id: 1342145 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=hGHhdh16; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BNK8D6QbBz9sPB for ; Fri, 7 Aug 2020 19:00:43 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DC27E3850426; Fri, 7 Aug 2020 09:00:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DC27E3850426 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1596790840; bh=LccV+XluDNzV1n0+EIjOnrrFFvzpgUt6opB74zvHrMY=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=hGHhdh16W9BSyp4+GqEvKbo+teXEgFrr02Uu9yxEKrWuJ67OwHRHomTJGHmVFMiLR 9erbwczG1KtHl7b38MJ5QZ8JPxXLMzTyC6QxpWaWOOYVAexitmxlPAljFHjlRMu+ms ihmqJw2Jlliuc49r1dY9kcfQaOWpuD2PL+NKhrxo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by sourceware.org (Postfix) with ESMTPS id E967D3858D35 for ; Fri, 7 Aug 2020 09:00:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E967D3858D35 Received: by mail-wr1-x441.google.com with SMTP id z18so943406wrm.12 for ; Fri, 07 Aug 2020 02:00:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=LccV+XluDNzV1n0+EIjOnrrFFvzpgUt6opB74zvHrMY=; b=GuiQJ0L/P1NNpTX4kM5Uql9BMZAujVtNOLB2nk9wZ7ehzO2V5lrN2qFkKO1ZgMy3a1 u2rbjRAef+/LOo+sNnhNZqRW0BtDGgKGn8DdMlRr1Zho4bt/FtobjAVdfTcXCV+mZyS3 ygqFIacJMTyI16MpC1souoiRcFioBRMZHlpo7p9L35XDfrOQK8Y0Kf3yRaDojPklNRer 3JmrP5rF/zhiJFVAgm+F3PFjLydDWX8p2g9aAJIiy4j5RqvrVnSE31Hurot4b2sEDeaL vG/RkWS699zWzeqdrRZkpOhce7SJljVgUSupAINPJcB7emQSxvGNOa9DBwlmDSDuwqMw Hn3A== X-Gm-Message-State: AOAM531a8BGGx8U5IHMwM/ajW9ypg39nG18eOKC/3rvEytvBAfxCBY6P pfrCqyFpN+V8a75N6WYN6bp+n29hD6InJVBPPMSaYMXW X-Google-Smtp-Source: ABdhPJxeCCdClMfiNMlEnHU3DEqVblqF5xu4IF1qHLHqY2Da1QXY86mXAaBKrxFYhTj6raAnNO8nBqj/dYgejypQGkA= X-Received: by 2002:a5d:6646:: with SMTP id f6mr11283035wrw.155.1596790837637; Fri, 07 Aug 2020 02:00:37 -0700 (PDT) MIME-Version: 1.0 Date: Fri, 7 Aug 2020 14:30:26 +0530 Message-ID: Subject: [PATCH] emit-rtl.c: Allow splitting of RTX_FRAME_RELATED_P insns? To: gcc-patches@gcc.gnu.org X-Spam-Status: No, score=-6.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Senthil Kumar via Gcc-patches From: Senthil Kumar Selvaraj Reply-To: Senthil Kumar Cc: ebotcazou@adacore.com Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, I'm working on converting the AVR backend to MODE_CC, following the steps described for case #2 in the CC0 transition wiki page, and I've implemented the first three bullet points (https://github.com/saaadhu/gcc-avr-cc0/tree/avr-cc0-squashed). With the below patch, there are zero regressions (for mega and xmega subarchs) compared to the current mainline, as of yesterday. The wiki suggests using post-reload splitters, so that's the direction I took, but I ran into an issue where split_insn bails out early if RTX_FRAME_RELATED_P is true - this means that splits for REG_CC clobbering insns with RTX_FRAME_RELATED_P will never execute, resulting in a could-not-split insn ICE in the final stage. I see that the recog.c:peep2_attempt allows splitting of a RTX_FRAME_RELATED_P insn, provided the result of the split is a single insn. Would it be ok to modify try_split also to allow those kinds of insns (tentative patch attached, code copied over from peep2_attempt, only setting old and new_insn)? Or is there a different approach to fix this? Regards Senthil gcc/ChangeLog: * emit-rtl.c (try_split): Allow splitting certain RTX_FRAME_RELATED_P insns. diff --git gcc/emit-rtl.c gcc/emit-rtl.c index f9b0e9714d9..7cf5704cf14 100644 --- gcc/emit-rtl.c +++ gcc/emit-rtl.c @@ -3822,10 +3822,6 @@ try_split (rtx pat, rtx_insn *trial, int last) int njumps = 0; rtx_insn *call_insn = NULL; - /* We're not good at redistributing frame information. */ - if (RTX_FRAME_RELATED_P (trial)) - return trial; - if (any_condjump_p (trial) && (note = find_reg_note (trial, REG_BR_PROB, 0))) split_branch_probability @@ -3842,6 +3838,7 @@ try_split (rtx pat, rtx_insn *trial, int last) if (!seq) return trial; + int split_insn_count = 0; /* Avoid infinite loop if any insn of the result matches the original pattern. */ insn_last = seq; @@ -3850,11 +3847,87 @@ try_split (rtx pat, rtx_insn *trial, int last) if (INSN_P (insn_last) && rtx_equal_p (PATTERN (insn_last), pat)) return trial; + split_insn_count++; if (!NEXT_INSN (insn_last)) break; insn_last = NEXT_INSN (insn_last); } + /* We're not good at redistributing frame information if + the split results in more than one insn */ + if (RTX_FRAME_RELATED_P (trial)) + { + if (split_insn_count != 1) + return trial; + + // Copy from recog.c:peep2_attempt + bool any_note = false; + rtx note; + rtx_insn *new_insn = seq; + rtx_insn *old_insn = trial; + + /* We have a 1-1 replacement. Copy over any frame-related info. */ + RTX_FRAME_RELATED_P (new_insn) = 1; + + /* Allow the backend to fill in a note during the split. */ + for (note = REG_NOTES (new_insn); note ; note = XEXP (note, 1)) + switch (REG_NOTE_KIND (note)) + { + case REG_FRAME_RELATED_EXPR: + case REG_CFA_DEF_CFA: + case REG_CFA_ADJUST_CFA: + case REG_CFA_OFFSET: + case REG_CFA_REGISTER: + case REG_CFA_EXPRESSION: + case REG_CFA_RESTORE: + case REG_CFA_SET_VDRAP: + any_note = true; + break; + default: + break; + } + + /* If the backend didn't supply a note, copy one over. */ + if (!any_note) + for (note = REG_NOTES (old_insn); note ; note = XEXP (note, 1)) + switch (REG_NOTE_KIND (note)) + { + case REG_FRAME_RELATED_EXPR: + case REG_CFA_DEF_CFA: + case REG_CFA_ADJUST_CFA: + case REG_CFA_OFFSET: + case REG_CFA_REGISTER: + case REG_CFA_EXPRESSION: + case REG_CFA_RESTORE: + case REG_CFA_SET_VDRAP: + add_reg_note (new_insn, REG_NOTE_KIND (note), XEXP (note, 0)); + any_note = true; + break; + default: + break; + } + + /* If there still isn't a note, make sure the unwind info sees the + same expression as before the split. */ + if (!any_note) + { + rtx old_set, new_set; + + /* The old insn had better have been simple, or annotated. */ + old_set = single_set (old_insn); + gcc_assert (old_set != NULL); + + new_set = single_set (new_insn); + if (!new_set || !rtx_equal_p (new_set, old_set)) + add_reg_note (new_insn, REG_FRAME_RELATED_EXPR, old_set); + } + + /* Copy prologue/epilogue status. This is required in order to keep + proper placement of EPILOGUE_BEG and the DW_CFA_remember_state. */ + maybe_copy_prologue_epilogue_insn (old_insn, new_insn); + } + + /* We will be adding the new sequence to the function. The splitters may have introduced invalid RTL sharing, so unshare the sequence now. */ unshare_all_rtl_in_chain (seq);