From patchwork Thu Sep 28 10:47:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 145935 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3216397vqu; Thu, 28 Sep 2023 03:48:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEjVNrwu3uhku4vr2gJMInJL0APQsVsdIrMJVNnPn8NVhobsFpj8nAP3UKdU/ju8jJH/P+F X-Received: by 2002:a17:906:28e:b0:9ad:ec25:825b with SMTP id 14-20020a170906028e00b009adec25825bmr801768ejf.58.1695898092025; Thu, 28 Sep 2023 03:48:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695898092; cv=none; d=google.com; s=arc-20160816; b=niSKd//VmEy4sTFIIldv4gdx8AwAQtNMoj/Va+9jVv0kiOWObgydBdoRJ3CBlhxbG9 jyyn+m0Lk6q/iGG+SoSPCYA04ZcFGSnBwJNfy9vNmLiHTwYyyjKdadhUyGKqzPV+leiV pM8Kmnv9wx87nq1QcUTfz3ny8jBLFIcOfIOOoFYvH4EQwmncQkMJNhAvHKLVrTFtY7do qI7AZRRMnDvKWR627xRYYbQXTXtrmXasl0iNauwjmUSffh1hBlGWdQlmAat79E21NDYp OwZjtvAMzDKct3gNSjruCNC8yVjdv+WEWoL3NiaFqnsM9yJCnxZOxYnlySrn5irMLAmy k2XA== ARC-Message-Signature: i=1; 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:to:from:date :dkim-signature:dmarc-filter:delivered-to; bh=T97H3Ykt0gFS0kLeims6jjtbGudM9Xj9aBLTJ0CUp4I=; fh=qkak3WWaCVCdXwcpqXpG5sGMt7CWV/vRjLhzgNmIypI=; b=Dafjn7sARcOaemDgRuii2qKP8f2vfadh4HJgnVlgc1yom2unW2Am3JhG/QGB2eDsyN uKhL+x9yF63H68N1F+tj5I2pV+NWBBuvTkU8eqy48HVNOnW7fdZ2vzCxhTRvT0PqeBnR Jlvgk0MB+aIYQCSS8V380TRx1F+BRnNx3FsmGBmyXy53+CU5FvSTPgTfJJ1oVOSMmJFr GEewmzlBOT9/qMxyAcTjTaURupK4tjo86Dab0kyemC10CZvchKfHLM3gBF9A/onVD25f ISn62sN2jXCcDYaB0iX4zVyFh4hux66PHBbtRNHjU6FYxM4kU/TTpIyZnGCb55djLiHC WRxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Zdputrfg; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id qu15-20020a170907110f00b009ad869ac659si15676752ejb.1004.2023.09.28.03.48.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 03:48:12 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Zdputrfg; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 EFCC0387093F for ; Thu, 28 Sep 2023 10:47:43 +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 00A753861855 for ; Thu, 28 Sep 2023 10:47:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 00A753861855 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695898039; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=T97H3Ykt0gFS0kLeims6jjtbGudM9Xj9aBLTJ0CUp4I=; b=Zdputrfg9Nj+YiWzqeSBl21zancSurwnXxhiKhgPzePYK8pLMqBZ+SNh3BNjlsHeQ8h2Ge k8RfHdsp3cufw5ePkJqvslDUbOLy3/bmXBNg1bgWI7XQml7rMZd90uk+o/cWpqDXEHPoHb YyMNuDL2pyZlwerdvumSWba5hkGgcGU= 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-684-z-TlVVDpPoqV7_rGvGOanw-1; Thu, 28 Sep 2023 06:47:18 -0400 X-MC-Unique: z-TlVVDpPoqV7_rGvGOanw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2A06E8007A4; Thu, 28 Sep 2023 10:47:18 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.193.202]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D2ED52026D68; Thu, 28 Sep 2023 10:47:17 +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 38SAlEvC2652191 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 28 Sep 2023 12:47:15 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 38SAlDnG2652190; Thu, 28 Sep 2023 12:47:13 +0200 Date: Thu, 28 Sep 2023 12:47:13 +0200 From: Jakub Jelinek To: Richard Biener , Richard Sandiford , gcc-patches@gcc.gnu.org Subject: [PATCH] use *_grow_cleared rather than *_grow on vec Message-ID: References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.4 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_H3, 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: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778278037571829656 X-GMAIL-MSGID: 1778278037571829656 On Thu, Sep 28, 2023 at 12:29:15PM +0200, Jakub Jelinek wrote: > On Thu, Sep 28, 2023 at 09:29:31AM +0000, Richard Biener wrote: > > > The following patch splits the bitmap_head class into a POD > > > struct bitmap_head_pod and bitmap_head derived from it with non-trivial > > > default constexpr constructor. Most code should keep using bitmap_head > > > as before, bitmap_head_pod is there just for the cases where we want to > > > embed the bitmap head into a vector which we want to e.g. {quick,safe}_grow > > > and in a loop bitmap_initialize it afterwards (to avoid having to > > > {quick,safe}_grow_cleared them just to overwrite with bitmap_initialize). > > > The patch is larger than I hoped, because e.g. some code just used bitmap > > > and bitmap_head * or const_bitmap and const bitmap_head * interchangeably. > > > > > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > > > OK if there are no comments indicating otherwise. > > A counter argument against this patch would be that it weakens the intent > to catch uses of uninitialized bitmaps for saving a few compile time cycles. > If one uses > bitmap_head var; > bitmap_initialize (&var, NULL); > etc., we spend those extra cycles to initialize it and nothing is told that > bitmap_initialize overwrites the whole var without ever using of any of its > elements, so DSE can't eliminate that. And in the vec case which prompted > this patch it was about > vec a; > a.create (n); > a.safe_grow (n); // vs. a.safe_grow_cleared (n); > for (int i = 0; i < n; ++i) > bitmap_initialize (&a[i], NULL); > When using bitmap_head_pod, one needs to ensure initialization without > help to catch such mistakes. Here is the alternative patch which pays the small extra price while not undermining the checking. Verified in all those places there is a loop doing bitmap_initialize immediately afterwards or worst case a few lines later. With the static_assert uncommented, the remaining failures are poly_int related (supposedly gone with Richard S.'s poly_int patch) and the vect_unpromoted_value/ao_ref still unresolved cases. 2023-09-28 Jakub Jelinek * tree-ssa-loop-im.cc (tree_ssa_lim_initialize): Use quick_grow_cleared instead of quick_grow on vec members. * cfganal.cc (control_dependences::control_dependences): Likewise. * rtl-ssa/blocks.cc (function_info::build_info::build_info): Likewise. (function_info::place_phis): Use safe_grow_cleared instead of safe_grow on auto_vec vars. * tree-ssa-live.cc (compute_live_vars): Use quick_grow_cleared instead of quick_grow on vec var. Jakub --- gcc/tree-ssa-loop-im.cc.jj 2023-09-28 12:06:03.527974171 +0200 +++ gcc/tree-ssa-loop-im.cc 2023-09-28 12:38:07.028966742 +0200 @@ -3496,13 +3496,13 @@ tree_ssa_lim_initialize (bool store_moti (mem_ref_alloc (NULL, 0, UNANALYZABLE_MEM_ID)); memory_accesses.refs_loaded_in_loop.create (number_of_loops (cfun)); - memory_accesses.refs_loaded_in_loop.quick_grow (number_of_loops (cfun)); + memory_accesses.refs_loaded_in_loop.quick_grow_cleared (number_of_loops (cfun)); memory_accesses.refs_stored_in_loop.create (number_of_loops (cfun)); - memory_accesses.refs_stored_in_loop.quick_grow (number_of_loops (cfun)); + memory_accesses.refs_stored_in_loop.quick_grow_cleared (number_of_loops (cfun)); if (store_motion) { memory_accesses.all_refs_stored_in_loop.create (number_of_loops (cfun)); - memory_accesses.all_refs_stored_in_loop.quick_grow + memory_accesses.all_refs_stored_in_loop.quick_grow_cleared (number_of_loops (cfun)); } --- gcc/cfganal.cc.jj 2023-09-28 11:31:45.013870771 +0200 +++ gcc/cfganal.cc 2023-09-28 12:37:34.302425957 +0200 @@ -468,7 +468,7 @@ control_dependences::control_dependences bitmap_obstack_initialize (&m_bitmaps); control_dependence_map.create (last_basic_block_for_fn (cfun)); - control_dependence_map.quick_grow (last_basic_block_for_fn (cfun)); + control_dependence_map.quick_grow_cleared (last_basic_block_for_fn (cfun)); for (int i = 0; i < last_basic_block_for_fn (cfun); ++i) bitmap_initialize (&control_dependence_map[i], &m_bitmaps); for (int i = 0; i < num_edges; ++i) --- gcc/rtl-ssa/blocks.cc.jj 2023-09-28 11:31:45.413865158 +0200 +++ gcc/rtl-ssa/blocks.cc 2023-09-28 12:41:28.063145949 +0200 @@ -57,7 +57,7 @@ function_info::build_info::build_info (u // write to an entry before reading from it. But poison the contents // when checking, just to make sure we don't accidentally use an // uninitialized value. - bb_phis.quick_grow (num_bb_indices); + bb_phis.quick_grow_cleared (num_bb_indices); bb_mem_live_out.quick_grow (num_bb_indices); bb_to_rpo.quick_grow (num_bb_indices); if (flag_checking) @@ -614,7 +614,7 @@ function_info::place_phis (build_info &b // Calculate dominance frontiers. auto_vec frontiers; - frontiers.safe_grow (num_bb_indices); + frontiers.safe_grow_cleared (num_bb_indices); for (unsigned int i = 0; i < num_bb_indices; ++i) bitmap_initialize (&frontiers[i], &bitmap_default_obstack); compute_dominance_frontiers (frontiers.address ()); @@ -626,7 +626,7 @@ function_info::place_phis (build_info &b // they are live on entry to the corresponding block, but do not need // phi nodes otherwise. auto_vec unfiltered; - unfiltered.safe_grow (num_bb_indices); + unfiltered.safe_grow_cleared (num_bb_indices); for (unsigned int i = 0; i < num_bb_indices; ++i) bitmap_initialize (&unfiltered[i], &bitmap_default_obstack); --- gcc/tree-ssa-live.cc.jj 2023-09-28 11:31:45.637862015 +0200 +++ gcc/tree-ssa-live.cc 2023-09-28 12:38:25.590706289 +0200 @@ -1361,7 +1361,7 @@ compute_live_vars (struct function *fn, We then do a mostly classical bitmap liveness algorithm. */ active.create (last_basic_block_for_fn (fn)); - active.quick_grow (last_basic_block_for_fn (fn)); + active.quick_grow_cleared (last_basic_block_for_fn (fn)); for (int i = 0; i < last_basic_block_for_fn (fn); i++) bitmap_initialize (&active[i], &bitmap_default_obstack);