From patchwork Tue May 28 18:56:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1940679 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=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=R31jyGVi; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4VphZh6sQTz20Pq for ; Wed, 29 May 2024 04:57:00 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 480A0384B434 for ; Tue, 28 May 2024 18:56:59 +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.129.124]) by sourceware.org (Postfix) with ESMTPS id 97F203865C27 for ; Tue, 28 May 2024 18:56:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 97F203865C27 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 97F203865C27 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716922598; cv=none; b=BuIiFxvnBhC4BiUxors+302FPJ4hDQ4nfg5HRNC3Xbxg6x1PgOOLv7AbWxRdwJ+9rHkcVLihTqTd4URnCYfJRosYkqAtk9mQJ70+qyDoBtye8gw6FU0SJrITwIHkjSwaNkVNCkmqq0gQMI71qQD06Anleo/1SQEMntjdo+hXnuM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716922598; c=relaxed/simple; bh=T94kUWTf8ScnsMXLLl3dDqJNWnS49wzzivqH050foVk=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=ctbUl0LkNtSELGQYvft7CzQLswlEdiNaTEpcpBkqpZLL8Fx5k3XKzjLarwn0U3NQFWhqQYlHohXZ56FDV+bf7g5Dq0bHnVi2yXCGCL83s0fGz6hQe7Z0tnfJ4JC8/sLL1E5/5vKnb7Ovgfl6Dy59T07nzYAV1Zrjide/bDXNBhs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716922596; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=N+rO5BvGU/WUl1qiOWBoiPwIcTeS8NSbXqHgoBHAurw=; b=R31jyGVijyHlsx0qt1pL6ZTUxZ0dHlCaBTQU+xfhY9dFgojw9wd8YIs/J6S3sn+Mz2RCo9 gQtoZiw2K5gqr1v5NCcWBqpzPJYN4czFzM6Ah3bfZSk+M0jjwdy8HPhbqYgJhRImM1SeW/ /vJOr7mMqsbmRtffjH0Vcg6AtLFFCU0= Received: from mail-ot1-f72.google.com (mail-ot1-f72.google.com [209.85.210.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-463-3WZAbRKUP3S3MOw75vm6rA-1; Tue, 28 May 2024 14:56:34 -0400 X-MC-Unique: 3WZAbRKUP3S3MOw75vm6rA-1 Received: by mail-ot1-f72.google.com with SMTP id 46e09a7af769-6f8f3e1178eso1301432a34.3 for ; Tue, 28 May 2024 11:56:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716922593; x=1717527393; h=cc: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=lnLoVF3VzKVeb4fIO9IA3WH2/5qQ6dMK2wHkmZ7KmwU=; b=tEyHzu+SlEjV2IQiUXmLABVuZkbOLsbezvMDtP6FXsCGVNdMJf+G6QDU8NRCVE0N7O G+ncWtBP0yOhDLyRPYbP5X/45Nw9GDpZB7S0W414MEW9le5jHuRz+lDdB277fobG/9mH Nrv3z9ItFEpYByZ1uT368KvvUj/R4MMOMTkVIja93gC1wSubbjkQsEQPise+cVTOfOqX DHgQRS3alUBawLZ7tlEwND+Pv3BR4eh423cnxymgiUwuHn+oR3BvbKCI2iz940icFzvF qRrgkAyxUowfwucbN60XSmNW+OC7/BqbK1MIU2E0Rc/PlX7bf94/5qVY6nFbU060e5KX BVFQ== X-Gm-Message-State: AOJu0YwBfTIQcZX3XrUA4SWsuKsSWTLQIbAXiakhwsRGmJWmgD5OKzH0 ktQ+NN0XJQFEI7br5RDpVO2UUjkp0ZV3e1FcBc2ttb96PXj3onTrbzW+QpgeLgnanyNJOALH89m P13InHtAMWJ9Nn+pnS6K1wzol9hhFrmJ0b8SMmU0kOf4tHK0ScZrCze5HxZwbgu79LxqYMPMPZJ RHSnFNWW+tDI7bWEDnFt2TMDCj8R790MuRSY9Igac= X-Received: by 2002:a05:6870:818e:b0:24f:d448:c97a with SMTP id 586e51a60fabf-24fd448cae1mr9217478fac.42.1716922592925; Tue, 28 May 2024 11:56:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHfnHXzIIhBV158Xs8JuIaRhwiaUEMjaRKsGCjCo28KalTygvVOSIsbXKsspD8/v9gI2f9FPA== X-Received: by 2002:a05:6870:818e:b0:24f:d448:c97a with SMTP id 586e51a60fabf-24fd448cae1mr9217459fac.42.1716922592476; Tue, 28 May 2024 11:56:32 -0700 (PDT) Received: from ?IPV6:2607:fea8:51db:5900::9ff8? ([2607:fea8:51db:5900::9ff8]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-43fb18aecbdsm45162611cf.61.2024.05.28.11.56.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 28 May 2024 11:56:32 -0700 (PDT) Message-ID: <6614eff0-1c27-478f-9cab-baa726d1b91c@redhat.com> Date: Tue, 28 May 2024 14:56:31 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: gcc-patches From: Andrew MacLeod Subject: [COMMITTED] tree-optimization/115221 - Do not invoke SCEV if it will use a different range query. Cc: "hernandez, aldy" X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-11.2 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_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_WEB, 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: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org The original patch causing the PR made  ranger's cache re-entrant to enable SCEV to use the current range_query when called from within ranger.. SCEV uses the currently active range query (via get_range_query()) for picking up values.  fold_using_range is the general purpose stmt folder many  components use, and it takes a range_query to use for folding.   When propagating values in the cache, we need to ensure no new queries are invoked, and when the cache is propagating and calculating outgoing edges, it switches to a read only range_query which uses what it knows about global values to come up with best result using current state. SCEV is unaware of what the caller is using for a range_query, so when attempting to fold a PHI node, it is re-invoking the current query during propagation which is undesired behavior.   This patch tells fold_using_range to not use SCEV if the range_query being used is not the same as the one SCEV is going to use. Bootstrapped on x86_64-pc-linux-gnu with no regressions. Pushed. Andrew From b814e390e7c87c14ce8d9cdea6c6cd127a4e6261 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Mon, 27 May 2024 11:00:57 -0400 Subject: [PATCH] Do not invoke SCEV if it will use a different range query. SCEV always uses the current range_query object. Ranger's cache uses a global value_query when propagating cache values to avoid re-invoking ranger during simple vavhe propagations. when folding a PHI value, SCEV can be invoked, and since it alwys uses the current range_query object, when ranger is active this causes the undesired re-invoking of ranger during cache propagation. This patch checks to see if the fold_using_range specified range_query object is the same as the one SCEV uses, and does not invoke SCEV if they do not match. PR tree-optimization/115221 gcc/ * gimple-range-fold.cc (range_of_ssa_name_with_loop_info): Do not invoke SCEV is range_query's do not match. gcc/testsuite/ * gcc.dg/pr115221.c: New. --- gcc/gimple-range-fold.cc | 6 +++++- gcc/testsuite/gcc.dg/pr115221.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr115221.c diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index b3965b5ee50..98a4877ba18 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -1264,7 +1264,11 @@ fold_using_range::range_of_ssa_name_with_loop_info (vrange &r, tree name, fur_source &src) { gcc_checking_assert (TREE_CODE (name) == SSA_NAME); - if (!range_of_var_in_loop (r, name, l, phi, src.query ())) + // SCEV currently invokes get_range_query () for values. If the query + // being passed in is not the same SCEV will use, do not invoke SCEV. + // This can be remove if/when SCEV uses a passed in range-query. + if (src.query () != get_range_query (cfun) + || !range_of_var_in_loop (r, name, l, phi, src.query ())) r.set_varying (TREE_TYPE (name)); } diff --git a/gcc/testsuite/gcc.dg/pr115221.c b/gcc/testsuite/gcc.dg/pr115221.c new file mode 100644 index 00000000000..f139394e5c0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr115221.c @@ -0,0 +1,29 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +typedef unsigned uint32_t; +int cde40_t; +int offset; +void aal_test_bit(); +uint32_t cde40_key_pol(); +long cde40_offset_check(uint32_t pos) { + cde40_key_pol(); + if (cde40_t) + return (offset - 2) % (((pos == 3) ? 18 : 26)) != 0; + return 0; +} +void cde40_check_struct() { + uint32_t i, j, to_compare; + for (;; i++) { + cde40_offset_check(i); + if (to_compare == 0) { + if (i && cde40_key_pol()) + ; + to_compare = i; + continue; + } + j = to_compare; + for (; j < i; j++) + aal_test_bit(); + } +} -- 2.41.0