From patchwork Thu Jan 4 09:34:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 184962 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5505802dyb; Thu, 4 Jan 2024 01:35:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IF5qHLWJWEIqLfo7TLNswNfXIb9WIAETyuyZwcVB/rD/w2dnRglB6cBoumqheb/jEm3I9i2 X-Received: by 2002:a05:620a:1237:b0:781:5505:d5a with SMTP id v23-20020a05620a123700b0078155050d5amr297146qkj.107.1704360950241; Thu, 04 Jan 2024 01:35:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704360950; cv=pass; d=google.com; s=arc-20160816; b=Uvz5UI8oxyAUNwuZGfEQ6ZjVcQ5hc+ZjpayWlVPhhWhbNvT3NeBTdGaeHLXpboHWdN +2HMwrRtcgyRzrU13oYpuxplNQhNYYc3H1y1+hBj3u0ANCz11cFHhn0H/+0XtuS+ZsQx jdDvO3bzir/sW4/7qh3VAHn1kv+gBMn8nmQa5g9i9t74gtaxwnsqUSUBGMjDQOhISSEP mCMkssvAO5PYMPaK//YAoPY1oJoQu00rdD+OxC69aVuTqcYyEdviCr5t0v930Ypx7b7I c/epNWMS8LFXpNpskA6ioEsAIZE0VdVPIis4xNEnAUYf0tHueaNnQD8AzPdOnMi7cg+G hFjA== 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=Y8VFFO8rnyLgNRVQYO/FoIhXPY42c3ty5uyqjXzJnVc=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=KD1oPeVuUsz+P/Ims8DH2uEQHpFRDpPS/QXNPi2+KufIt5b+LskiUWJM2zrbmAp7jv kmAdY2t486x4caGGWXP8Z8te8anAqxTyffajSpZDJPMPJ6+z/6nZRs8mZYjhJLWBbwYj hle/Gj7kD6L+G7w9LeiAuzOpuGZjAib+ft9RloSC+8GbtatxD+JLVx5oRNewx6gEMYVX nbjK4aeqtp2EuLFt9M7IeBv0BMrEaFfkjuDDdErpXHFufsGrDmntBCE522sE8+2kpynw GaCxBCkmpkJTkZxqRSaB6oSKJ63LCUNe4MpMI8My5Qk+qIlOfSVB40JvQttXb7rryJD7 z60g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eDXWsTee; arc=pass (i=1); 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=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ou4-20020a05620a620400b007815517a8a9si19450278qkn.336.2024.01.04.01.35.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 01:35:50 -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=@redhat.com header.s=mimecast20190719 header.b=eDXWsTee; arc=pass (i=1); 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=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CC2A6385E009 for ; Thu, 4 Jan 2024 09:35: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 89564385DC16 for ; Thu, 4 Jan 2024 09:34:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 89564385DC16 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 89564385DC16 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=1704360901; cv=none; b=khOFiqCSkNWyuuuhsTMUNIj/N7xlnGnm5yoWceLelwoQ2+7G+WTaHkyjqI6nUalVHXTUURbZjAzfcPC1x/E1VHKOeqE6hLfolHTxlIkUJnjGR91n2c6oC89YRgydcDiV9KI8VH3Ovzx4lBH9m6a6lO2rx48ugZ1SStGxHNvUZf4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704360901; c=relaxed/simple; bh=E2IGKUVdV/ZEduQbI51P52aNW3vMf1nsrCUv1WEAIew=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=Nu1hF5VQ4DMO2NGhTbdin+Vqzu43Z0in68rElvheDXe1mSduLFh1SSfpNPYY9b5Fi9mRfL10aTX9Q/kwM51UXu5qFQuXc85ULv3PeTsO23q+5efgj9rzU1vrQG+Zb5WBaKJDBPsDX6oi0Ld3a39oTbSDJCWB88L8G5Eq71zlVxk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704360899; 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=Y8VFFO8rnyLgNRVQYO/FoIhXPY42c3ty5uyqjXzJnVc=; b=eDXWsTeelTi4BK9NmIOmOWr4MGT9iloHC9HUVl6h1hLo3dhSUIspWwanss5vaY2Q8MSc1k xVsxxnYVoKoJPutoBEK+lMhLEaiezmlv9KDEyO5OM8J4W5HHYVaz32B6hloj0saPpyuOln WwWS5Fsy/40ZpZgqLOIXcopipfCcDLo= 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-490-H6WBubsOMzSJ98APeKLBwg-1; Thu, 04 Jan 2024 04:34:56 -0500 X-MC-Unique: H6WBubsOMzSJ98APeKLBwg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 C191384A292; Thu, 4 Jan 2024 09:34:55 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 854FE51D5; Thu, 4 Jan 2024 09:34:55 +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 4049YrmM3945220 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 4 Jan 2024 10:34:53 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 4049Yq313945219; Thu, 4 Jan 2024 10:34:52 +0100 Date: Thu, 4 Jan 2024 10:34:52 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] scev: Avoid ICE on results used in abnormal PHI args [PR113201] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-4.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: 1787151987384085642 X-GMAIL-MSGID: 1787151987384085642 Hi! The following testcase ICEs when rslt is SSA_NAME_OCCURS_IN_ABNORMAL_PHI and we call replace_uses_by with a INTEGER_CST def, where it ICEs on: if (e->flags & EDGE_ABNORMAL && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (val)) because val is not an SSA_NAME. One way would be to add && TREE_CODE (val) == SSA_NAME check in between the above 2 lines in replace_uses_by. And/or the following patch just punts propagating constants to SSA_NAME_OCCURS_IN_ABNORMAL_PHI rslt uses. Or we could punt somewhere earlier in final value replacement (but dunno where). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? Or do you want the replace_uses_by change (or both that and the following, something else)? 2024-01-04 Jakub Jelinek PR tree-optimization/113201 * tree-scalar-evolution.cc (final_value_replacement_loop): Don't call replace_uses_by on SSA_NAME_OCCURS_IN_ABNORMAL_PHI rslt. * gcc.c-torture/compile/pr113201.c: New test. Jakub --- gcc/tree-scalar-evolution.cc.jj 2024-01-03 11:51:38.929628514 +0100 +++ gcc/tree-scalar-evolution.cc 2024-01-03 18:31:17.550973344 +0100 @@ -3881,7 +3881,7 @@ final_value_replacement_loop (class loop /* Propagate constants immediately, but leave an unused initialization around to avoid invalidating the SCEV cache. */ - if (CONSTANT_CLASS_P (def)) + if (CONSTANT_CLASS_P (def) && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rslt)) replace_uses_by (rslt, def); /* Create the replacement statements. */ --- gcc/testsuite/gcc.c-torture/compile/pr113201.c.jj 2024-01-03 18:44:18.859121266 +0100 +++ gcc/testsuite/gcc.c-torture/compile/pr113201.c 2024-01-03 18:37:28.099814475 +0100 @@ -0,0 +1,15 @@ +/* PR tree-optimization/113201 */ + +void foo (void) __attribute__((returns_twice)); +void bar (void); + +int +baz (void) +{ + int x = 42; + foo (); + while (--x) + ; + bar (); + return x; +}