<div dir="ltr"><div>You are right, x1 is not redefined by `PseudoBRIND`. There was recently a fix for this in the RISC-V backend: <a href="https://github.com/llvm/llvm-project/commit/9e6c09c0d995721eff6366d9af2f8ab1c203bf61">https://github.com/llvm/llvm-project/commit/9e6c09c0d995721eff6366d9af2f8ab1c203bf61</a></div><div><br></div><div>Sam</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Dec 12, 2020 at 10:53 PM Cristian Cobzarenco via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div>The RISCV target defines a pseudo instruction for `brind` as shown below (RISCVInstrInfo.td):<br></div></div><div><br></div><div>let isCall = 1, Defs=[X1] in<br>let isBarrier = 1, isBranch = 1, isIndirectBranch = 1, isTerminator = 1 in<br>def PseudoBRIND : Pseudo<(outs), (ins GPR:$rs1, simm12:$imm12), []>,<br>                  PseudoInstExpansion<(JALR X0, GPR:$rs1, simm12:$imm12)>;<br></div><div><br></div><div>def : Pat<(brind GPR:$rs1), (PseudoBRIND GPR:$rs1, 0)>;<br>def : Pat<(brind (add GPR:$rs1, simm12:$imm12)),<br>          (PseudoBRIND GPR:$rs1, simm12:$imm12)>;<br></div><div><br></div><div>Note the `Defs=[X1]` (the return address register) in the definition despite it not actually being used in the expansion. This results in code being generated to save the link register before performing an indirect jump (llvm/test/CodeGen/RISCV/indirectbr.ll):</div><div><br></div><div>define i32 @indirectbr(i8* %target) nounwind {<br>; RV32I-LABEL: indirectbr:<br>; RV32I:       # %bb.0:<br>; RV32I-NEXT:    addi sp, sp, -16<br>; RV32I-NEXT:    sw ra, 12(sp)<br>; RV32I-NEXT:    jr a0<br>; RV32I-NEXT:  .LBB0_1: # %test_label<br>; RV32I-NEXT:    mv a0, zero<br>; RV32I-NEXT:    lw ra, 12(sp)<br>; RV32I-NEXT:    addi sp, sp, 16<br>; RV32I-NEXT:    ret<br>  indirectbr i8* %target, [label %test_label]<br>test_label:<br>  br label %ret<br>ret:<br>  ret i32 0<br>}<br></div><div><br></div><div>This seems unnecessary to me, as `brind` is not a call, right? Or are the semantics of `brind` more complicated than I understand it to be? As far as I can tell ARM doesn't do this, but I can't follow ARMInstrInfo.td as well, so I'm not sure. Should I replicate this in my target? Or should I send a patch to fix this in the RISCV target?<br></div><div><br></div><div>Would appreciate any help in the matter.</div><div><br></div><div>Thanks,</div><div>Cristi.<br></div></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr">Sam Elliott</div><div dir="ltr">Software Team Lead<br>Senior Software Developer - LLVM and OpenTitan<br>lowRISC CIC<br></div></div></div></div>