From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 5F0FC3858CDB for ; Wed, 17 Jan 2024 12:50:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5F0FC3858CDB 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 5F0FC3858CDB 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=1705495821; cv=none; b=J8ZTzzEELo+MyienPb+gODVF01zJ8ps/fTxI/QBe9poDpXpkvmMmghqTZ5mEq7ym7ud7HBTC7EfpDniNbcd7fPOkNhMxFxaQ5FPv7c6kGQwazoT6zBsawkE7eCzuL0zHl+3weGvA8a7UlNA4qUixey7oMiIW1FetpD1YZZ/lVRw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705495821; c=relaxed/simple; bh=PKdV78YnOOmaMEhTH1TdyfjBrl2LRbCSVxf+zk4ihiM=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=H5sRhycYIu0zYTwI40ppyU1fEamqxKSzoOTnvbymtb5wYzFXOkIsEEsMYy6mOGoHxygXTdQbEsfDLiQax9Lxw8u2EsBjYbdHrymxmGNBzm/UGOImaaTSVx4dzJEtuf/wBJeUuqcmHyRoc+oYOptgenuXocVBiPPi/OCDTLbV43Y= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705495818; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=L1up0/B3krZPZCobGF6vBMZ0ZMoN7AQC9qRnmXec+PA=; b=YaXbwkEFOE9juxOsx5+6lzOFXxL/Fy9QY0KF38DioTUTHctn/d3IxqrfptflZNFU1e0/IX cXZjmvNHuCnWQkSG3y0eHYJwG6lxYvYtU/AkK9I9gINOgqGcq/0D+7AkoPGQ/YSlAz15/1 uV/fZ5tom3YCmuQeRDqo1bHiSTLTVZs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-531-PvUn81RPPEaHC_pcRSTKGA-1; Wed, 17 Jan 2024 07:50:17 -0500 X-MC-Unique: PvUn81RPPEaHC_pcRSTKGA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 347E2868905; Wed, 17 Jan 2024 12:50:17 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.70]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ED946492BC6; Wed, 17 Jan 2024 12:50: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 40HCoEKS2324758 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 17 Jan 2024 13:50:14 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 40HCoDKM2324757; Wed, 17 Jan 2024 13:50:13 +0100 Date: Wed, 17 Jan 2024 13:50:13 +0100 From: Jakub Jelinek To: Jan Hubicka Cc: gcc-patches@gcc.gnu.org Subject: Re: Fix merging of value predictors Message-ID: Reply-To: Jakub Jelinek References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-4.3 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_H4,RCVD_IN_MSPIKE_WL,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 List-Id: On Wed, Jan 17, 2024 at 01:45:18PM +0100, Jan Hubicka wrote: > Hi, > expr_expected_value is doing some guesswork when it is merging two or more > independent value predictions either in PHI node or in binary operation. > Since we do not know how the predictions interact with each other, we can > not really merge the values precisely. > > The previous logic merged the prediciton and picked the later predictor > (since predict.def is sorted by reliability). This however leads to troubles > with __builtin_expect_with_probability since it is special cased as a predictor > with custom probabilities. If this predictor is downgraded to something else, > we ICE since we have prediction given by predictor that is not expected > to have customprobability. > > This patch fixies it by inventing new predictors PRED_COMBINED_VALUE_PREDICTIONS > and PRED_COMBINED_VALUE_PREDICTIONS_PHI which also allows custom values but > are considered less reliable then __builtin_expect_with_probability (they > are combined by ds theory rather then by first match). This is less likely > going to lead to very stupid decisions if combining does not work as expected. > > I also updated the code to be bit more careful about merging values and do not > downgrade the precision when unnecesary (as tested by new testcases). > > Bootstrapped/regtested x86_64-linux, will commit it tomorrow if there are > no complains. > > 2024-01-17 Jan Hubicka > Jakub Jelinek 2 spaces before < rather than 1. > > PR tree-optimization/110852 > > gcc/ChangeLog: > > * predict.cc (expr_expected_value_1): > (get_predictor_value): > * predict.def (PRED_COMBINED_VALUE_PREDICTIONS): > (PRED_COMBINED_VALUE_PREDICTIONS_PHI): > > gcc/testsuite/ChangeLog: > > * gcc.dg/predict-18.c: Please fill in what has changed, both for predict-18.c and predict.{cc,def} changes. > @@ -2613,24 +2658,40 @@ expr_expected_value_1 (tree type, tree op0, enum tree_code code, > if (!nop1) > nop1 = op1; > } > + /* We already checked if folding one of arguments to constant is good > + enough. Consequently failing to fold both means that we will not > + succeed determinging the value. */ s/determinging/determining/ Otherwise LGTM. Jakub