From patchwork Sat Dec 2 10:44:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 172802 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp1691441vqy; Sat, 2 Dec 2023 02:44:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IF2wYfDGCf5Pc5CfOAGhyYmC5ZLpr2LayJIl9jnRCs69veJ784ImTM9VNZ0NOKkaC+EQggD X-Received: by 2002:a05:6214:301:b0:67a:9b65:fe57 with SMTP id i1-20020a056214030100b0067a9b65fe57mr1198460qvu.65.1701513894904; Sat, 02 Dec 2023 02:44:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701513894; cv=pass; d=google.com; s=arc-20160816; b=tmhHEJUU5E88/zgw9IjT3/UwzF167pcc4CdMWaEidrDJj4zMn1CAvBWfL86DHGLWrI VDft5Atjpkoh9UAyLt6aOnNqQ5Uctb5ZeJqojhomnx/5Vvqv0cOnP1P140STB0mW8OdP NG7DfZPNNa9Xzq6dHdmpxxGdUjL7c/mFsyNbBuONOoRITXJAVr84vWrKW0oEKUc8rKsB OsYy6UojhgQ40wshJKR3GB5vvOjl/pea7Y3bdeAmf4MKGA0bPG8xNHZXpzObdUI05Vui zOLE8jAlRFJDe6ChfSqBitc0NHIDambSo9AMu/p/+lnEbYvTMbv8aSWdJLddHVJBb/aY imWw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=krH9Od3asXlON2N9zO5FeW9L8YX7OztLlBAhKyOoNqk=; fh=6mJod6pd+m68yJ4edq4Z+7izYpBQud6Qgy8ZKty5LpU=; b=o3ab3lfcX+1sjv19dmkJ+0sX/WSwpgra/Hc9J6WDJSZvl4O4noTAsGCUT7+mFtK0ut jFxL6Qo82mx0JmFRZwZzhD/irOKeXuUz7pcs65tdiqbxvxsA//TvsRKtN4viJlh/pLQS B45fyYXeSH84toIwTLz9vYzHjhcwwYlC1V5BT6YnOZ/zZeRsEHuutkeAM39zBRIQraIS i1hHAK5AUNg9r+wRA7Fnv8DgUiSYPfZje/9bRyVEIu2JKer/h6gELkdTiUWflCJv2iCn qhbcG3zkQvf7065gnZLx49B1bReMW7looyZxXd4ny0oD8UE5RaFCDHQWwNAIb9m745mF dYkw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SvhlRcsE; arc=pass (i=1); 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=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id k1-20020a0cebc1000000b0067aa5281f3asi1740184qvq.422.2023.12.02.02.44.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Dec 2023 02:44:54 -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=@redhat.com header.s=mimecast20190719 header.b=SvhlRcsE; arc=pass (i=1); 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=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A9F12385DC0D for ; Sat, 2 Dec 2023 10:44:54 +0000 (GMT) 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 31A89385ED72 for ; Sat, 2 Dec 2023 10:44:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 31A89385ED72 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 31A89385ED72 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701513861; cv=none; b=FyPjQG4xedNuu2LYZW1DLxQN9Xf1+AgA57w9nJbDX1OUBexC7F4ZQGfZ6M1aSAwKMRV8MP2ehSy0pZKEPTkRSKPwZOm+V9102Z8rJVAV7f/oeCe+Snbw6EtwAYY6OGPjaRkhJQwlgDmf/FpNK9BHaKe3rq9KBRcT0nkcONhgtRQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701513861; c=relaxed/simple; bh=4FG+C9IqElRVu1G/wqMHXLPAgwBqDj97x7Qzuzp2bmY=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=fTQb8qp+JD2Uqx0rezHL7OvUF62G3Dm0DisXXj6KgzVtItSgZpkqatq30OadRPYXvLXGB6wS4VnUzbbfLju8icwtuEBKApnWcMGgW+yJ70SufbFnEw6Y49TpCxR6mNkrTR9J+dWCeRusS8zcXgtQ2k2yU89oUGQWaFpIAkPLY4s= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701513859; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=krH9Od3asXlON2N9zO5FeW9L8YX7OztLlBAhKyOoNqk=; b=SvhlRcsEQK9FcL+fkz0PVYNWVKcskmoX1qgkWhFenAfxgfl9D/pTkNyaNJCflrbojOXPqO YMqpzAxFKU9X7gy2I+gEF/EkPJF7Btm56TDbpo0q8NNoYVtugAOwIuR+DwXKmXpXL4VZYZ k/YoM8OL/yQV9eyIVrQwKbt+V4LTFJE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-673-U4OMavsYNCeLqw-MoaLA4Q-1; Sat, 02 Dec 2023 05:44:16 -0500 X-MC-Unique: U4OMavsYNCeLqw-MoaLA4Q-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E1B04810FDD; Sat, 2 Dec 2023 10:44:15 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.157]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 511EA492BE0; Sat, 2 Dec 2023 10:44:14 +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 3B2AiAYt3605187 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 2 Dec 2023 11:44:11 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3B2Ai9Jw3605186; Sat, 2 Dec 2023 11:44:09 +0100 Date: Sat, 2 Dec 2023 11:44:08 +0100 From: Jakub Jelinek To: Richard Sandiford , Eric Botcazou , Segher Boessenkool , Jeff Law Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] pro_and_epilogue: Call df_note_add_problem () if SHRINK_WRAPPING_ENABLED [PR112760] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.4 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784166633693296544 X-GMAIL-MSGID: 1784166633693296544 Hi! The following testcase ICEs on x86_64-linux since df_note_add_problem () call has been added to mode switching. The problem is that the pro_and_epilogue pass in prepare_shrink_wrap -> copyprop_hardreg_forward_bb_without_debug_insn uses regcprop.cc infrastructure which relies on accurate REG_DEAD/REG_UNUSED notes. E.g. regcprop.cc /* We need accurate notes. Earlier passes such as if-conversion may leave notes in an inconsistent state. */ df_note_add_problem (); documents that. On the testcase below it is in particular the /* Detect obviously dead sets (via REG_UNUSED notes) and remove them. */ if (set && !RTX_FRAME_RELATED_P (insn) && NONJUMP_INSN_P (insn) && !may_trap_p (set) && find_reg_note (insn, REG_UNUSED, SET_DEST (set)) && !side_effects_p (SET_SRC (set)) && !side_effects_p (SET_DEST (set))) { bool last = insn == BB_END (bb); delete_insn (insn); if (last) break; continue; } case where a stale REG_UNUSED note breaks stuff up (added in vzeroupper pass, redundant insn after it deleted later). The following patch makes sure the notes are not stale if shrink wrapping is enabled. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-12-02 Jakub Jelinek PR rtl-optimization/112760 * function.cc (thread_prologue_and_epilogue_insns): If SHRINK_WRAPPING_ENABLED, call df_note_add_problem before calling df_analyze. * gcc.dg/pr112760.c: New test. Jakub --- gcc/function.cc.jj 2023-11-07 08:32:01.699254744 +0100 +++ gcc/function.cc 2023-12-01 13:42:51.885189341 +0100 @@ -6036,6 +6036,11 @@ make_epilogue_seq (void) void thread_prologue_and_epilogue_insns (void) { + /* prepare_shrink_wrap uses copyprop_hardreg_forward_bb_without_debug_insn + which uses regcprop.cc functions which rely on accurate REG_UNUSED + and REG_DEAD notes. */ + if (SHRINK_WRAPPING_ENABLED) + df_note_add_problem (); df_analyze (); /* Can't deal with multiple successors of the entry block at the --- gcc/testsuite/gcc.dg/pr112760.c.jj 2023-12-01 13:46:57.444746529 +0100 +++ gcc/testsuite/gcc.dg/pr112760.c 2023-12-01 13:46:36.729036971 +0100 @@ -0,0 +1,22 @@ +/* PR rtl-optimization/112760 */ +/* { dg-do run } */ +/* { dg-options "-O2 -fno-dce -fno-guess-branch-probability --param=max-cse-insns=0" } */ +/* { dg-additional-options "-m8bit-idiv -mavx" { target i?86-*-* x86_64-*-* } } */ + +unsigned g; + +__attribute__((__noipa__)) unsigned short +foo (unsigned short a, unsigned short b) +{ + unsigned short x = __builtin_add_overflow_p (a, g, (unsigned short) 0); + g -= g / b; + return x; +} + +int +main () +{ + unsigned short x = foo (40, 6); + if (x != 0) + __builtin_abort (); +}