From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id E42503858412; Mon, 24 Jan 2022 09:20:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E42503858412 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-9491] optabs: Fix up checking for CALLs in newly added code by double-word divmod [PR103838] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: c239267759be2cf3e1afadea86aff5ba3517d934 X-Git-Newrev: 2712f1249e0a8dd663a02bdf710a455fe5b14e3f Message-Id: <20220124092030.E42503858412@sourceware.org> Date: Mon, 24 Jan 2022 09:20:30 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Jan 2022 09:20:31 -0000 https://gcc.gnu.org/g:2712f1249e0a8dd663a02bdf710a455fe5b14e3f commit r11-9491-g2712f1249e0a8dd663a02bdf710a455fe5b14e3f Author: Jakub Jelinek Date: Tue Dec 28 17:39:23 2021 +0100 optabs: Fix up checking for CALLs in newly added code by double-word divmod [PR103838] These two spots are meant to punt if the newly added code contains any CALL_INSNs, because in that case having a large sequence of insns that also calls something is undesirable, better have one call that is optimized in itself well. The functions do last = get_last_insn (); before emitting any insns (and expand_binop as the ultimate caller uses delete_insns_since if the expansion fails), but the checks were incorrect for 2 reasons: 1) it checked not just what follows after that last insn, but also the last insn itself; so, if the division or modulo is immediately preceded by a CALL_INSN, then we punt; this also causes -fcompare-debug failures if the CALL_INSN is with -g followed by one or more DEBUG_INSNs 2) if get_last_insn () is NULL (i.e. emitting into a new sequence), then we didn't check anything 2021-12-28 Jakub Jelinek PR debug/103838 * optabs.c (expand_doubleword_mod, expand_doubleword_divmod): Only check newly added insns for CALL_P, not the last insn of previous code. * gcc.dg/pr103838.c: New test. (cherry picked from commit 78ee8381bf0ebd09a92936bdb9e1b5c9fc85ad88) Diff: --- gcc/optabs.c | 8 ++++++++ gcc/testsuite/gcc.dg/pr103838.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/gcc/optabs.c b/gcc/optabs.c index f4614a39458..e55c1785b4e 100644 --- a/gcc/optabs.c +++ b/gcc/optabs.c @@ -1113,6 +1113,10 @@ expand_doubleword_mod (machine_mode mode, rtx op0, rtx op1, bool unsignedp) remainder = convert_modes (mode, word_mode, remainder, unsignedp); /* Punt if we need any library calls. */ + if (last) + last = NEXT_INSN (last); + else + last = get_insns (); for (; last; last = NEXT_INSN (last)) if (CALL_P (last)) return NULL_RTX; @@ -1206,6 +1210,10 @@ expand_doubleword_divmod (machine_mode mode, rtx op0, rtx op1, rtx *rem, } /* Punt if we need any library calls. */ + if (last) + last = NEXT_INSN (last); + else + last = get_insns (); for (; last; last = NEXT_INSN (last)) if (CALL_P (last)) return NULL_RTX; diff --git a/gcc/testsuite/gcc.dg/pr103838.c b/gcc/testsuite/gcc.dg/pr103838.c new file mode 100644 index 00000000000..cde44e6e4e3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr103838.c @@ -0,0 +1,28 @@ +/* PR debug/103838 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fcompare-debug" } */ + +#ifdef __SIZEOF_INT128__ +__int128 m; +#else +long long m; +#endif +int n; + +__attribute__((noinline)) void +bar (void) +{ + n += !!m; +} + +void +foo (void) +{ + int i; + + for (i = 0; i < 2; ++i) + { + bar (); + m /= 3; + } +}