From patchwork Wed Jan 11 10:30:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 41883 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3241358wrt; Wed, 11 Jan 2023 02:31:22 -0800 (PST) X-Google-Smtp-Source: AMrXdXuw0HbpKc1BLrldKYVqgdlDuxok7cybJ6snvXzghv0G5B5GKXuTeYgTz9OsBRDeXHKGUZLY X-Received: by 2002:a17:906:ce3a:b0:84d:242c:13a with SMTP id sd26-20020a170906ce3a00b0084d242c013amr13897766ejb.74.1673433082186; Wed, 11 Jan 2023 02:31:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673433082; cv=none; d=google.com; s=arc-20160816; b=a2JT7zoGhwFfRXX18EXU3LRMGJYX5oRpveA20PLeZ3pEZ4H0KN4sQu07KW8PP6Z1ay 1NeQCjm8VWtgvyD+RZmsm5ISG+COM+HyDVGte6GO36MxZFZA0QbuDA6hvg9luA/E5WxD DVskIsmNpQOSNkGRMKqW1FF3nBddzEwQhBlO/S0fXg8Br3lnlWYpIPxQoNB4auw2Zmmh XraoGNvwdxa3AJON4yIaCNZhx60BSV4AjcyAcwHnG8fUHJJTWktgPCTrSn7CfPjF9c7+ JZpQdQAaW55EZnN9yBfegRU2LxkewvYRzVUSATVcrmU9pFXrN8VDMEpjAyYSurTK8hsq SxVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :content-language:to:subject:from:user-agent:mime-version:date :message-id:dkim-signature:dkim-signature:dmarc-filter:delivered-to; bh=F0F2pV792VEyzGQgxFE/gk+bDlSuH3j2PrBowCiP5EA=; b=fpakUMZLNTCCqteCjmFRu+s3waMwWRB4NQfktHZzk0/ukqMBN5ake9I9GfnDBVu/wU ok93DOaqMsBmAaGzrAdViavc2YnzH39zVpqa5qot8GR0Kzmao8ZkJt8aJ26Jzqd1H984 VGVIkIkCz+EAuviw2MAEWlhsQhW9RppWvZI3mOau1xxnyld7AQPwo0aZ8D194DG4iMoE LeFbaAVhRYPSRn0ueB5vPooyemIj88xiV4RIfSukEEeV5Vbr9QdN1S0ICZvJV6PHqjVZ K4qecXqnYx/SAZ1c4tmpGoKT5VgcwOh9Zi1IZ8RlgaH1h1wa6X3cyGkAejwBWI0HdkA5 jgrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=ered6IBc; dkim=neutral (no key) header.i=@gcc.gnu.org; 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" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id hv22-20020a17090760d600b007b5911c9b13si15289017ejc.831.2023.01.11.02.31.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jan 2023 02:31:22 -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=@suse.cz header.s=susede2_rsa header.b=ered6IBc; dkim=neutral (no key) header.i=@gcc.gnu.org; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 58CF03857C43 for ; Wed, 11 Jan 2023 10:31:17 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id E31C93858C83 for ; Wed, 11 Jan 2023 10:30:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E31C93858C83 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 4DE4776F4B for ; Wed, 11 Jan 2023 10:30:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1673433052; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=F0F2pV792VEyzGQgxFE/gk+bDlSuH3j2PrBowCiP5EA=; b=ered6IBcAXBbXb1DUYNI4H6MhPlZhdt482Ojl6mYWd3SW9hdk15DrqNSmLe8Wl3LGT4SSS i1Rk7EE1hnAZ27VVzIh/2xnRb1ZGQhQe3vDBpgfBJ29/h2t3Bs2E18oO/6JojJ/d9RcGQ8 x2gL1oCQul9Oi6CfdgqTf4ebJCP8Aik= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1673433052; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=F0F2pV792VEyzGQgxFE/gk+bDlSuH3j2PrBowCiP5EA=; b=RQltOjF8Mv+CnA32L9f3BGYFbgN95Vp3m24aTLPO3dfMPrFm7IOpJwpV78hg8zBqa5bA7f X7yoNaAIOB/0X7Cg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 40CEC13591 for ; Wed, 11 Jan 2023 10:30:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id V5mzDtyPvmM3CAAAMHmgww (envelope-from ) for ; Wed, 11 Jan 2023 10:30:52 +0000 Message-ID: Date: Wed, 11 Jan 2023 11:30:51 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 From: =?utf-8?q?Martin_Li=C5=A1ka?= Subject: [PATCH] switch expansion: limit JT growth param values To: gcc-patches@gcc.gnu.org Content-Language: en-US X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, 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: , 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?1754721767701524757?= X-GMAIL-MSGID: =?utf-8?q?1754721767701524757?= Currently, one can request a huge jump table creation which leads to a non-sensual huge output. Moreover, use auto_vec rather than a stack-allocated array. Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Ready to be installed? Thanks, Martin PR middle-end/107976 gcc/ChangeLog: * params.opt: Limit JT params. * stmt.cc (emit_case_dispatch_table): Use auto_vec. --- gcc/params.opt | 4 ++-- gcc/stmt.cc | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/gcc/params.opt b/gcc/params.opt index e178dec1600..3454700eb91 100644 --- a/gcc/params.opt +++ b/gcc/params.opt @@ -327,11 +327,11 @@ Common Joined UInteger Var(param_iv_max_considered_uses) Init(250) Param Optimiz Bound on number of iv uses in loop optimized in iv optimizations. -param=jump-table-max-growth-ratio-for-size= -Common Joined UInteger Var(param_jump_table_max_growth_ratio_for_size) Init(300) Param Optimization +Common Joined UInteger Var(param_jump_table_max_growth_ratio_for_size) Init(300) IntegerRange(0, 10000) Param Optimization The maximum code size growth ratio when expanding into a jump table (in percent). The parameter is used when optimizing for size. -param=jump-table-max-growth-ratio-for-speed= -Common Joined UInteger Var(param_jump_table_max_growth_ratio_for_speed) Init(800) Param Optimization +Common Joined UInteger Var(param_jump_table_max_growth_ratio_for_speed) Init(800) IntegerRange(0, 10000) Param Optimization The maximum code size growth ratio when expanding into a jump table (in percent). The parameter is used when optimizing for speed. -param=l1-cache-line-size= diff --git a/gcc/stmt.cc b/gcc/stmt.cc index 82a3e1035ec..b239c02018a 100644 --- a/gcc/stmt.cc +++ b/gcc/stmt.cc @@ -746,7 +746,7 @@ emit_case_dispatch_table (tree index_expr, tree index_type, tree range, basic_block stmt_bb) { int i, ncases; - rtx *labelvec; + auto_vec labelvec; rtx_insn *fallback_label = label_rtx (case_list[0].m_code_label); rtx_code_label *table_label = gen_label_rtx (); bool has_gaps = false; @@ -779,8 +779,7 @@ emit_case_dispatch_table (tree index_expr, tree index_type, /* Get table of labels to jump to, in order of case index. */ ncases = tree_to_shwi (range) + 1; - labelvec = XALLOCAVEC (rtx, ncases); - memset (labelvec, 0, ncases * sizeof (rtx)); + labelvec.safe_grow_cleared (ncases); for (unsigned j = 0; j < case_list.length (); j++) { @@ -860,11 +859,11 @@ emit_case_dispatch_table (tree index_expr, tree index_type, emit_jump_table_data (gen_rtx_ADDR_DIFF_VEC (CASE_VECTOR_MODE, gen_rtx_LABEL_REF (Pmode, table_label), - gen_rtvec_v (ncases, labelvec), + gen_rtvec_v (ncases, labelvec.address ()), const0_rtx, const0_rtx)); else emit_jump_table_data (gen_rtx_ADDR_VEC (CASE_VECTOR_MODE, - gen_rtvec_v (ncases, labelvec))); + gen_rtvec_v (ncases, labelvec.address ()))); /* Record no drop-through after the table. */ emit_barrier ();