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 9133E3858D3C for ; Tue, 18 Oct 2022 08:30:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9133E3858D3C 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 3EC4A20046 for ; Tue, 18 Oct 2022 08:30:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1666081822; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=qL4qaICxWPhVP2OCmrzuobl0dFqVuhPTUewYDnRIIPw=; b=KQ+PGGL+tzPYyb0EBfgKAZU3VTcMcCWXl8yH/EBTNUgXCN1qImcbZrbb1rwgo9ek2EiuXk LKFLuV9pNrUlFiuq6CR0QvrLgIOjCvTbf9dyTsUSdGGOJBCywemcq77BB70i0BwWaroR0D b1JBuX4WbI6Ai5yQ+DepFLq9xCEtCrc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1666081822; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=qL4qaICxWPhVP2OCmrzuobl0dFqVuhPTUewYDnRIIPw=; b=AwTBYbbbfQJawP9v5OtyUo9NvZy+AMG6r1fo2llXWMlOrpxZoMsuvyC4TMdOyL7aV0WHDc yXbPzBj4qUZ/caBg== 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 2B11F139D2 for ; Tue, 18 Oct 2022 08:30:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id fohiCR5kTmP9ZQAAMHmgww (envelope-from ) for ; Tue, 18 Oct 2022 08:30:22 +0000 Date: Tue, 18 Oct 2022 10:30:21 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/107301 - check if we can duplicate block before doing so MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Message-Id: <20221018083022.2B11F139D2@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: Path isolation failed to do that. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/107301 * gimple-ssa-isolate-paths.cc (handle_return_addr_local_phi_arg): Check whether we can duplicate the block. (find_implicit_erroneous_behavior): Likewise. * gcc.dg/torture/pr107301.c: New testcase. --- gcc/gimple-ssa-isolate-paths.cc | 6 ++++-- gcc/testsuite/gcc.dg/torture/pr107301.c | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr107301.c diff --git a/gcc/gimple-ssa-isolate-paths.cc b/gcc/gimple-ssa-isolate-paths.cc index 87ecd19ef4a..e4a4e08f549 100644 --- a/gcc/gimple-ssa-isolate-paths.cc +++ b/gcc/gimple-ssa-isolate-paths.cc @@ -647,7 +647,8 @@ handle_return_addr_local_phi_arg (basic_block bb, basic_block duplicate, if (!maybe && (flag_isolate_erroneous_paths_dereference || flag_isolate_erroneous_paths_attribute) - && gimple_bb (use_stmt) == bb) + && gimple_bb (use_stmt) == bb + && (duplicate || can_duplicate_block_p (bb))) { duplicate = isolate_path (bb, duplicate, e, use_stmt, lhs, true); @@ -765,7 +766,8 @@ find_implicit_erroneous_behavior (void) ? gimple_location (use_stmt) : phi_arg_loc; - if (stmt_uses_name_in_undefined_way (use_stmt, lhs, loc)) + if (stmt_uses_name_in_undefined_way (use_stmt, lhs, loc) + && (duplicate || can_duplicate_block_p (bb))) { duplicate = isolate_path (bb, duplicate, e, use_stmt, lhs, false); diff --git a/gcc/testsuite/gcc.dg/torture/pr107301.c b/gcc/testsuite/gcc.dg/torture/pr107301.c new file mode 100644 index 00000000000..5f0afcc0d10 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr107301.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ + +__attribute__ ((pure, returns_twice)) int +foo (int x) +{ + int a; + + a = x ? 3 : 0; + x /= a; + a = foo (x); + if (x == a) + __builtin_unreachable (); + + return 0; +} -- 2.35.3