From patchwork Tue Apr 30 21:23:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1929857 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=KSAHJYSm; 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 4VTYB10lSkz23hd for ; Wed, 1 May 2024 07:24:38 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A3249385828E for ; Tue, 30 Apr 2024 21:24:36 +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 33E9B3858D20 for ; Tue, 30 Apr 2024 21:24:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 33E9B3858D20 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 33E9B3858D20 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=1714512248; cv=none; b=WBgLU4OAFm9oE8vlKuMIzXdjbWcHcl2tNoaBZJYRTSZE8OxG1ZRAa2BfugtHtStt1hM86RYAkUCBc8SVazcNIfy9fnh6u6sWbGlw+CriECrzxYbcqlcMPerXBmevJ8LRLIPf95QJvs1IzRMKPmEfNMsNrUUeeCai4m++cM0fWAg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714512248; c=relaxed/simple; bh=uNSbJ/agTyOVKEXyeCURzmBpmfweJXoju63c9oxXR2c=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=e8vZk5VibULzwibIOEsynvdItzotBiWMrCAWjI783Wx7aNFho1YleqrZhYRr2r4/4GRvEVRMJ+WrlqFKJI50PiSiR7Op01oLbscZcOA9ZxkgtbwA0hi/d/gdtVciHOmBGMEbd2E3OCnys49n2GULt9FNqV9OH+3nymsaZaMUBWM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714512245; 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=pZdcIqUsRD2fLp96XKigg4lcSdZ2QkjpPcUDHcl0zrI=; b=KSAHJYSmlwddMc6LVJvnkbBRKlZYiEunuVtfTfGIz3ChsuVi56CMYZI+cEtBtVoMm6/lUj xSbG2T7a3Co9VRCPHAedGMJlLlzLNQZPftI9zQDi2sg2Pz0bNfeASx2LGvPZY8a1NPABx+ k1hwBJQB+T3kZotLIdTgHGEWPM7Mpi4= Received: from mail-yw1-f198.google.com (mail-yw1-f198.google.com [209.85.128.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-671-DTJIcWpGPg2loYW_7oMZRg-1; Tue, 30 Apr 2024 17:24:02 -0400 X-MC-Unique: DTJIcWpGPg2loYW_7oMZRg-1 Received: by mail-yw1-f198.google.com with SMTP id 00721157ae682-61bbd6578f9so61936817b3.1 for ; Tue, 30 Apr 2024 14:24:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714512241; x=1715117041; 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=enuSondabX/MvkIngLGJu8GVC2lNk2cHOwpxrX3kq1s=; b=vB02nThBDXwwMIfmEklInqMC08Q7j+VcA7h7k2htjL+oCgrV7xsNhHo+oFYJeinSu9 e+Dfk5OxxVt1T7Ui1cbHTrp8s1D25U8AO92Ev5HNnSNtARI22XJ6hi2zJX318Pv9O9qM hx78d3VZAHPQTBq2sJn8uydpkloVKQ1AO38kxIDRvNOaeh1Qg7gX6CTw7nYfnWu5Sxtt 1560qcoHg91mm7aqHB2+W9MGA5pMd8Zl1VK2J9S2QaoOB6dwpyYCqHwkhewR13cSOxQH ALHWIrVmt7c/p2luo5K6DzZ6SgzKn9cBKL/TkgEQtJZZY+4CFhd3p8wXIg7YzDhOBpfO QXyw== X-Gm-Message-State: AOJu0YzQSuCff4njYJTOUWcTjDdvZZXEEvIA+qOap4qc8+bcTWeRri/a hG2KrlTHGmEYF++K+sqWuwrvhGtfglfEbOJ85yMVSy/Vc1tvrMQt6GY9sXfj2vzAJIC++MwoCNU MkE5kKv0xUpBQ3GX7rjDoQoA1U67qwgd8Yl9+xeqVwFifyHLAy+S7IFZ21zfI7NSUDzZxa1aeSC SMmYJIjxZ/gPw1dNXlmx6n3m0wcOUMnG3MQ5dSMuU= X-Received: by 2002:a05:690c:6410:b0:615:1527:aa2 with SMTP id hr16-20020a05690c641000b0061515270aa2mr835425ywb.10.1714512241252; Tue, 30 Apr 2024 14:24:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYpXWZk1Y9tT5Zq3GqoXo8sQo8GUmjw58mii8NYdc+1rmEsa/R2U94xAR5vi6qUSA8mG1ySw== X-Received: by 2002:a05:690c:6410:b0:615:1527:aa2 with SMTP id hr16-20020a05690c641000b0061515270aa2mr835409ywb.10.1714512240629; Tue, 30 Apr 2024 14:24:00 -0700 (PDT) Received: from [192.168.0.174] ([104.219.121.64]) by smtp.gmail.com with ESMTPSA id h5-20020ac85485000000b00439cccb91b2sm7868097qtq.73.2024.04.30.14.23.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Apr 2024 14:24:00 -0700 (PDT) Message-ID: Date: Tue, 30 Apr 2024 17:23:58 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: gcc-patches Cc: "hernandez, aldy" From: Andrew MacLeod Subject: [COMMITTED 1/5] Remove wrapper around gimple_range_global. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, 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: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org This came up during stage 4 when someone noticed a comment that said when legacy EVRP was removed, the wrapper around accessing SSA_NAME_RANGES for initial values could be removed. To be clearer, the original discussion is here: https://gcc.gnu.org/pipermail/gcc-patches/2021-June/571709.html We couldn't prime ranger's initial use of an ssa-name before inlining, or we would end up removing builtin_unreachable calls. These conditions are no longer present, and its safe to simple always pick up whatever the best value we can find. It even provides a modest speedup with less condition checking on every access to a global. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  pushed. Andrew From f3571462b581e1b57d563268483207bc929de952 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 20 Feb 2024 12:27:51 -0500 Subject: [PATCH 1/9] Remove wrapper around gimple_range_global. Now that legacy EVRP has been removed, we can remove the wrapper which prevented us from using global names before inlining except under some specific conditions. See discussion: https://gcc.gnu.org/pipermail/gcc-patches/2021-June/571709.html * value-query.cc (get_range_global): Rename to gimple_range_global. (gimple_range_global): Remove wrapper function. (global_range_query::range_of_expr): Call gimple_range_global. --- gcc/value-query.cc | 40 +++++++--------------------------------- 1 file changed, 7 insertions(+), 33 deletions(-) diff --git a/gcc/value-query.cc b/gcc/value-query.cc index 052b7511565..e88c8e25789 100644 --- a/gcc/value-query.cc +++ b/gcc/value-query.cc @@ -280,11 +280,15 @@ get_ssa_name_ptr_info_nonnull (const_tree name) // Update the global range for NAME into the SSA_RANGE_NAME_INFO and // Return the legacy global range for NAME if it has one, otherwise // return VARYING. +// See discussion here regarding why there use to be a wrapper function: +// https://gcc.gnu.org/pipermail/gcc-patches/2021-June/571709.html +// Legacy EVRP has been removed, leaving just this function. -static void -get_range_global (vrange &r, tree name, struct function *fun = cfun) +void +gimple_range_global (vrange &r, tree name, struct function *fun) { tree type = TREE_TYPE (name); + gcc_checking_assert (TREE_CODE (name) == SSA_NAME); if (SSA_NAME_IS_DEFAULT_DEF (name)) { @@ -332,36 +336,6 @@ get_range_global (vrange &r, tree name, struct function *fun = cfun) r.set_varying (type); } -// This is where the ranger picks up global info to seed initial -// requests. It is a slightly restricted version of -// get_range_global() above. -// -// The reason for the difference is that we can always pick the -// default definition of an SSA with no adverse effects, but for other -// SSAs, if we pick things up to early, we may prematurely eliminate -// builtin_unreachables. -// -// Without this restriction, the test in g++.dg/tree-ssa/pr61034.C has -// all of its unreachable calls removed too early. -// -// See discussion here: -// https://gcc.gnu.org/pipermail/gcc-patches/2021-June/571709.html - -void -gimple_range_global (vrange &r, tree name, struct function *fun) -{ - tree type = TREE_TYPE (name); - gcc_checking_assert (TREE_CODE (name) == SSA_NAME); - - if (SSA_NAME_IS_DEFAULT_DEF (name) || (fun && fun->after_inlining) - || is_a (SSA_NAME_DEF_STMT (name))) - { - get_range_global (r, name, fun); - return; - } - r.set_varying (type); -} - // ---------------------------------------------- // global_range_query implementation. @@ -373,7 +347,7 @@ global_range_query::range_of_expr (vrange &r, tree expr, gimple *stmt) if (!gimple_range_ssa_p (expr)) return get_tree_range (r, expr, stmt); - get_range_global (r, expr); + gimple_range_global (r, expr); return true; } -- 2.41.0 From patchwork Tue Apr 30 21:24:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1929860 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=BadOV6xb; 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 4VTYCB4bvPz1ymc for ; Wed, 1 May 2024 07:25:42 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D5803384AB4C for ; Tue, 30 Apr 2024 21:25:40 +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 695F53858D38 for ; Tue, 30 Apr 2024 21:24:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 695F53858D38 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 695F53858D38 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=1714512261; cv=none; b=JpMVj3z9AOFfTHfuPoXd7Z86XZJWlTwVCkf1Y/BSXxbF+RUgwcbsKZeywB8ZvZRgFqVIwnOjBOFeGZZPMU1YtiEM4T/betwMIulC/x1X4cUSX+htwB3Yb4aoJiqHjhOim2i5Gwoe/hnffqFRXkC7GNmXYVF8dc3M4CgXFkXuvAI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714512261; c=relaxed/simple; bh=r0NC0tZMyt/nG3SxAywnN4SHkPUx68KugHeWA86XjqA=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=GFRRJCn+P9A7zJWrdsRQT+npMq/3108d3KJ3BpZ0idvX3dMvlbeN8A+2h71nBz1Z/PScvBWJ5iqGd8b1NUqQjVJiulNE9qEVxs4mWpYXVD/j3+bfZ9lhEYrefoWm7PIJpe7OPtioYawmFGDQWZT0yylIBhi0eYDhfQZDWhEn8dw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714512259; 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=llBGv5gTL5y+MBYhLBoBGngZpTFVrz7fEJdg3oBYz1E=; b=BadOV6xbzjgyBTQD0YczVDdUL0xpmpmjLO2QbYSJvEVMyHKJ+Jke69G2eRBQ0/7Bvz8JYa ZabyiguYRaZ4J24Y99kIuza1FVRtxrIIAnXIcMQCHeqaunn/BZRzE7syNrNiWuY+72aaEa Pth3PhPNKQO8ZzdNqdZMiGWIjFQO5I8= 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-26-HoOB6RQyO8e-kUSR3pm_Og-1; Tue, 30 Apr 2024 17:24:18 -0400 X-MC-Unique: HoOB6RQyO8e-kUSR3pm_Og-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-4365ab4c663so57802101cf.0 for ; Tue, 30 Apr 2024 14:24:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714512257; x=1715117057; 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=XaN76/QREWh812Bt41BOjRXw7WQ7MHZl8Bk13C5QzA0=; b=XRwSAOMzCt0/zTYsOmJptOp/edwyqZHmXyJRIanOcn43M6ELwI2Ln4X3ButdQ6GuWG h3PrtB4eXtcun5iARM0Q9GYzW1L8dR/CyuhJ55nMY4pY+4Uh/NCwQOwaRO9BRIdPX7Ag tSjdd9vrRAwfO70FpvIa4YhCabF/1XBH3DWQXOLztPc4HCdas599KEu9rEBdB35L1LWJ uIRaxzECJ6TznlMS/3jawMWjFoKa0Kw5OZ4tVlax3ercjHJzhljxuDNoJSSrOC0//b8c AdeO4a98Qalidd7C5FmhW8CmNSmCXtpmsIcbSfSPQeEfM5AtYnKcf2N/ZsqZZcMaW2Tc 776Q== X-Gm-Message-State: AOJu0YzposBiSNG5jh2OvtmbZ6+VdFg98/2Zo+8ur+zqASHv5o+2CcKu UkcqiPZxpm2bPU2vhDKncvHwzqJR1t6UxtKKiHFz/+x6+JiMlI0UsIjxWzwPGzHMz9SL3MHUXNk vZAO67b3IUQhPLpnGQY0F0q/Mw/K1hbuoSdhvvK+bx8KQ/JhmCf1uo5RxSKDo7E2QvGUzJgmGHC tm4AJsWSxN3WQupmgCy5hw8Kd3McRDTuZYpXde4xw= X-Received: by 2002:ac8:7d05:0:b0:43a:cc5d:35b5 with SMTP id g5-20020ac87d05000000b0043acc5d35b5mr490647qtb.22.1714512256643; Tue, 30 Apr 2024 14:24:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFnk/6Z+lQgXZB1iXMnFbvc8nfJS1m/qMfLD9qdbmzQgT+V9eJmGNL9GSD3ZvYNbvErg3hQNQ== X-Received: by 2002:ac8:7d05:0:b0:43a:cc5d:35b5 with SMTP id g5-20020ac87d05000000b0043acc5d35b5mr490634qtb.22.1714512256221; Tue, 30 Apr 2024 14:24:16 -0700 (PDT) Received: from [192.168.0.174] ([104.219.121.64]) by smtp.gmail.com with ESMTPSA id h5-20020ac85485000000b00439cccb91b2sm7868097qtq.73.2024.04.30.14.24.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Apr 2024 14:24:15 -0700 (PDT) Message-ID: Date: Tue, 30 Apr 2024 17:24:15 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: gcc-patches Cc: "hernandez, aldy" From: Andrew MacLeod Subject: [COMMITTED 2/5] Fix ranger when called from SCEV. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.9 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, 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: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Also during stage 3/4, we discovered that it is unsafe to call ranger from within SCEV.  This is because ranger uses SCEV to resolve PHIS, and we can end up in a bad loop under the right conditions. The fix is for ranger's cache to NOT try to pre-evaluate PHIs (which is kind of waste anyway since they rarely resolve based on known incoming ranges to anything interesting). Combined with this, it is now safe to make filling the block cache re-entrant (which can also happen if called from SCEV). Turns out not wasting time pre-evaluating PHIs was also a time win.. so this patch also provides some modest speedups. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  pushed. Andrew From 83e95c10ed822270e39cb8da8c09f607ad65abbd Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Wed, 13 Mar 2024 14:10:41 -0400 Subject: [PATCH 2/9] Fix ranger when called from SCEV. Do not pre-evaluate PHIs in the cache, and allow fill_block_cache to be re-entrant. This allows SCEV to call into ranger with a context and not produce cycles or loops. * gimple-range-cache.cc (ranger_cache::get_global_range): Do not pre-evaluate PHI nodes from the cache. (ranger_cache::fill_block_cache): Make re-entrant. --- gcc/gimple-range-cache.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index a33b7a73872..72ac2552311 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -1047,7 +1047,9 @@ ranger_cache::get_global_range (vrange &r, tree name, bool ¤t_p) if (r.varying_p () && !cfun->after_inlining) { gimple *s = SSA_NAME_DEF_STMT (name); - if (gimple_get_lhs (s) == name) + // Do not process PHIs as SCEV may be in use and it can + // spawn cyclic lookups. + if (gimple_get_lhs (s) == name && !is_a (s)) { if (!fold_range (r, s, get_global_range_query ())) gimple_range_global (r, name); @@ -1413,7 +1415,7 @@ ranger_cache::fill_block_cache (tree name, basic_block bb, basic_block def_bb) // At this point we shouldn't be looking at the def, entry block. gcc_checking_assert (bb != def_bb && bb != ENTRY_BLOCK_PTR_FOR_FN (cfun)); - gcc_checking_assert (m_workback.length () == 0); + unsigned start_length = m_workback.length (); // If the block cache is set, then we've already visited this block. if (m_on_entry.bb_range_p (name, bb)) @@ -1500,7 +1502,7 @@ ranger_cache::fill_block_cache (tree name, basic_block bb, basic_block def_bb) } m_on_entry.set_bb_range (name, bb, block_result); - gcc_checking_assert (m_workback.length () == 0); + gcc_checking_assert (m_workback.length () == start_length); return; } @@ -1512,7 +1514,7 @@ ranger_cache::fill_block_cache (tree name, basic_block bb, basic_block def_bb) m_on_entry.set_bb_range (name, bb, undefined); gcc_checking_assert (m_update->empty_p ()); - while (m_workback.length () > 0) + while (m_workback.length () > start_length) { basic_block node = m_workback.pop (); if (DEBUG_RANGE_CACHE) -- 2.41.0 From patchwork Tue Apr 30 21:24:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1929858 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=S8YDPXl8; 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 4VTYBM6jTmz23hd for ; Wed, 1 May 2024 07:24:59 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2A0293858404 for ; Tue, 30 Apr 2024 21:24:58 +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 0DD7E3858C56 for ; Tue, 30 Apr 2024 21:24:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0DD7E3858C56 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 0DD7E3858C56 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=1714512273; cv=none; b=FUxMQ5eUm7Yppm9zPaljLZubCS8PbKUNP1IkwTCYolnoqaFERJdvAlucgUFDmZSIXoNYei6OZAuP1tDUi/iJYzmHeVWWeEi/HFgZNFvtGFIbqVm6L20hQrrTeEmFJm2OLZablT4o218JHJN6Ec206PSrz0jCv4M8QdO023bmP14= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714512273; c=relaxed/simple; bh=b7ivi+yc2JYfvwr1JSAi7LGPqPg3T5Adaj4xDzCZIUo=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=B6eK/twN+ij5grkcwt5koLRxZ7XVN7ff+oaHaspmA3mDrEFMPZxYqWrPxobaFnGeJw/0jF0Sc0T7fr7ckbpYl+ypC63fl6noQ7qzhIT6ACsRIHQTQXZnyr2eJsSykbfpX57U/pK+Kb6YwrJoS0+BGPofVdTaztFGyoaPdxNFGjw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714512267; 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=nEc98wU59OAp/sDIukk4hgMBImKSj7viEkdRGOw3O4I=; b=S8YDPXl8Q/isyEvdFQT5r0CeSJwCkRVm9NzbVxWXrRIW2Ga6jZ7/JEQcwobyjIs66zF7Uw BKOfjX61u+KpDQB3eC7ggIg5ZCQmrOn8DDtWwqNwpPnsRakSiG9SzeL/vGpwfDri87uCn2 8JIb3YxJn1G1VylVCDbEL0QzEG7SJu0= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-84-ISvsz3fIN6iUH4g6XQhKBQ-1; Tue, 30 Apr 2024 17:24:24 -0400 X-MC-Unique: ISvsz3fIN6iUH4g6XQhKBQ-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-43ace079ba1so36630791cf.0 for ; Tue, 30 Apr 2024 14:24:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714512263; x=1715117063; 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=9mTrnukqWiY3ReRyHBrmuo+W98iLJEBqusGuc2pI4sU=; b=FlfT9YphxPd7X/m34K9rXL+YlIJnAaYaRFRVqlPoZX3x8n/cCuVBWM91k5XbrsriUE ZGTdsVTYj3WGALvONqo1vdUWAoGkrj9ebeXpbnL4XERrrYWdOkDBiwU+6G+n4OSueSML U3dHwT/KqAW/VXFIkVlQqeKCStLDRFohXHw4V9j+89BXE4Q/3Kf22rG9G41NUdsgbR+f 4tnl7MkU2Q1RmXU2pf06m30CWe7JiA43/JzvFU27X9knNiiXi3HuC20spUZXWoEzADRd 4/Rw3EhLjWQBqmRw36QWCM4v1Pwga/JAfufK8lNMwvu8iZruw7K20mPvDAKa7SoOu5K+ KkyQ== X-Gm-Message-State: AOJu0Yxau2qDrveS1jtbIj8B0fmP8N6+y2KTeOhttrxVbF/eMSPmiNcg YUhtKJHUVGKJmMKXKjBNP1MEx7AxdWvTWf7GK6r8zGXCJF9N2j8VGslgcQ6iLQAQDSQCC7Zgq8T 2NWB3D36urfS9ossja895p3Ww8qQX6NYfwIW7ti4UuZxfXmsmBhgMF+ukGXk+5iN1OBoFcxnc4b V6QZldplULZ1H8F+tM/LWTOdOsxWLudDiC5ZtoI6c= X-Received: by 2002:a05:622a:3ca:b0:43a:a8ad:1131 with SMTP id k10-20020a05622a03ca00b0043aa8ad1131mr459151qtx.5.1714512263409; Tue, 30 Apr 2024 14:24:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHTUsjDlf0/lXl1X+2GyFMgLVL0vTUS9wFl6gVjGvKDiRO5XkejJGj1sSNYNzSI/huBDo4NQw== X-Received: by 2002:a05:622a:3ca:b0:43a:a8ad:1131 with SMTP id k10-20020a05622a03ca00b0043aa8ad1131mr459143qtx.5.1714512263067; Tue, 30 Apr 2024 14:24:23 -0700 (PDT) Received: from [192.168.0.174] ([104.219.121.64]) by smtp.gmail.com with ESMTPSA id h5-20020ac85485000000b00439cccb91b2sm7868097qtq.73.2024.04.30.14.24.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Apr 2024 14:24:22 -0700 (PDT) Message-ID: <7e388f53-180d-49bd-912f-6f06f52d46e0@redhat.com> Date: Tue, 30 Apr 2024 17:24:22 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: gcc-patches Cc: "hernandez, aldy" From: Andrew MacLeod Subject: [COMMITTED 3/5] Invoke range_of_stmt on ssa_names with no context. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.1 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 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 If range_of_expr is called on an ssa-name with no context, ranger just grabs whatever the global value is. It was pointed out we can do better than this.  If the name is in the IL, there is no reason for ranger to not try to fold the statement and see if we get a better result for it.   It removes an unnecessary penalty when there is no statement given for context. This requires a tiny bit more work, sometimes for no benefit. However, the slowdown is also marginal. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  pushed. Andrew From cca3c4f2e7075fe613ac1cd67a3e1743faf33505 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Wed, 13 Mar 2024 14:13:28 -0400 Subject: [PATCH 3/9] Invoke range_of_stmt on ssa_names with no context. Evalaute ssa-names when range_of_expr is called with no context statement by calling range_of_stmt to get an initial value. * gimple-range.cc (gimple_ranger::range_of_expr): Call range_of_stmt when there is no context stmt. --- gcc/gimple-range.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc index 4d3b1ce8588..3966cfbd14c 100644 --- a/gcc/gimple-range.cc +++ b/gcc/gimple-range.cc @@ -102,7 +102,15 @@ gimple_ranger::range_of_expr (vrange &r, tree expr, gimple *stmt) if (!stmt) { Value_Range tmp (TREE_TYPE (expr)); - m_cache.get_global_range (r, expr); + // If there is no global range for EXPR yet, try to evaluate it. + // This call sets R to a global range regardless. + if (!m_cache.get_global_range (r, expr)) + { + gimple *s = SSA_NAME_DEF_STMT (expr); + // Calculate a range for S if it is safe to do so. + if (s && gimple_bb (s) && gimple_get_lhs (s) == expr) + return range_of_stmt (r, s); + } // Pick up implied context information from the on-entry cache // if current_bb is set. Do not attempt any new calculations. if (current_bb && m_cache.block_range (tmp, current_bb, expr, false)) -- 2.41.0 From patchwork Tue Apr 30 21:24:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1929859 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=Zr+C0NjU; 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 4VTYBS53plz23hd for ; Wed, 1 May 2024 07:25:04 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E80B4384B000 for ; Tue, 30 Apr 2024 21:25:02 +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 A107C3858D34 for ; Tue, 30 Apr 2024 21:24:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A107C3858D34 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 A107C3858D34 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=1714512275; cv=none; b=AqzdBWQjSHbZeec1cr7pPYeTTMQhEULNF5J/6SsPbnAj11RnhuNL1/3XfSrKYxHcdv3OMexdq/TProryfF7YreMY2lvgk/dKx63nR6OQciXfO+Gd1ZRwr+KXPmj1wb0FyLGPbm8kgq6d5Z7niq8NkXDSJLxH1Ovd+whsDY/BCCU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714512275; c=relaxed/simple; bh=s5l/NOlR24LtkE4L9o5/MnyQV5BxLNNZHBs531mG9XQ=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=wZh0Zj/13OG8Pfj6UbflLGu0fv3Xy8yOhj7mX8MqScAUfVq9te8zgC52W08LKZVdy+/amepswNqvsXCN12RHtiOexmZIZu2mf3RjOfQMXQjPSHsFXlfSlPX/6w6KIdz3EyfwYU/gQvdHfcjOkvK/s6P9QEw31TLtgJ2XnRcZ76g= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714512272; 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=Q+3ZgFpsDOHag4+3/QGaFq7CsXVMraR5KE9q5IkuR6c=; b=Zr+C0NjU4Yx9mmxAAizFhK/nlWrN5c4BN2na0IrqwSja8+vNC9ocmWpMe0eDWySVXTMJBE YAQ5JHVdWNw0o0Lcw1vqkkhfimbLjU46hAEhFYBA5KDx8/pR2VupzQ6S8k+5l2cxtBkIVe /VQOc7Rs2zJMyXNxRrhf3rJbRVzSo+4= Received: from mail-yb1-f197.google.com (mail-yb1-f197.google.com [209.85.219.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-629-7aA-HcsqPzuFvDGDTq9IjQ-1; Tue, 30 Apr 2024 17:24:30 -0400 X-MC-Unique: 7aA-HcsqPzuFvDGDTq9IjQ-1 Received: by mail-yb1-f197.google.com with SMTP id 3f1490d57ef6-dc64f63d768so12290225276.2 for ; Tue, 30 Apr 2024 14:24:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714512269; x=1715117069; 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=+9CwLWhWr6Kyzd8W6Sz8Qo99RoudQlLigufaNb/+Gmc=; b=CB1dqhKduSudA4fLss8C2mMnDZkDVTngliOLDBoEH/N0D5OuS/VnHKNHAabe2BW/t/ x+KKk0GQ898Z2QQOVyLc1BjOwwW4sZUR2HMHfG2mBCpGZhdM0/Rgo+fTnOi7+jncRZIt +mgHJzgDJvMTjibW8YZSyAMlCrh1sHUpOgOr4hA41a4hGPzYTVCQllNSZks98TxsFJlQ 1clTY6iFKZlbnj899IGp36NaC368WqAQd2sAR1lGUR4gflopyA2z6g4+wrPOMrczBqDb 3s0HCJehcL7M1i18y0T6bPiL6N+DDWg17KvU2UpcwjtJ5mKQ93YGZzoCZXqOMxHFv3eu 5B1w== X-Gm-Message-State: AOJu0Yyzpc8xrhWIQ1xvldqotwTcXlQGsdpUWo0IWW/m3YnJGrlE3/sR IS0SRAc5QejRn0vjBLvxUXpdFWc9FYBo0p55dW83Ay31I2SwEK3U3uMmAjxaZSbxEJTgP33j4MM euGKQn0U4ynu10FWA3poGjpTJCQVfRii32it44iOqvi8etKTp1idTKQzZbUykGkLFrLc+lZxjDg h3NmzOVrIofy9XGb8BQGYZGJpOjedYqssJBOMPElE= X-Received: by 2002:a25:907:0:b0:dcc:9e88:b15 with SMTP id 7-20020a250907000000b00dcc9e880b15mr814500ybj.41.1714512269077; Tue, 30 Apr 2024 14:24:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGqidQPWZBWPDGqNcmPwjOWCtyySvVlOhsLW+fA/C6fTBKt4qMlKu5O4g10wsJtanBCQElsTQ== X-Received: by 2002:a25:907:0:b0:dcc:9e88:b15 with SMTP id 7-20020a250907000000b00dcc9e880b15mr814485ybj.41.1714512268691; Tue, 30 Apr 2024 14:24:28 -0700 (PDT) Received: from [192.168.0.174] ([104.219.121.64]) by smtp.gmail.com with ESMTPSA id h5-20020ac85485000000b00439cccb91b2sm7868097qtq.73.2024.04.30.14.24.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Apr 2024 14:24:28 -0700 (PDT) Message-ID: <9b0d623c-22ba-4a96-87b7-eb10dbf183df@redhat.com> Date: Tue, 30 Apr 2024 17:24:27 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: gcc-patches Cc: "hernandez, aldy" From: Andrew MacLeod Subject: [COMMITTED 4/5] - Add range_on_entry/exit to value_query API. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.8 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, 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: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org It was also requested that I make range_on_entry() and range_on_exit () part of the fomal API for a range_query.  These are now provided along with the orignal range_of_expr (), range_of_stmt (), and range_on_edge ().  The routines were already there, just not published for consumption in the API. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  pushed. Andrew From 4b955ac10f3d978a9be491d9c5277778da005895 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Wed, 13 Mar 2024 14:18:48 -0400 Subject: [PATCH 4/9] Add range_on_entry/exit to value_query API. Add range_on_entry and range_on_exit to the value_query API. These will also work with generic trees like range_of_expr does. * gimple-range.cc (gimple_ranger::range_on_entry): Adjust for new API and support non-SSA expressions. (gimple_ranger::range_on_exit): Ditto. * gimple-range.h (range_on_entry, range_on_exit): Adjust API. * value-query.cc (range_query::range_on_entry): New. (range_query::range_on_exit): New. (range_query::value_on_entry): New. (range_query::value_on_exit): New. (range_query::invoke_range_of_expr): New. (range_query::get_tree_range): Allow stmt, on_entry or on_exit range queries. SSA_NAMES should invoke range_of_expr if possible. * value-query.h (class range_query): Adjust prototypes. --- gcc/gimple-range.cc | 14 ++++--- gcc/gimple-range.h | 4 +- gcc/value-query.cc | 100 ++++++++++++++++++++++++++++++++++++++++---- gcc/value-query.h | 9 +++- 4 files changed, 112 insertions(+), 15 deletions(-) diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc index 3966cfbd14c..e75e2e17dc3 100644 --- a/gcc/gimple-range.cc +++ b/gcc/gimple-range.cc @@ -152,11 +152,13 @@ gimple_ranger::range_of_expr (vrange &r, tree expr, gimple *stmt) // Return the range of NAME on entry to block BB in R. -void +bool gimple_ranger::range_on_entry (vrange &r, basic_block bb, tree name) { + if (!gimple_range_ssa_p (name)) + return get_tree_range (r, name, NULL, bb, NULL); + Value_Range entry_range (TREE_TYPE (name)); - gcc_checking_assert (gimple_range_ssa_p (name)); unsigned idx; if ((idx = tracer.header ("range_on_entry ("))) @@ -174,16 +176,17 @@ gimple_ranger::range_on_entry (vrange &r, basic_block bb, tree name) if (idx) tracer.trailer (idx, "range_on_entry", true, name, r); + return true; } // Calculate the range for NAME at the end of block BB and return it in R. // Return false if no range can be calculated. -void +bool gimple_ranger::range_on_exit (vrange &r, basic_block bb, tree name) { - // on-exit from the exit block? - gcc_checking_assert (gimple_range_ssa_p (name)); + if (!gimple_range_ssa_p (name)) + return get_tree_range (r, name, NULL, NULL, bb); unsigned idx; if ((idx = tracer.header ("range_on_exit ("))) @@ -208,6 +211,7 @@ gimple_ranger::range_on_exit (vrange &r, basic_block bb, tree name) if (idx) tracer.trailer (idx, "range_on_exit", true, name, r); + return true; } // Calculate a range for NAME on edge E and return it in R. diff --git a/gcc/gimple-range.h b/gcc/gimple-range.h index 8739ab6a2ef..167b54b2a37 100644 --- a/gcc/gimple-range.h +++ b/gcc/gimple-range.h @@ -52,8 +52,8 @@ public: virtual bool range_of_stmt (vrange &r, gimple *, tree name = NULL) override; virtual bool range_of_expr (vrange &r, tree name, gimple * = NULL) override; virtual bool range_on_edge (vrange &r, edge e, tree name) override; - void range_on_entry (vrange &r, basic_block bb, tree name); - void range_on_exit (vrange &r, basic_block bb, tree name); + virtual bool range_on_entry (vrange &r, basic_block bb, tree name) override; + virtual bool range_on_exit (vrange &r, basic_block bb, tree name) override; void export_global_ranges (); inline gori_compute &gori () { return m_cache.m_gori; } virtual void dump (FILE *f) override; diff --git a/gcc/value-query.cc b/gcc/value-query.cc index e88c8e25789..c2ab745a466 100644 --- a/gcc/value-query.cc +++ b/gcc/value-query.cc @@ -41,6 +41,18 @@ range_query::range_on_edge (vrange &r, edge, tree expr) return range_of_expr (r, expr); } +bool +range_query::range_on_entry (vrange &r, basic_block, tree expr) +{ + return range_of_expr (r, expr); +} + +bool +range_query::range_on_exit (vrange &r, basic_block, tree expr) +{ + return range_of_expr (r, expr); +} + bool range_query::range_of_stmt (vrange &r, gimple *stmt, tree name) { @@ -54,6 +66,9 @@ range_query::range_of_stmt (vrange &r, gimple *stmt, tree name) return false; } +// If the range of expr EXPR at STMT is a single value, return it. +// Otherwise return NULL_TREE. + tree range_query::value_of_expr (tree expr, gimple *stmt) { @@ -76,6 +91,9 @@ range_query::value_of_expr (tree expr, gimple *stmt) return NULL_TREE; } +// If the range on edge E for EXPR is a single value, return it. +// Otherwise return NULL_TREE. + tree range_query::value_on_edge (edge e, tree expr) { @@ -94,9 +112,11 @@ range_query::value_on_edge (edge e, tree expr) return t; } return NULL_TREE; - } +// If the range of STMT for NAME is a single value, return it. +// Otherwise return NULL_TREE. + tree range_query::value_of_stmt (gimple *stmt, tree name) { @@ -113,7 +133,44 @@ range_query::value_of_stmt (gimple *stmt, tree name) if (range_of_stmt (r, stmt, name) && r.singleton_p (&t)) return t; return NULL_TREE; +} + +// If the range on entry to BB for EXPR is a single value, return it. +// Otherwise return NULL_TREE. + +tree +range_query::value_on_entry (basic_block bb, tree expr) +{ + tree t; + gcc_checking_assert (bb); + if (!Value_Range::supports_type_p (TREE_TYPE (expr))) + return NULL_TREE; + + Value_Range r (TREE_TYPE (expr)); + + if (range_on_entry (r, bb, expr) && r.singleton_p (&t)) + return t; + return NULL_TREE; +} + +// If the range on exit to BB for EXPR is a single value, return it. +// Otherwise return NULL_TREE. + +tree +range_query::value_on_exit (basic_block bb, tree expr) +{ + tree t; + + gcc_checking_assert (bb); + if (!Value_Range::supports_type_p (TREE_TYPE (expr))) + return NULL_TREE; + + Value_Range r (TREE_TYPE (expr)); + + if (range_on_exit (r, bb, expr) && r.singleton_p (&t)) + return t; + return NULL_TREE; } void @@ -130,11 +187,36 @@ range_query::~range_query () { } -// Return a range in R for the tree EXPR. Return true if a range is -// representable, and UNDEFINED/false if not. +// This routine will invoke the equivalent of range_of_expr on +// either a gimple statement STMT, on entry to block BBENTRY, or on +// exit from block BBEXIT. Only one of these 3 fields may be set. +// It is valid for none of them to be set, in wqhich case there is no context. + +bool +range_query::invoke_range_of_expr (vrange &r, tree expr, gimple *stmt, + basic_block bbentry, basic_block bbexit) +{ + if (bbentry) + { + gcc_checking_assert (!stmt && !bbexit); + return range_on_entry (r, bbentry, expr); + } + if (bbexit) + { + gcc_checking_assert (!stmt); + return range_on_exit (r, bbexit, expr); + } + + return range_of_expr (r, expr, stmt); +} + +// Return a range in R for the tree EXPR. The context can be either a STMT, +// or on entry to block BBENTRY or exit from block BBEXIT. +// Return true if a range is representable, and UNDEFINED/false if not. bool -range_query::get_tree_range (vrange &r, tree expr, gimple *stmt) +range_query::get_tree_range (vrange &r, tree expr, gimple *stmt, + basic_block bbentry, basic_block bbexit) { tree type; if (TYPE_P (expr)) @@ -180,6 +262,9 @@ range_query::get_tree_range (vrange &r, tree expr, gimple *stmt) } case SSA_NAME: + // If this is not an abnormal or virtual ssa, invoke range_of_expr. + if (gimple_range_ssa_p (expr)) + return invoke_range_of_expr (r, expr, stmt, bbentry, bbexit); gimple_range_global (r, expr); return true; @@ -210,8 +295,8 @@ range_query::get_tree_range (vrange &r, tree expr, gimple *stmt) { Value_Range r0 (TREE_TYPE (op0)); Value_Range r1 (TREE_TYPE (op1)); - range_of_expr (r0, op0, stmt); - range_of_expr (r1, op1, stmt); + invoke_range_of_expr (r0, op0, stmt, bbentry, bbexit); + invoke_range_of_expr (r1, op1, stmt, bbentry, bbexit); if (!op.fold_range (r, type, r0, r1)) r.set_varying (type); } @@ -228,7 +313,8 @@ range_query::get_tree_range (vrange &r, tree expr, gimple *stmt) Value_Range r0 (TREE_TYPE (TREE_OPERAND (expr, 0))); Value_Range r1 (type); r1.set_varying (type); - range_of_expr (r0, TREE_OPERAND (expr, 0), stmt); + invoke_range_of_expr (r0, TREE_OPERAND (expr, 0), stmt, bbentry, + bbexit); if (!op.fold_range (r, type, r0, r1)) r.set_varying (type); } diff --git a/gcc/value-query.h b/gcc/value-query.h index a1306e2bd25..4d2a7bce485 100644 --- a/gcc/value-query.h +++ b/gcc/value-query.h @@ -60,6 +60,8 @@ public: virtual tree value_of_expr (tree expr, gimple * = NULL); virtual tree value_on_edge (edge, tree expr); virtual tree value_of_stmt (gimple *, tree name = NULL); + virtual tree value_on_entry (basic_block, tree expr); + virtual tree value_on_exit (basic_block, tree expr); // These are the range equivalents of the value_* methods. Instead // of returning a singleton, they calculate a range and return it in @@ -70,6 +72,8 @@ public: virtual bool range_of_expr (vrange &r, tree expr, gimple * = NULL) = 0; virtual bool range_on_edge (vrange &r, edge, tree expr); virtual bool range_of_stmt (vrange &r, gimple *, tree name = NULL); + virtual bool range_on_entry (vrange &r, basic_block bb, tree expr); + virtual bool range_on_exit (vrange &r, basic_block bb, tree expr); // Query if there is any relation between SSA1 and SSA2. relation_kind query_relation (gimple *s, tree ssa1, tree ssa2, @@ -82,7 +86,10 @@ public: virtual void dump (FILE *); protected: - bool get_tree_range (vrange &v, tree expr, gimple *stmt); + bool get_tree_range (vrange &v, tree expr, gimple *stmt, + basic_block bbentry = NULL, basic_block bbexit = NULL); + bool invoke_range_of_expr (vrange &v, tree expr, gimple *stmt, + basic_block bbentry, basic_block bbexit); bool get_arith_expr_range (vrange &r, tree expr, gimple *stmt); relation_oracle *m_oracle; }; -- 2.41.0 From patchwork Tue Apr 30 21:24:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1929861 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=fV36eSdC; 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 4VTYCW17FPz1ymc for ; Wed, 1 May 2024 07:25:59 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 60EBD3858C41 for ; Tue, 30 Apr 2024 21:25:57 +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 06F323858C5F for ; Tue, 30 Apr 2024 21:24:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 06F323858C5F 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 06F323858C5F 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=1714512278; cv=none; b=eClKcrPcPxi/nkgQQ8NjyBSIV/CGRvduVmwYWVXpg41+sgkLhLDVW5SvIdGM3m4JXGaHrVpJLH/AnSIvb4R0EVZN5xBZoIND/lnYF16gPWDM998C5Wu/JJ5F1Ixfj7jFfS0RTgDB1spaV0Cj9uEska1onXR2ryWCRr4A97K0UbA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714512278; c=relaxed/simple; bh=It/T4meXDRaH9DjLHb4onWF49ELb3Kw6MS5vlDDPcb0=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=xeuix3wZE/QMqQockJN1KE0usVDH6OFvX0FjPaj0nSD1ncnE6cug5qKeTbB+pEQ9DTDzRVKy68b/TazBAAv0t+UNX/GPXJHX8nDR9L6N6qlUnBaq5xXC8zRC47aM8suZoCD2FoYBlp3xlgEoRGjXDemu9boGH1MCh1M0xhe7/I8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714512276; 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=87kSfGqBKOcojD2V/81J5ghTtEzl0o7u1st37Iv6t3k=; b=fV36eSdCY2JxSu4H5+n07uJfwl28Inwvm8bH87ao2M0DvE2rN0YqYmMSG8ufFQ0taB/z5u hYff8p7o/yINCwLHffGskVP8aTZ+ulEVu/aDmwLKwkXfb2pav9wuVjCgmw+Xa2YdkghcM/ xo2D1nm/Nh43bZI6dQY3AL6b7Kbtm2s= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-564-anbaSIHkOvep3RMqkiVKIQ-1; Tue, 30 Apr 2024 17:24:35 -0400 X-MC-Unique: anbaSIHkOvep3RMqkiVKIQ-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-43ad0f1a08aso38605331cf.0 for ; Tue, 30 Apr 2024 14:24:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714512274; x=1715117074; 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=hf/g1T+dYzNd9wIThB3MV+dx13IMUXQAPXolTLEvYqk=; b=cM3Fw1JjK9TjGtmzEI6NAXUbJcDAlQeKRFeGr2go6mL1sySQ0qwvx2YEu4B/iNhTeU woA7AIpRUmoNsPKme9APjXMJoyge44DrgdrB0pfWeuCdFDvcBABg9jOjepCbVBJGbBC+ 21A9b6L95c95M6fx90nHYMl6pYU6k01K5l8krgJ8/q1DxxzvjZ8RC5zKO5zD0Dnx8z7d pw3WQfLzpzWCJxdkGVMUBc2vIHy6WDXxtzRSzHtPSKRQhEms1gEi8f6V2fRSLImjztnu RtjPOgz/eVS6oQ/WyyNsb2JIyFBF04C+8rSoY4HyrMt2AnoLK33JCjA/UpbeAUtPtpuZ RH6A== X-Gm-Message-State: AOJu0Yyg+B/dfkoitlAuWVZPpOTz/xNx/BJH/mvffun1VJrSfvVMycT6 jXsDVuGuMiGCUE8UbIPrvFcbmZJtCzqBgSXFzJ6ic5ch+nc4Inj3jWJOeKcQ8ktDcZvH/DaKyMj m4mcfsrm8srdnv9ywHd36uDni6ZEVaDLZsxvifLgvJKnbWWgIF3Op4jcfrSgVoySJbz4ACLP7oN nWso9igToZfr9m6jum8jjtgp1rAb3X2DO14l2DfsI= X-Received: by 2002:a05:622a:1647:b0:43a:ef4e:7b28 with SMTP id y7-20020a05622a164700b0043aef4e7b28mr673638qtj.21.1714512274285; Tue, 30 Apr 2024 14:24:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGd8c0BfV0sXHirE89zYUQW/uwJQdGLul8ou/ZX8N0LmrPYU1Cxm6S/q+Zs854qjdrv92J63Q== X-Received: by 2002:a05:622a:1647:b0:43a:ef4e:7b28 with SMTP id y7-20020a05622a164700b0043aef4e7b28mr673622qtj.21.1714512273969; Tue, 30 Apr 2024 14:24:33 -0700 (PDT) Received: from [192.168.0.174] ([104.219.121.64]) by smtp.gmail.com with ESMTPSA id h5-20020ac85485000000b00439cccb91b2sm7868097qtq.73.2024.04.30.14.24.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Apr 2024 14:24:33 -0700 (PDT) Message-ID: <6375ec58-8532-4cb8-8c5f-be6ac7137d92@redhat.com> Date: Tue, 30 Apr 2024 17:24:33 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: gcc-patches Cc: "hernandez, aldy" From: Andrew MacLeod Subject: [COMMITTED 5/5] Remove incorrect asserts. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.1 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 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 while working on some new range-op enhancements, I found a couple of developing asserts that no longer apply.  This removed them. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  pushed. Andrew From a89de3a24d2312438848e513a0b02b480d52c81e Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 13 Feb 2024 10:07:11 -0500 Subject: [PATCH 5/9] Remove incorrect asserts. Gimple_range_op handles builtin functions, and a couple of asserts that are in place are incorrect in this context, so just remove them. * gimple-range-op.cc (gimple_range_op_handler::calc_op1): Don't assert that here are less than 3 operands. (gimple_range_op_handler::maybe_builtin_call): Simply return if there is no type for the function call. --- gcc/gimple-range-op.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index 9c50c00549e..587de186db2 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -178,7 +178,6 @@ gimple_range_op_handler::gimple_range_op_handler (gimple *s) bool gimple_range_op_handler::calc_op1 (vrange &r, const vrange &lhs_range) { - gcc_checking_assert (gimple_num_ops (m_stmt) < 3); // Give up on empty ranges. if (lhs_range.undefined_p ()) return false; @@ -1213,7 +1212,8 @@ gimple_range_op_handler::maybe_builtin_call () if (func == CFN_LAST) return; tree type = gimple_range_type (call); - gcc_checking_assert (type); + if (!type) + return; if (!Value_Range::supports_type_p (type)) return; -- 2.41.0