From patchwork Sat Nov 11 08:27:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 164103 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp114426vqg; Sat, 11 Nov 2023 00:27:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IGdeQflLRNemFinQ8szV6wInqtWeLTqpb7RNFXsPUDqoyl1kveo4eqhh97kMjDwRDTlwBaB X-Received: by 2002:a05:6871:5c8:b0:1ea:746d:16f7 with SMTP id v8-20020a05687105c800b001ea746d16f7mr1938455oan.6.1699691270140; Sat, 11 Nov 2023 00:27:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699691270; cv=pass; d=google.com; s=arc-20160816; b=WTkYLsTNfwEflChL7O5k1hmO1vbHNopXJ95bhbGFwk+p2yw52VFHg/HK7u734i46RZ WRs13+RwsX0kH5hgOocgqL7uzT+n+8zxx+taJF0vvdDQjeyooa+f759fyyIifaLAtoG7 Dt8LA4yiHQNnNn0Pw0g43q7zO6zMjytyr5GGQvSAqLFpF0P4iSsvacWTOz7Mbbmrcx8i u94xhA2ay+HLIbIwpIKR1lBM1sTy6k5ds4olI1zZ++Gr81xYFmak0/kTUk51eUc9euxE rUU46w7tDGqIqq2jfw5vqRuu8TQWfoE5bb+OB2TSi6awo7dSDgadYlr2U93M6Upjk/Sy ji+g== 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=OyzkOEzPxU5GFxO4PQSoYvW/MQbJ+pA9PqOC1+RkulI=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=Fk7ALiyBQ5iDu9V5vxiSQxVo7gLeJRnlG//TWMlHdRkBoD26EZ5Px9ZS2EEfcdcov1 RRU13//7KZGU97zCYRCHhzrnzFi67cwmhmTazo2NgnmX2TGOmsbH3ytJ0oqTezPr6WXv 8GTTFh/fitvLBwOzsv3JV8AHIpYQKDZL6udDh1efbUjwIdqWSnaCtW1S4l18rqquWAXn lbfG+l49tXq4hHn6AuDcZz62dF4xvrOiBmI1C9WDK68bGti3y6nu7FNmOKJ4nYZdVXSV 1/XdJOrUYnWpXPwms2sqvvtbQk91g7PFRuogHyRnO4lCxLPHXMxvuSj521GXOrTz1w/Z yImQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="U/MepoNy"; 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 z16-20020a05622a029000b004109d1af4d4si1007169qtw.647.2023.11.11.00.27.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Nov 2023 00:27:50 -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="U/MepoNy"; 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 E11873858C5E for ; Sat, 11 Nov 2023 08:27:49 +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.133.124]) by sourceware.org (Postfix) with ESMTPS id 823CE3858D1E for ; Sat, 11 Nov 2023 08:27:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 823CE3858D1E 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 823CE3858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699691245; cv=none; b=HUgT0S76W7dixiHz7XJ2gjmEPPz4JI24+RhDraAfdNqsnH0YaYBwoFCm2iMikRFBGseHaWTpJzXCOpgKSwlNSj47U6hx5dykC8G/W0REGH+59rWirWEk3hOtJZyAjzXNg31eD2oKzzuVC2EtHjIUzie+1z8f4Dwuz69cr/etKQs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699691245; c=relaxed/simple; bh=DVnjlVNoeV7L/It8EcedYWLimyc/pQsL2ShSUu2ysY0=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=M/+CWS2/7Y0k8ClndRvZK+3tRMNOW97jDWFmEPNyWL/Ez836t32HXDKlrXjY3aFM/MolNQb7soCzcawz+/PEwF+2GtCdpCsJG6mjVUh3UYz2VsOKUjW4Wgtc8mYvEMMoN85XABeHgkj2mtw7PvRgTX+KbWH7dyp1o4k/aLKirz8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699691244; 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=OyzkOEzPxU5GFxO4PQSoYvW/MQbJ+pA9PqOC1+RkulI=; b=U/MepoNy4T+FAuqq7Ks0W5m2ELuKEI0q8P2HISW5MWHZkCrY2OoD9Gp70ns/lg8IaCJktw Y442Dn4UsV4q2YM937raX0sq7pHKVd+zx10r1faLaXRCaosBaxTiSwoKQteIrfBZd2LxFw SqL+wu7NQc8itTcZeoq8afA+3UK5qQ0= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-166-oKBNwjirM02Uw0_kztw-GQ-1; Sat, 11 Nov 2023 03:27:22 -0500 X-MC-Unique: oKBNwjirM02Uw0_kztw-GQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 4584B1C04B56; Sat, 11 Nov 2023 08:27:22 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.81]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0735F361; Sat, 11 Nov 2023 08:27:21 +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 3AB8RJ3A3773553 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 11 Nov 2023 09:27:19 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3AB8RDu83773552; Sat, 11 Nov 2023 09:27:13 +0100 Date: Sat, 11 Nov 2023 09:27:13 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-ssa-math-opts: Fix up gsi_remove order in match_uaddc_usubc [PR112430] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.7 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_H3, 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: 1782255473144101349 X-GMAIL-MSGID: 1782255473144101349 Hi! The following testcase ICEs, because the temp_stmts were removed in wrong order, from the ones appearing earlier in the IL to the later ones, so insert_debug_temps_for_defs can reintroduce dead SSA_NAMEs back into the IL. The following patch fixes that by removing them in the order they were pushed into the vector, which is from later ones to earlier ones. Additionally, I've noticed I forgot to call release_defs on the removed stmts. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-11-11 Jakub Jelinek PR middle-end/112430 * tree-ssa-math-opts.cc (match_uaddc_usubc): Remove temp_stmts in the order they were pushed rather than in reverse order. Call release_defs after gsi_remove. * gcc.dg/pr112430.c: New test. Jakub --- gcc/tree-ssa-math-opts.cc.jj 2023-11-02 07:49:20.699815089 +0100 +++ gcc/tree-ssa-math-opts.cc 2023-11-10 13:43:13.059912310 +0100 @@ -5047,11 +5047,11 @@ match_uaddc_usubc (gimple_stmt_iterator gsi_insert_before (gsi, g, GSI_SAME_STMT); /* Remove some further statements which can't be kept in the IL because they can use SSA_NAMEs whose setter is going to be removed too. */ - while (temp_stmts.length ()) + for (gimple *g2 : temp_stmts) { - g = temp_stmts.pop (); - gsi2 = gsi_for_stmt (g); + gsi2 = gsi_for_stmt (g2); gsi_remove (&gsi2, true); + release_defs (g2); } } else @@ -5068,10 +5068,12 @@ match_uaddc_usubc (gimple_stmt_iterator rhs1 = gimple_assign_rhs1 (g); gsi2 = gsi_for_stmt (g); gsi_remove (&gsi2, true); + release_defs (g); } gcc_checking_assert (rhs1 == gimple_assign_lhs (im2)); gsi2 = gsi_for_stmt (im2); gsi_remove (&gsi2, true); + release_defs (im2); /* Replace the re2 statement with __real__ of the newly added .UADDC/.USUBC call. */ if (re2) --- gcc/testsuite/gcc.dg/pr112430.c.jj 2023-11-10 13:45:18.707163791 +0100 +++ gcc/testsuite/gcc.dg/pr112430.c 2023-11-10 13:45:04.523361174 +0100 @@ -0,0 +1,30 @@ +/* PR middle-end/112430 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -g" } */ + +int a, b, c, d, e; +unsigned int f; + +static void +foo (unsigned int x) +{ + unsigned int g = x < c; + int h = f < b; + x += h; + g += x < h; + f = x; + x = g; + g = f += a; + h = f < a; + x += h; + c += f < d; + x += c; + g += x < c; + e = g; +} + +void +bar (unsigned int x) +{ + foo (x); +}