From patchwork Wed Apr 5 20:10:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1765732 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=KIq5GA51; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PsG3T18Qfz1yYn for ; Thu, 6 Apr 2023 06:11:00 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E36493858404 for ; Wed, 5 Apr 2023 20:10:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E36493858404 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680725453; bh=QUAo4uWwZdYZfK2b2g3wpl/SAyuVZ+bh3gPxG6zRZPA=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=KIq5GA51XG8ZnBWri3PfPArcdsUJReZ0ZLQY/s9U6RdhiEFLWTW7DSQ+1Gz0CY36Z cifNBtjLDXQzy4mHvXkxGewaKfD3yjdBw+NfI9TEPaDS5sLxIjAgy+2k/eZOQJ7UL3 fjoWUY4VVGOZxuqITSFiNYwID5EXNK8PDMLWq6Ho= 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 5C62D3858D20 for ; Wed, 5 Apr 2023 20:10:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5C62D3858D20 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-659-GDMefdjYO8iW4O5bc5A9Kg-1; Wed, 05 Apr 2023 16:10:27 -0400 X-MC-Unique: GDMefdjYO8iW4O5bc5A9Kg-1 Received: by mail-qv1-f71.google.com with SMTP id e1-20020a0cd641000000b005b47df84f6eso16967778qvj.0 for ; Wed, 05 Apr 2023 13:10:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680725427; h=subject:from:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=dHDvJPpoJkI/FsRnAcQ5srOHjV5iIe/aJ8pP8Y02Ics=; b=hjCcepoIrZ/fsUt4mHNcOD52iTPnHoRy8ESft/Q3P2J2QL+zd8I5kNIs/iQMk9b390 7Rq49qt1SqY06fEAus2KCXKttlgzMbhMq9IX0Fgu2LCN4RFItgy0vgBfneh5WIU6CFWo xA8w42m6NP+OXiCkP/S0qafkIzsHFB6gcoDRLqtV1AWrDlsH/w+xODJej7diCNhBLHaX F4Ead1PwWynooxar9qQ5bIVbkvFMNqQTjgO6Kb9LrloQFyFNb//K5B10XRHl5czxPYqa Esrdyz5LsgEpB5t0FG9xcDMBbgXlPmBBTo0QgcEwhzHS7rjSQzqQFpltxURo5/dPLJ3p HchQ== X-Gm-Message-State: AAQBX9fLWaP2Omo5v+rqKZ0zEoncRtzw1BZJPvkkLAYRroVtm995acRm CA7mQhw9c2hdiguyXnuSgQjPod5ijjkGVzZfQ3ePcdS3EiGOC0Eqsq81GU4F/yCqp3g4G9YL3t4 H24qb5Ep7h4jAN3sbngqte+rBNucc4YLCsu2RoKAko/Jq0EpiE03RTTzZOATc0JuTEmjFZ9Gfit zW6A== X-Received: by 2002:a05:622a:507:b0:3e6:6502:16aa with SMTP id l7-20020a05622a050700b003e6650216aamr6625744qtx.36.1680725426837; Wed, 05 Apr 2023 13:10:26 -0700 (PDT) X-Google-Smtp-Source: AKy350a9dt2yUHxjVLlrByvKhlYQQAUCR69z24R1kSkfTNBx9whFLfsJSWVpdBsEC36BGaEirQS9jg== X-Received: by 2002:a05:622a:507:b0:3e6:6502:16aa with SMTP id l7-20020a05622a050700b003e6650216aamr6625697qtx.36.1680725426481; Wed, 05 Apr 2023 13:10:26 -0700 (PDT) Received: from ?IPV6:2607:fea8:51dd:1100::345b? ([2607:fea8:51dd:1100::345b]) by smtp.gmail.com with ESMTPSA id y20-20020ac87094000000b003e4e9aba4b3sm4232209qto.73.2023.04.05.13.10.25 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 05 Apr 2023 13:10:25 -0700 (PDT) Message-ID: Date: Wed, 5 Apr 2023 16:10:25 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 To: gcc-patches Subject: [PATCH] PR tree-optimization/109417 - Check if dependency is valid before using in may_recompute_p. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.4 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_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: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" When a statement is first processed, any SSA_NAMEs that are dependencies are cached for quick future access. if we ;later rewrite the statement (say propagate a constant into it), its possible the ssa-name in this cache is no longer active.   Normally this is not a problem, but the changed to may_recompute_p forgot to take that into account, and was checking a dependency from the cache that was in the SSA_NAME_FREE_LIST. It thus had no SSA_NAME_DEF_STMT when we were expecting one. This patch simply rejects dependencies from consideration if they are in the free list. Bootstrapping on x86_64-pc-linux-gnu  and presuming no regressio0ns, OK for trunk? Andrew commit ecd86e159e8499feb387bc4d99bd37a5fd6a0d68 Author: Andrew MacLeod Date: Wed Apr 5 15:59:38 2023 -0400 Check if dependency is valid before using in may_recompute_p. When the IL is rewritten after a statement has been processed and dependencies cached, its possible that an ssa-name in the dependency cache is no longer in the IL. Check this before trying to recompute. PR tree-optimization/109417 gcc/ * gimple-range-gori.cc (gori_compute::may_recompute_p): Check if dependency is in SSA_NAME_FREE_LIST. gcc/testsuite/ * gcc.dg/pr109417.c: New. diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc index 5f4313b27dd..6e2f9533038 100644 --- a/gcc/gimple-range-gori.cc +++ b/gcc/gimple-range-gori.cc @@ -1314,7 +1314,9 @@ gori_compute::may_recompute_p (tree name, basic_block bb, int depth) tree dep2 = depend2 (name); // If the first dependency is not set, there is no recomputation. - if (!dep1) + // Dependencies reflect original IL, not current state. Check if the + // SSA_NAME is still valid as well. + if (!dep1 || SSA_NAME_IN_FREE_LIST (dep1)) return false; // Don't recalculate PHIs or statements with side_effects. diff --git a/gcc/testsuite/gcc.dg/pr109417.c b/gcc/testsuite/gcc.dg/pr109417.c new file mode 100644 index 00000000000..15711dbbafe --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr109417.c @@ -0,0 +1,24 @@ +/* { dg-do compile } */ +/* { dg-options "-O3" } */ + +int printf(const char *, ...); +int c, d, *e, f[1][2], g; +int main() { + int h = 0, *a = &h, **b[1] = {&a}; + while (e) + while (g) { + L: + for (h = 0; h < 2; h++) { + while (d) + for (*e = 0; *e < 1;) + printf("0"); + while (c) + ; + f[g][h] = 0; + } + } + if (h) + goto L; + return 0; +} +