From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7395138493EC; Fri, 17 Feb 2023 11:40:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7395138493EC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676634019; bh=wNTiH1AT2LC+3TnKFKdYMqaC0hafLfyPTsfq46Vkys4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=KXTJXSanK1TXtbjR9XjgPWba8quMHLih6VztBOtWNazIhVQdEkN1g/mtYp8PGZck0 hHRhe0IHA0y4Sv9ZD2ZUyLtd3HtJpVsiMc9duSDu6+F/dKAL+v7H/q0VAZaWL1GcPK FJaXqh3IqF5C3BNhoz+FGwZksI70a4YyRZSpjUbU= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/108832] [13 Regression] ICE in replace_rtx, at rtlanal.cc:3358 Date: Fri, 17 Feb 2023 11:40:18 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: ice-on-valid-code X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED 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: cc 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=3D108832 Jakub Jelinek changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org, | |uros at gcc dot gnu.org --- Comment #1 from Jakub Jelinek --- So, this is on (insn 263 304 17 2 (set (reg:DI 2 cx [98]) (reg:DI 1 dx [98])) "pr108832.c":15:9 discrim 1 82 {*movdi_internal} (expr_list:REG_DEAD (reg:DI 1 dx [98]) (nil))) (insn 17 263 261 2 (parallel [ (set (reg:CCZ 17 flags) (compare:CCZ (and:SI (reg:SI 2 cx [98]) (const_int -2 [0xfffffffffffffffe])) (const_int 0 [0]))) (set (reg:DI 2 cx) (zero_extend:DI (and:SI (reg:SI 2 cx [98]) (const_int -2 [0xfffffffffffffffe])))) ]) "pr108832.c":16:11 565 {*andsi_2_zext} (nil)) (insn 261 17 259 2 (set (reg:DI 0 ax) (const_int 1 [0x1])) 82 {*movdi_internal} (expr_list:REG_EQUIV (const_int 1 [0x1]) (nil))) (insn 259 261 4 2 (set (reg:DI 2 cx) (if_then_else:DI (ne (reg:CCZ 17 flags) (const_int 0 [0])) (reg:DI 2 cx) (reg:DI 0 ax))) 1304 {*movdicc_noc} (expr_list:REG_DEAD (reg:CCZ 17 flags) (expr_list:REG_DEAD (reg:DI 0 ax) (nil)))) on which ;; Eliminate a reg-reg mov by inverting the condition of a cmov (#1). ;; mov r0,r1; dec r0; mov r2,r3; cmov r0,r2 -> dec r1; mov r0,r3; cmov r0, = r1 (define_peephole2 [(set (match_operand:SWI248 0 "general_reg_operand") (match_operand:SWI248 1 "general_reg_operand")) (parallel [(set (reg FLAGS_REG) (match_operand 5)) (set (match_dup 0) (match_operand:SWI248 6))]) (set (match_operand:SWI248 2 "general_reg_operand") (match_operand:SWI248 3 "general_gr_operand")) (set (match_dup 0) (if_then_else:SWI248 (match_operator 4 "ix86_comparison_operator" [(reg FLAGS_REG) (const_int 0)]) (match_dup 0) (match_dup 2)))] "TARGET_CMOVE && REGNO (operands[2]) !=3D REGNO (operands[0]) && REGNO (operands[2]) !=3D REGNO (operands[1]) && peep2_reg_dead_p (1, operands[1]) && peep2_reg_dead_p (4, operands[2]) && !reg_overlap_mentioned_p (operands[0], operands[3])" [(parallel [(set (match_dup 7) (match_dup 8)) (set (match_dup 1) (match_dup 9))]) (set (match_dup 0) (match_dup 3)) (set (match_dup 0) (if_then_else:SWI248 (match_dup 4) (match_dup 1) (match_dup 0)))] { operands[7] =3D SET_DEST (XVECEXP (PATTERN (peep2_next_insn (1)), 0, 0)); operands[8] =3D replace_rtx (operands[5], operands[0], operands[1], true); operands[9] =3D replace_rtx (operands[6], operands[0], operands[1], true); }) applies. replace_rtx has 2 modes, !all_regs in which it replaces just x = =3D=3D from with to and all_regs, in which case it does: if (all_regs && REG_P (x) && REG_P (from) && REGNO (x) =3D=3D REGNO (from)) { gcc_assert (GET_MODE (x) =3D=3D GET_MODE (from)); return to; } and so ICEs if we see the same REGNO as from in a different mode. I think we actually don't need most of what replace_rtx is doing, we don't = need to simplify anything etc. because we are just changing one register to anot= her and can do it in place. So, I think we need a different function for what the backend wants. It can avoid all the simplify stuff because replace_rtx was destructive, so could be implemented say using FOR_EACH_SUBRTX_PTR. When seeing *loc =3D= =3D from, it obviously should set *loc =3D to, if it sees REG_P (*loc) && REGNO (*loc) =3D=3D REGN= O (from), then if the mode is the same, it can also just *loc =3D to, but if it is a diffe= rent mode, I'd say for narrower mode it should *loc =3D gen_rtx_REG (GET_MODE (*loc), = REGNO (to)); and for wider mode (especially if say a multi-register reg) punt. Not sure if such a case can occur though, but the punting would be hard if = we have made some changes already...=