From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B7FF03858C5F; Sun, 24 Dec 2023 13:53:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B7FF03858C5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1703425990; bh=027f1qXVEGyqgcBmHJkf/k1Rr4M2iY87pNXdLrH5KaM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Fpt98muBZADHmu8ltokv/8eJpfVaUxJ5k9Q1onDbYiIvot3DTrdvYmgJpSnxsk6A/ TG8TldJsdpUtuDd/yhILmSjqEGq8/2gCOPfYOhFcq4nsxL31KYMrz3JyJowDa56anx BqdH8ATaa/Y8eoAOTiwPHCnU+BoZj4hibEQSZufU= From: "roger at nextmovesoftware dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/104914] [MIPS] wrong comparison with scrabbled int value Date: Sun, 24 Dec 2023 13:53:08 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: roger at nextmovesoftware dot com X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104914 --- Comment #17 from Roger Sayle --- I think this patch might resolve the problem (or move it somewhere else): diff --git a/gcc/expr.cc b/gcc/expr.cc index 9fef2bf6585..218bca905f5 100644 --- a/gcc/expr.cc +++ b/gcc/expr.cc @@ -6274,10 +6274,7 @@ expand_assignment (tree to, tree from, bool nontempo= ral) result =3D store_expr (from, to_rtx, 0, nontemporal, false); else { - rtx to_rtx1 - =3D lowpart_subreg (subreg_unpromoted_mode (to_rtx), - SUBREG_REG (to_rtx), - subreg_promoted_mode (to_rtx)); + rtx to_rtx1 =3D gen_reg_rtx (subreg_unpromoted_mode (to_r= tx)); result =3D store_field (to_rtx1, bitsize, bitpos, bitregion_start, bitregion_end, mode1, from, get_alias_set (to), The motivation/solution comes from a comment in expmed.cc: /* If the destination is a paradoxical subreg such that we need a truncate to the inner mode, perform the insertion on a temporary and truncate the result to the original destination. Note that we can't just truncate the paradoxical subreg as (truncate:N (subreg:W (reg:N X) 0)) is (reg:N X). */ The same caveat applies to extensions on MIPS, so we should use a new pseudo temporary register rather than update the SUBREG in place. If someone could confirm this fixes the issue on MIPS, I'll try to come up with a milder form of this fix that checks TARGET_MODE_REP_EXTENDED that'll limit the churn/impact on other targets.=