<div dir="ltr">RISC-V does this kind of thing, and the (new) LLVM back end has been written to (hopefully!) be an example of best practice, so it should be a good one to copy. The first (AUIPC) instruction adds the top 20 bits of a 32 bit offset to the current PC and puts the result into a temporary register. The branch instruction then adds a 12 bit offset to the temporary register.<div><br></div><div>The compiler *always* generates code this way. It's the linker's job to detect when the AUIPC isn't necessary and delete it and convert the branch to 12 bit PC-relative instead of register relative. You can turn this off (in gnu ld) if you want faster links and don't care about the occasional extra instruction.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 2, 2018 at 2:48 PM, David Chisnall via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 2 Mar 2018, at 11:45, Nagaraju Mekala <<a href="mailto:nagaraju.mekala87@gmail.com">nagaraju.mekala87@gmail.com</a>> wrote:<br>
><br>
> yes they are dependent if the branch immediate value is > 0xffff then<br>
> the imm instruction should generate other wise only "br" instruction<br>
> is enough.<br>
<br>
</span>This sounds as if you have two br instructions, one that takes an immediate and one that takes a register and requires that another instruction materialise the address in a register.  This is common to most targets - you will find lots of examples in the code - but the high-level picture is to describe both variants in TableGen with appropriate constraints on the range of the immediate.  SelectionDAG will pick the immediate version of the constraints match, otherwise it will pick the register version.<br>
<div class="HOEnZb"><div class="h5"><br>
David<br>
<br>
______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
</div></div></blockquote></div><br></div>