From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id D5E433858291; Tue, 18 Oct 2022 08:31:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D5E433858291 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666081877; bh=1NX8owOx0M7zg9tTcBIdGGzdFgVGPcSw9s98PJpTNGA=; h=From:To:Subject:Date:From; b=t3Yw4cRMvdCZEe/cCZvvmaV9QSMz2Xh4IvFpx1b1y04ZwhhtDeUkD92roJawgm0RA 7Mi4oN7GrssWvvvxvIBZW48r4LB2FR1VFDXLQkOq3oXgn3IC0ejg+WulJs4FQSLP1u UOqq3LgTj3g4GcnHe5Dx3DyhaUQmC53b2LurWZlQ= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3352] tree-optimization/107301 - check if we can duplicate block before doing so X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: 35106383c0995682f3bef20f745285f791796473 X-Git-Newrev: 5ad3cc1ecc3c7c61d5e319f74cb7287fb80944fd Message-Id: <20221018083117.D5E433858291@sourceware.org> Date: Tue, 18 Oct 2022 08:31:17 +0000 (GMT) List-Id: https://gcc.gnu.org/g:5ad3cc1ecc3c7c61d5e319f74cb7287fb80944fd commit r13-3352-g5ad3cc1ecc3c7c61d5e319f74cb7287fb80944fd Author: Richard Biener Date: Tue Oct 18 09:38:03 2022 +0200 tree-optimization/107301 - check if we can duplicate block before doing so Path isolation failed to do that. 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. Diff: --- gcc/gimple-ssa-isolate-paths.cc | 6 ++++-- gcc/testsuite/gcc.dg/torture/pr107301.c | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) 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; +}