From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id F14B7382C151; Fri, 28 Oct 2022 13:07:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F14B7382C151 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666962445; bh=QD9T5fwVoRdtI9RQNPmKrmpLWwC/iB0s9kte5s21Nmo=; h=From:To:Subject:Date:From; b=GJZh59E0rJ7/J6Y5XGbERYaDO3nFGpIN11pgJm3DSz4KiWZHo7Q4BAOMgm6CKC0ZR sBrDA7PB2vjlEKWfrOQD6g0ZFvzj9qsZ0rccmwrGDMm7jgtiEn8xQpfXdYmjXhEbqJ KtAL0tzBJXrqTcDIMGBf/nW8iA34P0dEnYgnrokI= 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-3545] tree-optimization/107447 - avoid hoisting returns-twice calls in LIM X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: 084128583212bd64308f50c2ab5f4c03be40e48c X-Git-Newrev: 1add3635563b39e3c0e9bed4930d11b3f605fdd3 Message-Id: <20221028130725.F14B7382C151@sourceware.org> Date: Fri, 28 Oct 2022 13:07:25 +0000 (GMT) List-Id: https://gcc.gnu.org/g:1add3635563b39e3c0e9bed4930d11b3f605fdd3 commit r13-3545-g1add3635563b39e3c0e9bed4930d11b3f605fdd3 Author: Richard Biener Date: Fri Oct 28 14:20:36 2022 +0200 tree-optimization/107447 - avoid hoisting returns-twice calls in LIM The following makes sure to not hoist returns-twice calls in LIM since we have no way to move the abnormal edge associated with it and we are prone having stray abnormal edges in the IL which will then cause IL verification failures even when the actual call does not return twice. PR tree-optimization/107447 * tree-ssa-loop-im.cc (determine_max_movement): Do not hoist returns-twice calls. * gcc.dg/torture/pr107447.c: New testcase. Diff: --- gcc/testsuite/gcc.dg/torture/pr107447.c | 23 +++++++++++++++++++++++ gcc/tree-ssa-loop-im.cc | 13 +++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/gcc/testsuite/gcc.dg/torture/pr107447.c b/gcc/testsuite/gcc.dg/torture/pr107447.c new file mode 100644 index 00000000000..06f7b7b15ae --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr107447.c @@ -0,0 +1,23 @@ +/* { dg-do compile } */ + +int n; + +void +bar (int, int); + +__attribute__ ((noinline, returns_twice)) int +zero (void) +{ + return 0; +} + +void +foo (void) +{ + (void) zero (); + + n = 0; + + for (;;) + bar (zero (), n); +} diff --git a/gcc/tree-ssa-loop-im.cc b/gcc/tree-ssa-loop-im.cc index 2ea815050d1..2119d4072d3 100644 --- a/gcc/tree-ssa-loop-im.cc +++ b/gcc/tree-ssa-loop-im.cc @@ -835,10 +835,15 @@ determine_max_movement (gimple *stmt, bool must_preserve_exec) return true; } - else - FOR_EACH_SSA_TREE_OPERAND (val, stmt, iter, SSA_OP_USE) - if (!add_dependency (val, lim_data, loop, true)) - return false; + + /* A stmt that receives abnormal edges cannot be hoisted. */ + if (is_a (stmt) + && (gimple_call_flags (stmt) & ECF_RETURNS_TWICE)) + return false; + + FOR_EACH_SSA_TREE_OPERAND (val, stmt, iter, SSA_OP_USE) + if (!add_dependency (val, lim_data, loop, true)) + return false; if (gimple_vuse (stmt)) {