From patchwork Thu Dec 15 07:53:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 33542 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp205968wrn; Wed, 14 Dec 2022 23:54:06 -0800 (PST) X-Google-Smtp-Source: AA0mqf6TlKCeRAAJcycgDwgIuTfSGHDL5vGoOvowSlQ8DTWThHESvfabnM5fH8mTVw1OcOuFG2ih X-Received: by 2002:a17:906:cc55:b0:7c1:6981:d062 with SMTP id mm21-20020a170906cc5500b007c16981d062mr15281963ejb.72.1671090846052; Wed, 14 Dec 2022 23:54:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671090846; cv=none; d=google.com; s=arc-20160816; b=v6BW5Q0abjk94kn3Ro+BjFyktvNuvlPi46zw6q2jLJCBmRmP/DTUuEvk2WmIheDJAy M3gYPIAFBx073N+e1cC220gwVUy1pIm2ESxVydOiMFgEyoQNAQpeltBkMzR2KyK85KA8 zIpulOLdS3KsdQSieg6sw/VwdwQOng8Zw2XaufBQCbX4mxpwG1gmI5sXZjpEPs4u3LFw 8aRfOT1669IQSsYOb4VNdIfZ/P/VcL34abXcsvW2kRfgLAfYQDNkpn5f+gQiaMq0F76D ed97/wQElB+anIgGnLZxPpXIGZKxepgwfnj/WOYKqTzoIPblZwlCoww65SBO9Vi2epGW 0EWg== 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=HAzhU6V+aGt0XCJAw4jTgBopGOFupiCsFT3Y6AAE6Cc=; b=zNvEabpUzqeg+eoDoCdfiqgUPMeHUehpUQkDgqTKWBs30DteuMAdFTIY+Z4OrfG0F+ AQG9V4bzd1PZJQGRPpotMxfLyYvOM9wX41voorv0XoEGv33yIYwUE40AawAu3iKik8DV rVGLC5iuzLjTLcWcCFXl/gOl1XzUd4pAjmI84dqgcogO/gpbgHL3Fc6Q6CCs/83dyRiO kblkaHQKS8TboEz6YXB5N9OZO7YKwDhYoilKcIaJfuVDpyaxq9fWzqrhsPGW/phIWnkT 2OznS3T2GDhrXb0JNhq64TMOCC0WN22Xy+ZCc4dCttbUocWmoXPgvq/pwaCw2RaWDRVZ lMXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ncTnGidy; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id z15-20020a17090655cf00b007c10bb5b4b3si4660864ejp.681.2022.12.14.23.54.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Dec 2022 23:54:06 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ncTnGidy; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 9A56A384231F for ; Thu, 15 Dec 2022 07:54:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9A56A384231F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671090841; bh=HAzhU6V+aGt0XCJAw4jTgBopGOFupiCsFT3Y6AAE6Cc=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=ncTnGidyFXAO3+1ajYnTG+B+HXJRX3cO7k0HafCTqtZ1jKNDYmQ4XBmzP5xyf7VPA 2STkn7nCfer8S1ivi5NWPEITDq6rr8ohaCGzFTborHu1naXC6AwAyfc9bYpJTsJzhF ++gjrmL08CKGyXPNQB6LfjkUg8jGiYAtdQXm8CAk= 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 117273864A21 for ; Thu, 15 Dec 2022 07:53:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 117273864A21 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-434-3rEGdWlwP4q2ctmbvb4OGA-1; Thu, 15 Dec 2022 02:53:11 -0500 X-MC-Unique: 3rEGdWlwP4q2ctmbvb4OGA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BADE81818E47; Thu, 15 Dec 2022 07:53:10 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.114]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 76C402026D68; Thu, 15 Dec 2022 07:53:10 +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 2BF7r5E33304677 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 15 Dec 2022 08:53:06 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2BF7r4JJ3304676; Thu, 15 Dec 2022 08:53:04 +0100 Date: Thu, 15 Dec 2022 08:53:04 +0100 To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] into-ssa: Fix emitting debug stmts after asm goto [PR108095] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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?1752265754901342484?= X-GMAIL-MSGID: =?utf-8?q?1752265754901342484?= Hi! The following testcase ICEs, because ccp1 replaced s.0_1 = &s; __asm__ goto("" : "=r" MEM[(T *)s.0_1] : : : "lab" lab); with __asm__ goto("" : "=r" s : : : "lab" lab); and because s is no longer addressable, we are rewriting it into ssa and want __asm__ goto("" : "=r" s_7 : : : "lab" lab); plus debug stmt # DEBUG s => s_7 The code assumes that there is at most one non-EH edge in that case, but with the addition of outputs to asm goto that is no longer the case, we can have many outgoing edges. The patch keeps the checking assertion that there is at most one such edge for everything but asm goto, but moves the addition of the debug stmt into the loop, so that it can be added on all edges where it is possible, not just one of them. Furthermore, looking at gsi_insert_on_edge_immediate -> gimple_find_edge_insert_loc, the conditions to insert stmt there to the destination block are if (single_pred_p (dest) && gimple_seq_empty_p (phi_nodes (dest)) && dest != EXIT_BLOCK_PTR_FOR_FN (cfun)) (plus there is code to insert it in the previous block but that is never true when the pred is known to be stmt_ends_bb_p), while mayube_register_def was just checking if (ef && single_pred_p (ef->dest) && ef->dest != EXIT_BLOCK_PTR_FOR_FN (cfun)) so if for whatever reason ef->dest had any PHIs, we'd split the edge for -g and not for -g0, something we must avoid for -fcompare-debug stability. So, I've added the no phi_nodes check too. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2022-12-15 Jakub Jelinek PR tree-optimization/108095 * tree-into-ssa.cc (maybe_register_def): Insert debug stmt on all non-EH edges from asm goto if they have a single predecessor rather than asserting there is at most one such edge. Test whether there are no PHI nodes next to the single predecessor test. * gcc.dg/pr108095.c: New test. Jakub --- gcc/tree-into-ssa.cc.jj 2022-12-05 23:20:24.000000000 +0100 +++ gcc/tree-into-ssa.cc 2022-12-14 14:20:50.301283097 +0100 @@ -1934,9 +1934,8 @@ maybe_register_def (def_operand_p def_p, tree tracked_var = target_for_debug_bind (sym); if (tracked_var) { - gimple *note = gimple_build_debug_bind (tracked_var, def, stmt); - /* If stmt ends the bb, insert the debug stmt on the single - non-EH edge from the stmt. */ + /* If stmt ends the bb, insert the debug stmt on the non-EH + edge(s) from the stmt. */ if (gsi_one_before_end_p (gsi) && stmt_ends_bb_p (stmt)) { basic_block bb = gsi_bb (gsi); @@ -1945,33 +1944,46 @@ maybe_register_def (def_operand_p def_p, FOR_EACH_EDGE (e, ei, bb->succs) if (!(e->flags & EDGE_EH)) { - gcc_checking_assert (!ef); + /* asm goto can have multiple non-EH edges from the + stmt. Insert on all of them where it is + possible. */ + gcc_checking_assert (!ef || (gimple_code (stmt) + == GIMPLE_ASM)); ef = e; - } - /* If there are other predecessors to ef->dest, then - there must be PHI nodes for the modified - variable, and therefore there will be debug bind - stmts after the PHI nodes. The debug bind notes - we'd insert would force the creation of a new - block (diverging codegen) and be redundant with - the post-PHI bind stmts, so don't add them. + /* If there are other predecessors to ef->dest, then + there must be PHI nodes for the modified + variable, and therefore there will be debug bind + stmts after the PHI nodes. The debug bind notes + we'd insert would force the creation of a new + block (diverging codegen) and be redundant with + the post-PHI bind stmts, so don't add them. - As for the exit edge, there wouldn't be redundant - bind stmts, but there wouldn't be a PC to bind - them to either, so avoid diverging the CFG. */ - if (ef && single_pred_p (ef->dest) - && ef->dest != EXIT_BLOCK_PTR_FOR_FN (cfun)) - { - /* If there were PHI nodes in the node, we'd - have to make sure the value we're binding - doesn't need rewriting. But there shouldn't - be PHI nodes in a single-predecessor block, - so we just add the note. */ - gsi_insert_on_edge_immediate (ef, note); - } + As for the exit edge, there wouldn't be redundant + bind stmts, but there wouldn't be a PC to bind + them to either, so avoid diverging the CFG. */ + if (e + && single_pred_p (e->dest) + && gimple_seq_empty_p (phi_nodes (e->dest)) + && e->dest != EXIT_BLOCK_PTR_FOR_FN (cfun)) + { + /* If there were PHI nodes in the node, we'd + have to make sure the value we're binding + doesn't need rewriting. But there shouldn't + be PHI nodes in a single-predecessor block, + so we just add the note. */ + gimple *note + = gimple_build_debug_bind (tracked_var, def, + stmt); + gsi_insert_on_edge_immediate (ef, note); + } + } } else - gsi_insert_after (&gsi, note, GSI_SAME_STMT); + { + gimple *note + = gimple_build_debug_bind (tracked_var, def, stmt); + gsi_insert_after (&gsi, note, GSI_SAME_STMT); + } } } --- gcc/testsuite/gcc.dg/pr108095.c.jj 2022-12-14 14:31:57.206580191 +0100 +++ gcc/testsuite/gcc.dg/pr108095.c 2022-12-14 14:31:25.234045359 +0100 @@ -0,0 +1,15 @@ +/* PR tree-optimization/108095 */ +/* { dg-do compile } */ +/* { dg-options "-Os -g" } */ + +int v; +typedef unsigned T; + +void +foo (void) +{ + unsigned s; + asm goto ("" : "=r" (*(T *) &s) : : : lab); + v = 0; +lab: +}