From patchwork Thu Sep 7 19:21:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1831125 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=FFzGWk4p; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RhTd92lzVz1yh1 for ; Fri, 8 Sep 2023 05:21:49 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5D493385841E for ; Thu, 7 Sep 2023 19:21:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5D493385841E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694114507; bh=0RAR/G+vMfOGlE0w4s8uxIxXTl+NGXD8VJgN4l6KtRk=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=FFzGWk4p2mqGCxYYg9B8yJn0on95Op0uZhzLZGrrKajAHAIWET39TDE2Cc+aiEbxX utMiPCJffyQLSHmqmIJI86mTBU0aBAOixkLIyRw7HKJRALxqPHDrQG0w28jhGdgd9m NEC/c5jX2NScljN4URqryQ8jzLd7rIgQafXbmDk0= 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 1BE15385841E for ; Thu, 7 Sep 2023 19:21:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1BE15385841E Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-80-FV02L9UXOUmYKEl7ZcBxOg-1; Thu, 07 Sep 2023 15:21:23 -0400 X-MC-Unique: FV02L9UXOUmYKEl7ZcBxOg-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-414e1c2b660so19874071cf.1 for ; Thu, 07 Sep 2023 12:21:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694114482; x=1694719282; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=0+cH+o2nYVzUU230eGz5VBB8n/6LPqu+DDzWilnQ4NU=; b=K41TMD+ojxXLC50SevJvCK8i38HEjqAAQaaSIENm2LLbSSwSmsV+5XgWi1DJBvvlrR gMRVgCVYW7f0fXhLXtBEJwQ6gaIsZFdFd+G6lLPYWHXkSEw0oMy39G4qZDEaqUVZECO4 auz+NbX62Y0uj9ey+Pfv6mnnQKaeQF9B9lIyh0rhuAryG9NqCjatNkcfLrk8J1K18w4X E83Dj5XCu/+fJ8vCOpNvOrOb2IYZaDOHRdauFcBPuOLwftVC4r4XV8HxEUU8CrWMZMT1 +uzuxv3EQKeuP6SrzyCWd8mIfU9kWK9v0LRnz9igA0WOgTw1JCaH4j2c7vTRRnrU5JHF bZwg== X-Gm-Message-State: AOJu0Yxbde751RnsedWO6nWs+JaZLu97CkU/80s7SuicAcXwaSQHU79U fh57T6h8U24sQ2yRs1U4f2EhIByi9pZ26ErwRR/sU3VgGvrlimibykll+YYF7xBqQiEPpqDV4wu ZNae6mDnMHhHbIVKYP0HIyK/FoNjyPG8M3tNzJzvOFULuA5EN1f8s1WM2Hu/j6zXLthW8gHfbnb fviQ== X-Received: by 2002:ac8:5981:0:b0:407:f3e2:ad59 with SMTP id e1-20020ac85981000000b00407f3e2ad59mr5126830qte.14.1694114482123; Thu, 07 Sep 2023 12:21:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGe3CokY7D8A2NzYFIxZzI9t6bZrPXXHMyq923MfjHWwmp0j6vOKT+ADa3DhClprzRpApPHuA== X-Received: by 2002:ac8:5981:0:b0:407:f3e2:ad59 with SMTP id e1-20020ac85981000000b00407f3e2ad59mr5126805qte.14.1694114481788; Thu, 07 Sep 2023 12:21:21 -0700 (PDT) Received: from ?IPV6:2605:8d80:5c0:6877:face:a711:4d29:8fe9? ([2605:8d80:5c0:6877:face:a711:4d29:8fe9]) by smtp.gmail.com with ESMTPSA id fy22-20020a05622a5a1600b00403c82c609asm72411qtb.14.2023.09.07.12.21.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Sep 2023 12:21:21 -0700 (PDT) Message-ID: <6130f27c-ca74-1d41-6edb-bc6b7cb88890@redhat.com> Date: Thu, 7 Sep 2023 15:21:20 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 To: gcc-patches Subject: [COMMITTED] PR tree-optimization/110875 - Some ssa-names get incorrectly marked as always_current. 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_H3, RCVD_IN_MSPIKE_WL, 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.30 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 range_of_stmt invokes prefill_name to evaluate unvisited dependneciesit should not mark visited names as always_current. when raner_cache::get_globaL_range() is invoked with the optional  "current_p" flag, it triggers additional functionality. This call is meant to be from within ranger and it is understood that if the current value is not current,  set_global_range will always be called later with a value.  Thus it sets the always_current flag in the temporal cache to avoid computation cycles. the prefill_stmt_dependencies () mechanism within ranger is intended to emulate the bahaviour od range_of_stmt on an arbitrarily long series of unresolved dependencies without triggering the overhead of huge call chains from the range_of_expr/range_on_entry/range_on_exit routines.  Rather, it creates a stack of unvisited names, and invokes range_of_stmt on them directly in order to get initial cache values for each ssa-name. The issue in this PR was that routine was incorrectly invoking the get_global_cache to determine whether there was a global value.  If there was, it would move on to the next dependency without invoking set_global_range to clear the always_current flag. What it soudl have been doing was simply checking if there as a global value, and if there was not, add the name for processingand THEN invoke get_global_value to do all the special processing. Bootstraps on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From e9be59f7d2dc6b302cf85ad69b0a77dee89ec809 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Thu, 7 Sep 2023 11:15:50 -0400 Subject: [PATCH] Some ssa-names get incorrectly marked as always_current. When range_of_stmt invokes prefill_name to evaluate unvisited dependencies it should not mark already visited names as always_current. PR tree-optimization/110875 gcc/ * gimple-range.cc (gimple_ranger::prefill_name): Only invoke cache-prefilling routine when the ssa-name has no global value. gcc/testsuite/ * gcc.dg/pr110875.c: New. --- gcc/gimple-range.cc | 10 +++++++--- gcc/testsuite/gcc.dg/pr110875.c | 34 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr110875.c diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc index 01173c58f02..13c3308d537 100644 --- a/gcc/gimple-range.cc +++ b/gcc/gimple-range.cc @@ -351,10 +351,14 @@ gimple_ranger::prefill_name (vrange &r, tree name) if (!gimple_range_op_handler::supported_p (stmt) && !is_a (stmt)) return; - bool current; // If this op has not been processed yet, then push it on the stack - if (!m_cache.get_global_range (r, name, current)) - m_stmt_list.safe_push (name); + if (!m_cache.get_global_range (r, name)) + { + bool current; + // Set the global cache value and mark as alway_current. + m_cache.get_global_range (r, name, current); + m_stmt_list.safe_push (name); + } } // This routine will seed the global cache with most of the dependencies of diff --git a/gcc/testsuite/gcc.dg/pr110875.c b/gcc/testsuite/gcc.dg/pr110875.c new file mode 100644 index 00000000000..4d6ecbca0c8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr110875.c @@ -0,0 +1,34 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-vrp2" } */ + +void foo(void); +static int a, b; +static int *c = &a, *d; +static unsigned e; +static short f; +static unsigned g(unsigned char h, char i) { return h + i; } +int main() { + d = &a; + int *j = d; + e = -27; + for (; e > 18; e = g(e, 6)) { + a = 0; + for (; a != -3; a--) { + if (0 != a ^ *j) + for (; b; b++) f = -f; + else if (*c) { + foo(); + break; + } + if (!(((e) >= 235) && ((e) <= 4294967269))) { + __builtin_unreachable(); + } + b = 0; + } + } +} + + +/* { dg-final { scan-tree-dump-not "foo" "vrp2" } } */ + + -- 2.41.0