From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 042FB3858C53; Thu, 22 Jun 2023 11:09:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 042FB3858C53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687432187; bh=EQw4CjR3i8tHzKdTcA2PvKutDjx53REvHzcf6LaQ+6w=; h=From:To:Subject:Date:In-Reply-To:References:From; b=OIBrHKRNbtV37Osbe0swWrtjHCTfFDcxt0ZvgbOf3re+EfT66X+ccfhmpsIRZc9fW mDQtUHdNTS28nxGCZHJmKVHOaTtxmIt6jFdUzLMjfuLYbzFStiWYq3NXPPN9dMe7tT 1uQP5Xp0azCQjBLLxLH8tSRpTArir/48Rdh8VbvQ= From: "klepikov.alex+bugs at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/54089] [SH] Refactor shift patterns Date: Thu, 22 Jun 2023 11:09:44 +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: 4.8.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: klepikov.alex+bugs at gmail dot com X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: olegendo 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=3D54089 --- Comment #89 from Alexander Klepikov --- Here's what I did sh.md: (define_expand "ashrsi3" [(parallel [(set (match_operand:SI 0 "arith_reg_dest" "") (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "") (match_operand:SI 2 "nonmemory_operand" "")= )) (clobber (reg:SI T_REG))])] "" { if (expand_ashiftrt (operands)) DONE; if (!CONST_INT_P (operands[2])) FAIL; int value =3D INTVAL (operands[2]) & 31; emit_insn (gen_ashrsi3_n_call (operands[0], operands[1], GEN_INT(value))); DONE; }) (define_insn_and_split "ashrsi3_n_call" [(set (match_operand:SI 0 "arith_reg_dest" "=3Dr") (ashiftrt:SI (match_operand:SI 1 "arith_reg_operand" "0") (match_operand:SI 2 "const_int_operand"))) (clobber (reg:SI T_REG))] "TARGET_SH1" "#" "&& can_create_pseudo_p ()" [(const_int 0)] { char func[18]; int value; rtx wrk; cfun->machine->ashrsi3_libcall_expanded++; if (expand_ashiftrt (operands)) DONE; if (!CONST_INT_P (operands[2])) FAIL; value =3D INTVAL (operands[2]) & 31; if (dump_file) fprintf(dump_file, "ashrsi3_n_call: Expanding ashrsi3 libcall\n"); wrk =3D gen_reg_rtx (Pmode); /* Load the value into an arg reg and call a helper. */ emit_move_insn (gen_rtx_REG (SImode, 4), operands[1]); sprintf (func, "__ashiftrt_r4_%d", value); rtx lab =3D function_symbol (wrk, func, SFUNC_STATIC).lab; emit_insn (gen_ashrsi3_n (GEN_INT (value), wrk, lab)); emit_move_insn (operands[0], gen_rtx_REG (SImode, 4)); DONE; }) sh.cc: bool expand_ashiftrt (rtx *operands) { rtx wrk; int value; if (TARGET_DYNSHIFT) { if (!CONST_INT_P (operands[2])) { rtx count =3D copy_to_mode_reg (SImode, operands[2]); emit_insn (gen_negsi2 (count, count)); emit_insn (gen_ashrsi3_d (operands[0], operands[1], count)); return true; } else if (ashiftrt_insns[INTVAL (operands[2]) & 31] > 1 + SH_DYNAMIC_SHIFT_COST) { rtx count =3D force_reg (SImode, GEN_INT (- (INTVAL (operands[2]) & 31))); emit_insn (gen_ashrsi3_d (operands[0], operands[1], count)); return true; } } if (!CONST_INT_P (operands[2])) return false; value =3D INTVAL (operands[2]) & 31; if (value =3D=3D 31) { /* If we are called from abs expansion, arrange things so that we we can use a single MT instruction that doesn't clobber the source, if LICM can hoist out the load of the constant zero. */ if (currently_expanding_to_rtl) { emit_insn (gen_cmpgtsi_t (force_reg (SImode, CONST0_RTX (SImode)), operands[1])); emit_insn (gen_mov_neg_si_t (operands[0], get_t_reg_rtx ())); return true; } emit_insn (gen_ashrsi2_31 (operands[0], operands[1])); return true; } else if (value >=3D 16 && value <=3D 19) { wrk =3D gen_reg_rtx (SImode); emit_insn (gen_ashrsi2_16 (wrk, operands[1])); value -=3D 16; while (value--) gen_ashift (ASHIFTRT, 1, wrk); emit_move_insn (operands[0], wrk); return true; } /* Expand a short sequence inline, longer call a magic routine. */ else if (value <=3D 5) { wrk =3D gen_reg_rtx (SImode); emit_move_insn (wrk, operands[1]); while (value--) gen_ashift (ASHIFTRT, 1, wrk); emit_move_insn (operands[0], wrk); return true; } return false; } Now GCC falls into infinite loop when compiling this: int f_short_rshift_signed(char v){ return v >> 5; } It looks like it splits and then combines again.=