From patchwork Thu Dec 7 08:39:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 175021 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4635067vqy; Thu, 7 Dec 2023 00:39:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IG0ie45bllIOYQTV9J7MZyT9KnfruovCQ9daOWEBzPjurzbonRzzKKPmWDMmKfYYwk2w07e X-Received: by 2002:ad4:5a06:0:b0:67a:cbdb:8108 with SMTP id ei6-20020ad45a06000000b0067acbdb8108mr2223036qvb.60.1701938381609; Thu, 07 Dec 2023 00:39:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701938381; cv=pass; d=google.com; s=arc-20160816; b=LaZ5WzyCnVpjjRN1ytT/BIqjMfGufpJyzWI74PZ0CKijivEg7sNAmvA4qK8qr4KXfR 4YsFC6Pxm2rRruiYTZrcCrrmzLGPOcMLopPrqvVy2Id+N5p1eWex25G26lTI/mkMjvz3 V0LkFehFAMl5mtIcQPGtz/jmiLAx6gDMaiknauGLtdv5R7rWo/l0kcXHkpSgTYK+twxE onpd/JrN9WhbOL4S2BmPDCf4Ac+v0L1FIbD+1bpWbgl38h7frfyThIR60En3WuvMg6Z/ K7VaEpVtSyNYxSAjmtk5CL7bZeQ0QRxcJhLxrydfs93Spk89aI7AhQpdVn+PDgDIeHWN pfSg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to: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:from:date :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=sdiJV986KDgw+/5uLNkbyEU4/TyRQ0IaxfpQLzeUlgk=; fh=1eSk23nwesQJIzDgYGQ70Zwi44eJ5HnGJs8f4OTh0UY=; b=ZgJH/I5594JILhvE0FajecT3mkWi8pPZ/pClP2YK5/l3Z7NnmqdTapfQcbpG0EGCDv ZNP2uCkwFAJd3bMDPHFeAfULzm3VVtSt69NgNUs00pUIGsiGDkCAUC6LnpaRp3s0zsaC NgTJxJXHaWwU3wc06q8+vB6bvlkEU6MUOTjuSWzAZPdKlqlKOuOeV7QhTd4GWbUR7+lv TNzGOb4dQok0AOzy+C4lR6Lu/LEa875DeYTKky6OKZXpNizhD2vfXP8lKf+0yRbkVdH4 inPsA8pYJ6Qkrrd0zz/xOVM0hWwzUB3Tb/r0/+dNC/E37BLTNtcMvstQ19vCqDheJIBK 0dnw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CmCMD2QF; arc=pass (i=1); 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=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id e15-20020ac8490f000000b0042384d73c82si828920qtq.301.2023.12.07.00.39.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 00:39:41 -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=@redhat.com header.s=mimecast20190719 header.b=CmCMD2QF; arc=pass (i=1); 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=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5D7883860757 for ; Thu, 7 Dec 2023 08:39:41 +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 C0B52385841F for ; Thu, 7 Dec 2023 08:39:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C0B52385841F 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 C0B52385841F 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=1701938352; cv=none; b=FFg8LiJq6kwWHqJVKX21Op87yq2V1W4XzpL8cGRmQskM8hsFeKI4XivpH1aHWn2W4yCKskWN/Pc+A745vru4DsMcSn6CGOL+C/MlYh8T/EEG+HOOZKF6XFFTiZqK87mRjWXml8DArwnQmPsWTFMWD4TF8drzozFuwy7WA5ra8pY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701938352; c=relaxed/simple; bh=djPAkudO7WgD4CTc7PqjnhzhKVa8vDsZarkJHY4davw=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=JPU5Sw63RBDeWnyBWOzDatbNX80I0YPkHPFwrcbYfnX1iVqq3tmHcZ5yZEjG6GTW7ggMmzWSE4YltpwL47LdDciBIMfIqAWa8jct//RJFvAcb2EmjjG/Yy62+k8kjAIkwxbYj6rFfYKc1M7LaNsAY2fQZ9JBUo2QgFUtjlYJgEg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701938350; 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=sdiJV986KDgw+/5uLNkbyEU4/TyRQ0IaxfpQLzeUlgk=; b=CmCMD2QFbMvHpJBAmmJob62lGfHQ0sc0xe8E2yty6xIAMDUmEcRPteZwGhSPAbFCfJMF0P 96ne1cCI5kZdYORQeAZdNNjR5sazGKOQI1NyGROC9ynZ+jeA1PGCEO2jdW6W/9+CQeSZ4J Wd5TjQSpN6vRn6pumT3NVWCNbNmW1dQ= 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-665-go5U2epROHKpt0_7q4SWAQ-1; Thu, 07 Dec 2023 03:39:09 -0500 X-MC-Unique: go5U2epROHKpt0_7q4SWAQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 162CA84AEEE; Thu, 7 Dec 2023 08:39:09 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.157]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CD27A3C2E; Thu, 7 Dec 2023 08:39:08 +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 3B78d6nK162080 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 7 Dec 2023 09:39:06 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3B78d5sG162079; Thu, 7 Dec 2023 09:39:05 +0100 Date: Thu, 7 Dec 2023 09:39:05 +0100 From: Jakub Jelinek To: Richard Biener , Vladimir Makarov Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] v2: Add IntegerRange for -param=min-nondebug-insn-uid= and fix vector growing in LRA and vec [PR112411] Message-ID: References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-2.6 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, URIBL_BLACK autolearn=no 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: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784611740198345427 X-GMAIL-MSGID: 1784611740198345427 On Thu, Dec 07, 2023 at 09:36:22AM +0100, Jakub Jelinek wrote: > So, one way to fix the LRA issue would be just to use > lra_insn_recog_data_len = index * 3U / 2; > if (lra_insn_recog_data_len <= index) > lra_insn_recog_data_len = index + 1; > basically do what vec.cc does. I thought we can do better for > both vec.cc and LRA on 64-bit hosts even without growing the allocated > counters, but now that I look at it again, perhaps we can't. > The above overflows already with original alloc or lra_insn_recog_data_len > 0x55555556, where 0x5555555 * 3U / 2 is still 0x7fffffff > and so representable in the 32-bit, but 0x55555556 * 3U / 2 is > 1. I thought (and the patch implements it) that we could use > alloc * (size_t) 3 / 2 so that on 64-bit hosts it wouldn't overflow > that quickly, but 0x55555556 * (size_t) 3 / 2 there is 0x80000001 > which is still ok in unsigned, but given that vec.h then stores the > counter into unsigned m_alloc:31; bit-field, it is too much. > > The patch below is what I've actually bootstrapped/regtested on > x86_64-linux and i686-linux, but given the above I think I should drop > the vec.cc hunk and change (size_t) 3 in the LRA hunk to 3U. Here is so far untested adjusted patch, which does the computation just in unsigned int rather than size_t, because doing it in size_t wouldn't improve things. 2023-12-07 Jakub Jelinek PR middle-end/112411 * params.opt (-param=min-nondebug-insn-uid=): Add IntegerRange(0, 1073741824). * lra.cc (check_and_expand_insn_recog_data): Use 3U rather than 3 in * 3 / 2 computation and if the result is smaller or equal to index, use index + 1. * gcc.dg/params/blocksort-part.c: Add dg-skip-if for --param min-nondebug-insn-uid=1073741824. Jakub --- gcc/params.opt.jj 2023-11-02 07:49:18.010852541 +0100 +++ gcc/params.opt 2023-12-06 18:55:57.045420935 +0100 @@ -779,7 +779,7 @@ Common Joined UInteger Var(param_min_loo The minimum threshold for probability of semi-invariant condition statement to trigger loop split. -param=min-nondebug-insn-uid= -Common Joined UInteger Var(param_min_nondebug_insn_uid) Param +Common Joined UInteger Var(param_min_nondebug_insn_uid) Param IntegerRange(0, 1073741824) The minimum UID to be used for a nondebug insn. -param=min-size-for-stack-sharing= --- gcc/lra.cc.jj 2023-12-05 13:17:29.642260866 +0100 +++ gcc/lra.cc 2023-12-06 19:52:01.759241999 +0100 @@ -768,7 +768,9 @@ check_and_expand_insn_recog_data (int in if (lra_insn_recog_data_len > index) return; old = lra_insn_recog_data_len; - lra_insn_recog_data_len = index * 3 / 2 + 1; + lra_insn_recog_data_len = index * 3U / 2; + if (lra_insn_recog_data_len <= index) + lra_insn_recog_data_len = index + 1; lra_insn_recog_data = XRESIZEVEC (lra_insn_recog_data_t, lra_insn_recog_data, lra_insn_recog_data_len); --- gcc/testsuite/gcc.dg/params/blocksort-part.c.jj 2020-01-12 11:54:37.463397567 +0100 +++ gcc/testsuite/gcc.dg/params/blocksort-part.c 2023-12-07 08:46:11.656974144 +0100 @@ -1,4 +1,5 @@ /* { dg-skip-if "AArch64 does not support these bounds." { aarch64*-*-* } { "--param stack-clash-protection-*" } } */ +/* { dg-skip-if "For 32-bit hosts such param is too much and even for 64-bit might require hundreds of GB of RAM" { *-*-* } { "--param min-nondebug-insn-uid=1073741824" } } */ /*-------------------------------------------------------------*/ /*--- Block sorting machinery ---*/