From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 3B2053858D37; Wed, 1 Feb 2023 11:53:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3B2053858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675252416; bh=siNCs59dSlH4FUPeZtcjuTvN3fkssHuzg2F39i7SQz0=; h=From:To:Subject:Date:From; b=xEjY3x33tCbCPAfqo2uPYWoO7AMOgKhNP4e9/jPCgxsEOjXLTon1atp7pWOTvpASj 5p96UOw7CE6wK0MdAJroihji6QJw1FpiKwzNGFTK+rE33+hCE9TFG38EXxMntDnqmu 3Y37Apod1Y4FGFlQDdYaQ6U4MLFSjLz8cd0rHxZE= 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 r13-5625] ree: Fix -fcompare-debug issues in combine_reaching_defs [PR108573] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: eda38850a7980d78d966a39b58961349bea7c984 X-Git-Newrev: e4473d7cf871c8ddf8f22d105c5af6375ebe37bf Message-Id: <20230201115336.3B2053858D37@sourceware.org> Date: Wed, 1 Feb 2023 11:53:36 +0000 (GMT) List-Id: https://gcc.gnu.org/g:e4473d7cf871c8ddf8f22d105c5af6375ebe37bf commit r13-5625-ge4473d7cf871c8ddf8f22d105c5af6375ebe37bf Author: Jakub Jelinek Date: Wed Feb 1 12:52:52 2023 +0100 ree: Fix -fcompare-debug issues in combine_reaching_defs [PR108573] The PR78437 r7-4871 changes made combine_reaching_defs punt on WORD_REGISTER_OPERATIONS targets if a setter of smaller than word register has wider uses. This unfortunately breaks -fcompare-debug, because if such a use appears only in DEBUG_INSN(s), while all other uses aren't wider than the setter, we can REE optimize it without -g and not with -g. Such decisions shouldn't be based on debug instructions. We could try to reset them or adjust in some other way after we decide to perform the change, but at least on the testcase which used to fail on riscv64-linux the (debug_insn 8 7 9 2 (var_location:HI s (minus:HI (subreg:HI (and:DI (reg:DI 10 a0 [160]) (const_int 1 [0x1])) 0) (subreg:HI (ashiftrt:DI (reg/v:DI 9 s1 [orig:151 l ] [151]) (debug_expr:SI D#1)) 0))) "pr108573.c":12:5 -1 (nil)) clearly doesn't care about the upper bits and I have hard time imaging how could one end up with DEBUG_INSN which actually cares about those upper bits. So, the following patch just ignores uses on DEBUG_INSNs in this case, if we run into something where we'd need to do something further later on, let's deal with it when we have a testcase for it. 2023-02-01 Jakub Jelinek PR debug/108573 * ree.cc (combine_reaching_defs): Don't return false for paradoxical subregs in DEBUG_INSNs. * gcc.dg/pr108573.c: New test. Diff: --- gcc/ree.cc | 6 ++++-- gcc/testsuite/gcc.dg/pr108573.c | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/gcc/ree.cc b/gcc/ree.cc index 98bd80efd7b..413aec7c8eb 100644 --- a/gcc/ree.cc +++ b/gcc/ree.cc @@ -875,7 +875,8 @@ combine_reaching_defs (ext_cand *cand, const_rtx set_pat, ext_state *state) for (df_link *use = uses; use; use = use->next) if (paradoxical_subreg_p (GET_MODE (*DF_REF_LOC (use->ref)), - GET_MODE (SET_DEST (*dest_sub_rtx)))) + GET_MODE (SET_DEST (*dest_sub_rtx))) + && !DEBUG_INSN_P (DF_REF_INSN (use->ref))) return false; } @@ -963,7 +964,8 @@ combine_reaching_defs (ext_cand *cand, const_rtx set_pat, ext_state *state) rtx dest2 = SET_DEST (*dest_sub_rtx2); for (use = uses; use; use = use->next) if (paradoxical_subreg_p (GET_MODE (*DF_REF_LOC (use->ref)), - GET_MODE (dest2))) + GET_MODE (dest2)) + && !DEBUG_INSN_P (DF_REF_INSN (use->ref))) break; if (use) break; diff --git a/gcc/testsuite/gcc.dg/pr108573.c b/gcc/testsuite/gcc.dg/pr108573.c new file mode 100644 index 00000000000..5dd18043b2b --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr108573.c @@ -0,0 +1,18 @@ +/* PR debug/108573 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fcompare-debug" } */ + +unsigned g; + +int bar (void); +int baz (int); + +void +foo (unsigned short s, long l) +{ + unsigned u = bar (); + s &= __builtin_add_overflow_p (0, u, 0); + s %= g; + s -= l >> s; + baz (s); +}