From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 255423919BD2; Wed, 5 Jun 2024 16:56:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 255423919BD2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1717606584; bh=jcW89bm0Wow4C+1lR382hvnlHpstLkYN406q5Spbsbs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=uJYYQFTHFlxUfbQvi+lAZHZzyA0wCeXrKqRaKIUbP0pnk5qsVAiYkZdmSh30Sw8+n Tfqf+TD/0/3rPzn+8/NcYbrJDw4F8P2MgsSgLDBN67HnZT2WccZL0KmWu9KHtFz+Yc HbRdeS1C2zFoD8IIxTuGybp1UjeULe19ksRTO6O0= From: "syq at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/111376] missed optimization of one bit test on MIPS32r1 Date: Wed, 05 Jun 2024 16:56:23 +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: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: syq at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: syq 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=3D111376 --- Comment #5 from YunQiang Su --- I copy the RTL pattern from RISC-V, and it seems work ``` --- a/gcc/config/mips/mips.md +++ b/gcc/config/mips/mips.md @@ -6253,6 +6253,40 @@ (define_insn "*branch_bit_inverted" } [(set_attr "type" "branch") (set_attr "branch_likely" "no")]) + +(define_insn_and_split "*branch_on_bit" + [(set (pc) + (if_then_else + (match_operator 0 "equality_operator" + [(zero_extract:GPR (match_operand:GPR 2 "register_operand" = "d") + (const_int 1) + (match_operand:GPR 3 "const_int_operand")) + (const_int 0)]) + (label_ref (match_operand 1)) + (pc)))] + "!ISA_HAS_BBIT && !ISA_HAS_EXT_INS && !TARGET_MIPS16" + "#" + "!reload_completed" + [(set (match_dup 4) + (ashift:GPR (match_dup 2) (match_dup 3))) + (set (pc) + (if_then_else + (match_op_dup 0 [(match_dup 4) (const_int 0)]) + (label_ref (match_operand 1)) + (pc)))] +{ + int shift =3D GET_MODE_BITSIZE (mode) - 1 - INTVAL (operands[3]); + operands[3] =3D GEN_INT (shift); + operands[4] =3D gen_reg_rtx (mode); + + if (GET_CODE (operands[0]) =3D=3D EQ) + operands[0] =3D gen_rtx_GE (mode, operands[4], const0_rtx); + else + operands[0] =3D gen_rtx_LT (mode, operands[4], const0_rtx); +} +[(set_attr "type" "branch")]) + + ```=