From patchwork Thu Oct 21 08:12:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 46474 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DFB9E3858434 for ; Thu, 21 Oct 2021 08:13:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DFB9E3858434 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1634804019; bh=CB1k9yBPemJnph9xXO5Vr8awELXhsKd6pXURO942nfs=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=qEvpaHRMbodWkie2LOmZzVTAKRBEwja3EkEw/gExLqtWI+OcgN6LwdCXvLfzuAGAz EMLoSSMeB1EnMCNZ6X0gEI/LO6h5emGFoC/F9ffFKBUabCPlbdjsxvkhp0wMPwjtVR X0LepI/+b9DvfIWTIe3tfSfeQUMSVG6T8n/pzUzE= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTPS id C664E385740F for ; Thu, 21 Oct 2021 08:12:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C664E385740F Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-267-msJAdR25Pb6RNHK5MDkCeg-1; Thu, 21 Oct 2021 04:12:30 -0400 X-MC-Unique: msJAdR25Pb6RNHK5MDkCeg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B225C10A8E00; Thu, 21 Oct 2021 08:12:29 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.191]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 428295D9DE; Thu, 21 Oct 2021 08:12:28 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.16.1/8.15.2) with ESMTPS id 19L8CQut875274 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 21 Oct 2021 10:12:27 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.16.1/8.16.1/Submit) id 19L8CQea875273; Thu, 21 Oct 2021 10:12:26 +0200 To: GCC patches , Jeff Law Subject: [COMMITTED] Avoid threading circular paths. Date: Thu, 21 Oct 2021 10:12:06 +0200 Message-Id: <20211021081205.875196-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Aldy Hernandez via Gcc-patches From: Aldy Hernandez Reply-To: Aldy Hernandez Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The backward threader keeps a hash of visited blocks to avoid crossing the same block twice. Interestingly, we haven't been checking it for the final block out of the path. This may be inherited from the old code, as it was simple enough that it didn't matter. With the upcoming changes enabling the fully resolving threader, it gets tripped often enough to cause wrong code to be generated. Tested on x86-64 Linux. Committed as obvious. gcc/ChangeLog: * tree-ssa-threadbackward.c (back_threader::maybe_register_path): Avoid threading circular paths. --- gcc/tree-ssa-threadbackward.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gcc/tree-ssa-threadbackward.c b/gcc/tree-ssa-threadbackward.c index d94e3b962db..38913b06717 100644 --- a/gcc/tree-ssa-threadbackward.c +++ b/gcc/tree-ssa-threadbackward.c @@ -140,6 +140,10 @@ back_threader::maybe_register_path () if (taken_edge && taken_edge != UNREACHABLE_EDGE) { + // Avoid circular paths. + if (m_visited_bbs.contains (taken_edge->dest)) + return UNREACHABLE_EDGE; + bool irreducible = false; bool profitable = m_profit.profitable_path_p (m_path, m_name, taken_edge, &irreducible);