From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id D88A43858C1F for ; Thu, 15 Jun 2023 09:03:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D88A43858C1F Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1686819789; bh=zlSimaLRWMyjV2lkkTpMihyNkU89xTwnzMlbrY5GbZE=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=GYN49VW7n0hqcz0/xe+TTX6s8BBUU3lJ6flaQw+wk1olPFEfArxLoqPUHjpRDwbRh GkchBudodlwrbxWS2QdYstfdjbm9H+SCFoY0ml2056nArOTtpSmYvOQp2J+S/uOIkZ cAm5PxpSSH//u9/8DEEQb/aCNqCCNC8kuh+7UmoU= Received: from localhost.localdomain (xry111.site [IPv6:2001:470:683e::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 0583865A95; Thu, 15 Jun 2023 05:03:07 -0400 (EDT) Message-ID: Subject: Re: [pushed][PATCH v3] LoongArch: Avoid non-returning indirect jumps through $ra [PR110136] From: Xi Ruoyao To: i@xen0n.name Cc: xuchenghua@loongson.cn, Andrew Pinski , Lulu Cheng , gcc-patches@gcc.gnu.org Date: Thu, 15 Jun 2023 17:03:06 +0800 In-Reply-To: References: <20230615013033.505823-1-chenglulu@loongson.cn> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.3 MIME-Version: 1.0 X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,LIKELY_SPAM_FROM,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Xuerui: I guess this makes it sensible to show "ret" instead of "jirl $zero, $ra, 0" in objdump -d output, but I don't know how to implement it. Do you have some idea? On Thu, 2023-06-15 at 16:27 +0800, Lulu Cheng wrote: > Pushed to trunk and gcc-12 gcc-13. > r14-1866 > r13-7448 > r12-9698 >=20 > =E5=9C=A8 2023/6/15 =E4=B8=8A=E5=8D=889:30, Lulu Cheng =E5=86=99=E9=81=93= : > > Micro-architecture unconditionally treats a "jr $ra" as "return from > > subroutine", > > hence doing "jr $ra" would interfere with both subroutine return > > prediction and > > the more general indirect branch prediction. > >=20 > > Therefore, a problem like PR110136 can cause a significant increase > > in branch error > > prediction rate and affect performance. The same problem exists with > > "indirect_jump". > >=20 > > gcc/ChangeLog: > >=20 > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* config/loongarch/loon= garch.md: Modify the register > > constraints for template > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0"jumptable" and "indire= ct_jump" from "r" to "e". > >=20 > > Co-authored-by: Andrew Pinski > > --- > > v1 -> v2: > > =C2=A0=C2=A0 1. Modify the description. > > =C2=A0=C2=A0 2. Modify the register constraints of the template > > "indirect_jump". > > v2 -> v3: > > =C2=A0=C2=A0 1. Modify the description. > > --- > > =C2=A0 gcc/config/loongarch/loongarch.md | 8 ++++++-- > > =C2=A0 1 file changed, 6 insertions(+), 2 deletions(-) > >=20 > > diff --git a/gcc/config/loongarch/loongarch.md > > b/gcc/config/loongarch/loongarch.md > > index 816a943d155..b37e070660f 100644 > > --- a/gcc/config/loongarch/loongarch.md > > +++ b/gcc/config/loongarch/loongarch.md > > @@ -2895,6 +2895,10 @@ (define_insn "*jump_pic" > > =C2=A0 } > > =C2=A0=C2=A0=C2=A0 [(set_attr "type" "branch")]) > > =C2=A0=20 > > +;; Micro-architecture unconditionally treats a "jr $ra" as "return > > from subroutine", > > +;; non-returning indirect jumps through $ra would interfere with > > both subroutine > > +;; return prediction and the more general indirect branch > > prediction. > > + > > =C2=A0 (define_expand "indirect_jump" > > =C2=A0=C2=A0=C2=A0 [(set (pc) (match_operand 0 "register_operand"))] > > =C2=A0=C2=A0=C2=A0 "" > > @@ -2905,7 +2909,7 @@ (define_expand "indirect_jump" > > =C2=A0 }) > > =C2=A0=20 > > =C2=A0 (define_insn "@indirect_jump" > > -=C2=A0 [(set (pc) (match_operand:P 0 "register_operand" "r"))] > > +=C2=A0 [(set (pc) (match_operand:P 0 "register_operand" "e"))] > > =C2=A0=C2=A0=C2=A0 "" > > =C2=A0=C2=A0=C2=A0 "jr\t%0" > > =C2=A0=C2=A0=C2=A0 [(set_attr "type" "jump") > > @@ -2928,7 +2932,7 @@ (define_expand "tablejump" > > =C2=A0=20 > > =C2=A0 (define_insn "@tablejump" > > =C2=A0=C2=A0=C2=A0 [(set (pc) > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0(match_operand:P 0 "register= _operand" "r")) > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0(match_operand:P 0 "register= _operand" "e")) > > =C2=A0=C2=A0=C2=A0=C2=A0 (use (label_ref (match_operand 1 "" "")))] > > =C2=A0=C2=A0=C2=A0 "" > > =C2=A0=C2=A0=C2=A0 "jr\t%0" >=20 --=20 Xi Ruoyao School of Aerospace Science and Technology, Xidian University