From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 0A49D3858D1E for ; Tue, 14 Feb 2023 15:20:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0A49D3858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de 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 391DD1FD95; Tue, 14 Feb 2023 15:20:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1676388025; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=CGiHUAQfss0D9OupIDh7aSUaLMqceInnVD4gQNXqdO4=; b=XrCKogD4iMgT6Sweb3r2shsS9uEBH4erPzdzLxvMwAbZC8wT/DWRzNa0xl3MDduXRKnmNI sqGKwDsABoF2AdCT6aOp6AkOe3puGX06gxPz0BBKn5PDM5fA9C3khMsp0sxQhQlpdWI1P5 ORer47NIhOomKbHhJ0Ay5MliOmn+qWc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1676388025; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=CGiHUAQfss0D9OupIDh7aSUaLMqceInnVD4gQNXqdO4=; b=6TwxoSszKQrWKmEkkPeFcqTT0xm92+5TUGYWLTtsg9mhgG3TNiHBqOFwn07yUexKgACCcX iMhOHRQJ1Zd8w7DQ== 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 2226E138E3; Tue, 14 Feb 2023 15:20:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 9yNMB7mm62MobwAAMHmgww (envelope-from ); Tue, 14 Feb 2023 15:20:25 +0000 Date: Tue, 14 Feb 2023 16:20:24 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org cc: Jakub Jelinek Subject: [PATCH] Fix possible sanopt compile-time hog MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Message-Id: <20230214152025.2226E138E3@imap2.suse-dmz.suse.de> 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 List-Id: While working on bitmap operations I figured sanopt.cc uses a sbitmap worklist, iterating using bitmap_first_set_bit on it. That's quadratic since bitmap_first_set_bit for sbitmap is O(n). The fix is to use regular bitmaps for the worklist and the bitmap feeding it and to avoid a useless copy. Bootstrap and regtest running on x86_64-unknown-linux-gnu. OK for trunk? Thanks, Richard. * sanopt.cc (sanitize_asan_mark_unpoison): Use bitmap for with_poison and alias worklist to it. (sanitize_asan_mark_poison): Likewise. --- gcc/sanopt.cc | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/gcc/sanopt.cc b/gcc/sanopt.cc index aed22850079..b356a21eca3 100644 --- a/gcc/sanopt.cc +++ b/gcc/sanopt.cc @@ -987,15 +987,11 @@ static void sanitize_asan_mark_unpoison (void) { /* 1) Find all BBs that contain an ASAN_MARK poison call. */ - auto_sbitmap with_poison (last_basic_block_for_fn (cfun) + 1); - bitmap_clear (with_poison); + auto_bitmap with_poison; basic_block bb; FOR_EACH_BB_FN (bb, cfun) { - if (bitmap_bit_p (with_poison, bb->index)) - continue; - gimple_stmt_iterator gsi; for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi); gsi_prev (&gsi)) { @@ -1010,8 +1006,8 @@ sanitize_asan_mark_unpoison (void) auto_sbitmap poisoned (last_basic_block_for_fn (cfun) + 1); bitmap_clear (poisoned); - auto_sbitmap worklist (last_basic_block_for_fn (cfun) + 1); - bitmap_copy (worklist, with_poison); + /* We now treat with_poison as worklist. */ + bitmap worklist = with_poison; /* 2) Propagate the information to all reachable blocks. */ while (!bitmap_empty_p (worklist)) @@ -1088,8 +1084,7 @@ static void sanitize_asan_mark_poison (void) { /* 1) Find all BBs that possibly contain an ASAN_CHECK. */ - auto_sbitmap with_check (last_basic_block_for_fn (cfun) + 1); - bitmap_clear (with_check); + auto_bitmap with_check; basic_block bb; FOR_EACH_BB_FN (bb, cfun) @@ -1108,8 +1103,8 @@ sanitize_asan_mark_poison (void) auto_sbitmap can_reach_check (last_basic_block_for_fn (cfun) + 1); bitmap_clear (can_reach_check); - auto_sbitmap worklist (last_basic_block_for_fn (cfun) + 1); - bitmap_copy (worklist, with_check); + /* We now treat with_check as worklist. */ + bitmap worklist = with_check; /* 2) Propagate the information to all definitions blocks. */ while (!bitmap_empty_p (worklist)) -- 2.35.3