From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 1718C38425B2; Tue, 10 May 2022 08:23:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1718C38425B2 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 r10-10670] optabs: Don't create pseudos in prepare_cmp_insn when not allowed [PR102478] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: 03bd2b252bca8c0ba4aeecab8b560d751f2ef57d X-Git-Newrev: 42d66df40b5a12e1b7e77f0901ee8a6710cabd5f Message-Id: <20220510082305.1718C38425B2@sourceware.org> Date: Tue, 10 May 2022 08:23:05 +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: Tue, 10 May 2022 08:23:05 -0000 https://gcc.gnu.org/g:42d66df40b5a12e1b7e77f0901ee8a6710cabd5f commit r10-10670-g42d66df40b5a12e1b7e77f0901ee8a6710cabd5f Author: Jakub Jelinek Date: Fri Jan 21 11:16:50 2022 +0100 optabs: Don't create pseudos in prepare_cmp_insn when not allowed [PR102478] cond traps can be created during ce3 after reload (and e.g. PR103028 recently fixed some ce3 cond trap related bug, so I think often that works fine and we shouldn't disable cond traps after RA altogether), but it calls prepare_cmp_insn. This function can fail, so I don't see why we couldn't make it work after RA (in most cases it already just works). The first hunk is just an optimization which doesn't make sense after RA, so I've guarded it with can_create_pseudo_p. The second hunk is just a theoretical case, I don't have a testcase for it. prepare_cmp_insn has some other spots that can create pseudos, like when both operands have VOIDmode, or when it is BLKmode comparison, or not OPTAB_DIRECT, but I think none of that applies to ce3, we punt on BLKmode earlier, use OPTAB_DIRECT and shouldn't be comparing two VOIDmode CONST_INTs. 2022-01-21 Jakub Jelinek PR rtl-optimization/102478 * optabs.c (prepare_cmp_insn): If !can_create_pseudo_p (), don't force_reg constants and for -fnon-call-exceptions fail if copy_to_reg would be needed. * gcc.dg/pr102478.c: New test. (cherry picked from commit c2d9159717b474f9c06dde4d32b48b87164deb50) Diff: --- gcc/optabs.c | 8 ++++++-- gcc/testsuite/gcc.dg/pr102478.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/gcc/optabs.c b/gcc/optabs.c index 049a18ceb7c..64f23d2c293 100644 --- a/gcc/optabs.c +++ b/gcc/optabs.c @@ -3891,12 +3891,14 @@ prepare_cmp_insn (rtx x, rtx y, enum rtx_code comparison, rtx size, /* If we are optimizing, force expensive constants into a register. */ if (CONSTANT_P (x) && optimize && (rtx_cost (x, mode, COMPARE, 0, optimize_insn_for_speed_p ()) - > COSTS_N_INSNS (1))) + > COSTS_N_INSNS (1)) + && can_create_pseudo_p ()) x = force_reg (mode, x); if (CONSTANT_P (y) && optimize && (rtx_cost (y, mode, COMPARE, 1, optimize_insn_for_speed_p ()) - > COSTS_N_INSNS (1))) + > COSTS_N_INSNS (1)) + && can_create_pseudo_p ()) y = force_reg (mode, y); #if HAVE_cc0 @@ -3972,6 +3974,8 @@ prepare_cmp_insn (rtx x, rtx y, enum rtx_code comparison, rtx size, compare and branch in different basic blocks. */ if (cfun->can_throw_non_call_exceptions) { + if (!can_create_pseudo_p () && (may_trap_p (x) || may_trap_p (y))) + goto fail; if (may_trap_p (x)) x = copy_to_reg (x); if (may_trap_p (y)) diff --git a/gcc/testsuite/gcc.dg/pr102478.c b/gcc/testsuite/gcc.dg/pr102478.c new file mode 100644 index 00000000000..43bc49b584d --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr102478.c @@ -0,0 +1,29 @@ +/* PR rtl-optimization/102478 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-if-conversion -Wno-div-by-zero" } */ + +unsigned a, b, c; + +void +foo (void) +{ + c |= __builtin_expect (65535 / a, 0) && 0 / 0; + b = 0; +} + +void +bar (void) +{ + if (a <= 65535) + __builtin_trap (); + b = 0; +} + +void +baz (void) +{ + if (a > 65535) + b = 0; + else + __builtin_trap (); +}