From patchwork Thu Dec 8 10:11:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 31255 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp109423wrr; Thu, 8 Dec 2022 02:12:26 -0800 (PST) X-Google-Smtp-Source: AA0mqf6nl9bWhVjPTB4ZgMCZ1EtlCjY/nfFO05k/MwkQfAbgSsKlR44AtaboKAJNlZ5rTyDmNNnG X-Received: by 2002:a05:6402:64b:b0:46c:11ef:7b72 with SMTP id u11-20020a056402064b00b0046c11ef7b72mr23231044edx.235.1670494346507; Thu, 08 Dec 2022 02:12:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670494346; cv=none; d=google.com; s=arc-20160816; b=wl5A3dNFU2wJZibyrgf8nv19pgPgYRUjNi2PAawtAySUM/nxkV6uI6GARM88mHRBbS COfxfhTeUv5op62Ll/Z9fHaP3Z/VAlZhoZRburRGBC+iou8GpsTmP3+FRTjeDoOi0+6g UfVlUDKITp/B0ND9lYTO/mdTgu9WWz+62gJmdAYYeTwgX+cTyG70rBx2kLPWz8e6YJb4 gKw3S3X/GQBuRvFomZM7Hm0FWJIOedFoqR5ml/EByAQ5ip7ZNFVhLeoVbh97ii/qXLAg HsvBjuOce090EEodOo4fs3XTyYg3/h3jzXscWy5Lnf1EF8xrsAJPvBJ2H4mpQ1JhpaZr WrlQ== 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=tRWErJacRzex3LDflSjItT67YO5rnSbQ6ciXb9lJx7Q=; b=P+YmRjTHQRdQ0PaiF8g3epwBfJ/uJEzScq8ldawCXOUnOCtw4xbVJVzpeHc1+j3bQL uJgugWgvmCbUVxs1a0Xe4URKVrxwHVX4saCC5SqeqG7RG7ylzFtb0aRGsFT/pXdqp6rj /Q55Iq9VpzsNs3wlD2Moot0HF0ndnP+yRDyjfKqUzMXWQQUrXg4GrtEm0gCY3ublL0wL xQIMQkzTukznDIRVg3EXA/RGAacC6Y1dbm3kOHaeRD+9a9GyG3FdSI48IPNCdpA8N2Zk 5J090LVZmnp8/O8+eH44Q+X2Ho+Sw3CLRcCjW353BTltbMiSxXOai0qGsoTfBuWE2XZc DPlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=KGMo95lh; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id o8-20020a170906974800b007c0b6decb95si20248398ejy.739.2022.12.08.02.12.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Dec 2022 02:12:26 -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=KGMo95lh; 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 608BE38362E4 for ; Thu, 8 Dec 2022 10:12:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 608BE38362E4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670494335; bh=tRWErJacRzex3LDflSjItT67YO5rnSbQ6ciXb9lJx7Q=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=KGMo95lhUiApMAu8OevW+QHjh5uiGnJlFu9Pps8NgX7GL/sCdLryFv8AnLY8OQM2M HB9cNeIOgoFONfBwQUlrBT4IMVWLKcEKRBROCBD/DQGwRv95pe3Ab4twk8ZBvrfraN l/42ONz7ERfhJlHKcczFzv0PC2DYQYGCV+MVBAMU= 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 CC555383CD35 for ; Thu, 8 Dec 2022 10:11:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CC555383CD35 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-671-Mj9cFXMpMQ-OrDxJ6a_04g-1; Thu, 08 Dec 2022 05:11:26 -0500 X-MC-Unique: Mj9cFXMpMQ-OrDxJ6a_04g-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 4617C855438; Thu, 8 Dec 2022 10:11:26 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.114]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 043C2C15BA5; Thu, 8 Dec 2022 10:11:25 +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 2B8ABLRT1994262 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 8 Dec 2022 11:11:21 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2B8ABKJv1994261; Thu, 8 Dec 2022 11:11:20 +0100 Date: Thu, 8 Dec 2022 11:11:19 +0100 To: Richard Biener , Jeff Law Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] cfgbuild: Fix DEBUG_INSN handling in find_bb_boundaries [PR106719] 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.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?1751640279897786998?= X-GMAIL-MSGID: =?utf-8?q?1751640279897786998?= Hi! The following testcase FAILs on aarch64-linux. We have some atomic instruction followed by 2 DEBUG_INSNs (if -g only of course) followed by NOTE_INSN_EPILOGUE_BEG followed by some USE insn. Now, split3 pass replaces the atomic instruction with a code sequence which ends with a conditional jump and the split3 pass calls find_many_sub_basic_blocks. For -g0, find_bb_boundaries sees the flow_transfer_insn (the new conditional jump), then NOTE_INSN_EPILOGUE_BEG which can live in between basic blocks and then the USE insn, so splits block after the NOTE_INSN_EPILOGUE_BEG and puts the NOTE in between the blocks. For -g, if sees a DEBUG_INSN after the flow_transfer_insn, so sets debug_insn to it, then walks over another DEBUG_INSN, NOTE_INSN_EPILOGUE_BEG until it finally sees the USE insn, and triggers the: rtx_insn *prev = PREV_INSN (insn); /* If the first non-debug inside_basic_block_p insn after a control flow transfer is not a label, split the block before the debug insn instead of before the non-debug insn, so that the debug insns are not lost. */ if (debug_insn && code != CODE_LABEL && code != BARRIER) prev = PREV_INSN (debug_insn); code I've added for PR81325. If there are only DEBUG_INSNs, that is the right thing to do, but if in between debug_insn and insn there are notes which can stay in between basic blocks or simnilarly JUMP_TABLE_DATA or their associated CODE_LABELs, it causes -fcompare-debug differences. The following patch fixes it by clearing debug_insn if JUMP_TABLE_DATA or associated CODE_LABEL is seen (I'm afraid there is no good answer what to do with DEBUG_INSNs before those; the code then removes them: /* Clean up the bb field for the insns between the blocks. */ for (x = NEXT_INSN (flow_transfer_insn); x != BB_HEAD (fallthru->dest); x = next) { next = NEXT_INSN (x); /* Debug insns should not be in between basic blocks, drop them on the floor. */ if (DEBUG_INSN_P (x)) delete_insn (x); else if (!BARRIER_P (x)) set_block_for_insn (x, NULL); } but if there are NOTEs, the patch just reorders the NOTEs and DEBUG_INSNs, such that the NOTEs come first (so that they stay in between basic blocks like with -g0) and DEBUG_INSNs after those (so that bb is split before them, so they will be in the basic block after NOTE_INSN_BASIC_BLOCK). Bootstrapped/regtested on x86_64-linux and i686-linux plus tested on the testcase in a cross to aarch64-linux, ok for trunk? 2022-12-08 Jakub Jelinek PR debug/106719 * cfgbuild.cc (find_bb_boundaries): If there are NOTEs in between debug_insn (seen after flow_transfer_insn) and insn, move NOTEs before all the DEBUG_INSNs and split after NOTEs. If there are other insns like jump table data, clear debug_insn. * gcc.dg/pr106719.c: New test. Jakub --- gcc/cfgbuild.cc.jj 2022-01-18 11:58:58.944991171 +0100 +++ gcc/cfgbuild.cc 2022-12-07 21:36:27.493363173 +0100 @@ -445,6 +445,7 @@ find_bb_boundaries (basic_block bb) rtx_insn *debug_insn = NULL; edge fallthru = NULL; bool skip_purge; + bool seen_note_after_debug = false; if (insn == end) return; @@ -492,7 +493,10 @@ find_bb_boundaries (basic_block bb) if (code == DEBUG_INSN) { if (flow_transfer_insn && !debug_insn) - debug_insn = insn; + { + debug_insn = insn; + seen_note_after_debug = false; + } } /* In case we've previously seen an insn that effects a control flow transfer, split the block. */ @@ -506,7 +510,40 @@ find_bb_boundaries (basic_block bb) insn instead of before the non-debug insn, so that the debug insns are not lost. */ if (debug_insn && code != CODE_LABEL && code != BARRIER) - prev = PREV_INSN (debug_insn); + { + prev = PREV_INSN (debug_insn); + if (seen_note_after_debug) + { + /* Though, if there are NOTEs intermixed with DEBUG_INSNs, + move the NOTEs before the DEBUG_INSNs and split after + the last NOTE. */ + rtx_insn *first = NULL, *last = NULL; + for (x = debug_insn; x != insn; x = NEXT_INSN (x)) + { + if (NOTE_P (x)) + { + if (first == NULL) + first = x; + last = x; + } + else + { + gcc_assert (DEBUG_INSN_P (x)); + if (first) + { + reorder_insns_nobb (first, last, prev); + prev = last; + first = last = NULL; + } + } + } + if (first) + { + reorder_insns_nobb (first, last, prev); + prev = last; + } + } + } fallthru = split_block (bb, prev); if (flow_transfer_insn) { @@ -547,6 +584,14 @@ find_bb_boundaries (basic_block bb) flow_transfer_insn = prev_nonnote_nondebug_insn_bb (insn); debug_insn = NULL; } + else if (debug_insn) + { + if (code == NOTE) + seen_note_after_debug = true; + else + /* Jump tables. */ + debug_insn = NULL; + } if (control_flow_insn_p (insn)) flow_transfer_insn = insn; --- gcc/testsuite/gcc.dg/pr106719.c.jj 2022-12-07 21:35:56.523810192 +0100 +++ gcc/testsuite/gcc.dg/pr106719.c 2022-12-07 21:35:40.964034788 +0100 @@ -0,0 +1,13 @@ +/* PR debug/106719 */ +/* { dg-do compile { target sync_char_short } } */ +/* { dg-options "-O2 -fcompare-debug" } */ + +extern short int esi, easi[2]; + +void +foo (void) +{ + short int *psi = &easi[1]; + __atomic_nand_fetch (psi, esi, 0); + psi = &easi[1]; +}