From patchwork Thu Dec 22 12:54:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 35745 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp306370wrn; Thu, 22 Dec 2022 04:55:09 -0800 (PST) X-Google-Smtp-Source: AMrXdXtxu/jdWJRm3m2Oy2UCs6LgIfI8IXo/7eTkf+WgmldDuw558aEvUZmYK16xSa87omg1q4Zv X-Received: by 2002:a05:6402:3807:b0:47e:eb84:c598 with SMTP id es7-20020a056402380700b0047eeb84c598mr2450072edb.30.1671713708964; Thu, 22 Dec 2022 04:55:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671713708; cv=none; d=google.com; s=arc-20160816; b=C4TP3pq1WoWs1DimTPaJwdoog4rOyr6XgNqT8qL2Bt9wZFaEo0n/NzuAXr+XDQom4x G6TZT3UShzOJFTQv9ns7CNYn87TDr7T6E6nVvz5tFakkEY6NomkfuLQBOvEMrbo+cMTB IEU4gFgGhAif0xJ1gLTPQ1vwnGVcM2/rcJJ0FC2kiaaviBZZ5KdiuP2C+Kz19irbqkLj 6r8a85cYw+YCLIFuIL/7B2t3fAUhfKF02QbkrpnsJtn/Vr8Z5f+3+I4Z9/dQxj/f2UsY 7efwf+gIQB02WggpXxqobgkgI3V3E+MU7KDtoDXKZCdbwfBW8apKW+edSAWBgIAomU8R 38dA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:in-reply-to:mime-version:references:message-id :subject:cc:to:date:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=I0xHIsqLQEZQTJ/uB/1MRC4os+na/8onvAYsjhqUs9I=; b=a9yxoxdba6rHzKolR169+E9b2ormaoGBz3l8+iL/PJyHeI5spSiw/gV/yENkkqBdDw rt/YuBo5MNveIXXDaa8Il6hxwa/q+ipsyY7ScIH8/iI9SXE17AEeuLFSwV/3jLQBhRam USNXx/1rVTadyG8/RfSDQTHlSN77HPSBSNjkMq0P225kt7fuHkieNnC16jfCVZcI3loO wv6wWzAYGS86KICushXfQ+PD/rHlwTxKxi5X5ktT8sV+elUICbJXLToPu2HfYlc/hC8S V8ZnoNUEDj1RgbJitU8PSXt0CQjLzNPFBcPk81zye4qw2s4e6z8umnnSkXHK7OVKfR8r FB0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jQuJbH5h; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id y3-20020a056402358300b00468f9f21c11si685608edc.245.2022.12.22.04.55.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Dec 2022 04:55:08 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jQuJbH5h; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 978613854178 for ; Thu, 22 Dec 2022 12:55:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 978613854178 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671713703; bh=I0xHIsqLQEZQTJ/uB/1MRC4os+na/8onvAYsjhqUs9I=; h=Date:To:Cc:Subject:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=jQuJbH5h9XpAhUyDuDmLxoOx29OxvpM1P1ocxunt6dsVCCDFV/7c9m7L6RlDgJyoF MS1+ABuuQE12LccAEx88jI75nnY9LUuewRqX5YnyCWTBdNP7G8Mlp18SMLO/o99vr2 G5PhnCr7FxOOokWWb/AdYdaqt++ZdlMvnatitaG4= 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 A84AC3858D1E for ; Thu, 22 Dec 2022 12:54:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A84AC3858D1E Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-49-1vO2rUC9PQeMmR83PJvolQ-1; Thu, 22 Dec 2022 07:54:17 -0500 X-MC-Unique: 1vO2rUC9PQeMmR83PJvolQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3B1BF811E6E; Thu, 22 Dec 2022 12:54:17 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.114]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E238C40C2064; Thu, 22 Dec 2022 12:54:16 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 2BMCsEmP1197337 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 22 Dec 2022 13:54:14 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2BMCsDjZ1197336; Thu, 22 Dec 2022 13:54:13 +0100 Date: Thu, 22 Dec 2022 13:54:12 +0100 To: Aldy Hernandez Cc: Richard Biener , gcc-patches , Andrew MacLeod Subject: [PATCH] phiopt: Adjust instead of reset phires range Message-ID: References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752918874072582458?= X-GMAIL-MSGID: =?utf-8?q?1752918874072582458?= On Thu, Dec 22, 2022 at 01:09:21PM +0100, Aldy Hernandez wrote: > INTEGER_CST singleton and > > union that into the SSA_NAMEs range and then do set_range_info > > with the altered range I guess. > > > > Note that set_range_info is an intersect operation. It should really be > called update_range_info. Up to now, there were no users that wanted to > clobber old ranges completely. Thanks. That would be then (I've committed the previous patch, also for reasons of backporting) following incremental patch. For the just committed testcase, it does the right thing, # RANGE [irange] int [-INF, -1][1, +INF] # iftmp.2_9 = PHI is before the range (using -fdump-tree-all-alias) and r below is [irange] int [-INF, -1][1, +INF], unioned with carg of 0 into VARYING. If I try attached testcase though (which just uses signed char d instead of int d to give more interesting range info), then I see: # RANGE [irange] int [-128, -1][1, 127] # iftmp.2_10 = PHI but strangely r I get from range_of_expr is [irange] int [-128, 127] rather than the expected [irange] int [-128, -1][1, 127]. Sure, it is later unioned with 0, so it doesn't change anything, but I wonder what is the difference. Note, this is before actually replacing the phi arg 8(5) with iftmp.3_11(5). At that point bb4 is: [local count: 966367640]: # RANGE [irange] int [-128, 127] # iftmp.3_11 = PHI if (iftmp.3_11 != 0) goto ; [56.25%] else goto ; [43.75%] and bb 5 is empty forwarder, so [-128, -1][1, 127] is actually correct. Either iftmp.3_11 is non-zero, then iftmp.2_10 is that value and its range, or it is zero and then iftmp.2_10 is 8, so [-128, -1][1, 127] U [8, 8], but more importantly SSA_NAME_RANGE_INFO should be at least according to what is printed be without 0. 2022-12-22 Jakub Jelinek Aldy Hernandez * tree-ssa-phiopt.cc (value_replacement): Instead of resetting phires range info, union it with oarg. Jakub // PR tree-optimization/108166 // { dg-do run } bool a, b; signed char d; int c; const int & foo (const int &f, const int &g) { return !f ? f : g; } __attribute__((noipa)) void bar (int) { } int main () { c = foo (b, 0) > ((b ? d : b) ?: 8); a = b ? d : b; bar (a); if (a != 0) __builtin_abort (); } --- gcc/tree-ssa-phiopt.cc.jj 2022-12-22 12:52:36.588469821 +0100 +++ gcc/tree-ssa-phiopt.cc 2022-12-22 13:11:51.145060050 +0100 @@ -1492,11 +1492,25 @@ value_replacement (basic_block cond_bb, basic_block middle_bb, break; } if (equal_p) - /* After the optimization PHI result can have value - which it couldn't have previously. - We could instead of resetting it union the range - info with oarg. */ - reset_flow_sensitive_info (gimple_phi_result (phi)); + { + tree phires = gimple_phi_result (phi); + if (SSA_NAME_RANGE_INFO (phires)) + { + /* After the optimization PHI result can have value + which it couldn't have previously. */ + value_range r; + if (get_global_range_query ()->range_of_expr (r, phires, + phi)) + { + int_range<2> tmp (carg, carg); + r.union_ (tmp); + reset_flow_sensitive_info (phires); + set_range_info (phires, r); + } + else + reset_flow_sensitive_info (phires); + } + } if (equal_p && MAY_HAVE_DEBUG_BIND_STMTS) { imm_use_iterator imm_iter;