<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Tue, Dec 4, 2018 at 12:13 PM Friedman, Eli 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 12/3/2018 2:45 PM, Paolo via llvm-dev wrote:<br>
> Hi all,<br>
><br>
> I'm trying to implement the same branch relaxation mechanism implemented<br>
> in CodeGen in the MC layer of RISCV.<br>
><br>
> beqz t1, L1<br>
><br>
> =><br>
><br>
> bnez t1, L2<br>
><br>
> j L1<br>
><br>
> That's because LLVM does not apply the CodeGen optimizations when<br>
> compiling directly from assembly code.<br>
><br>
> What I'd like to do would be to add a pass that does that on the MC<br>
> instructions or at least to find a way to implement this relaxation in<br>
> the MC assembler.<br>
><br>
> Any suggestions on where/how to do it? Or any existing fixes?<br>
<br>
The RISCV assembler already has code for similar transforms; see <br>
RISCVAsmBackend::mayNeedRelaxation and <br>
RISCVAsmBackend::relaxInstruction. The only tricky bit is that the <br>
relaxation interface doesn't expect one instruction to be relaxed to two <br>
instructions... probably not too hard to change, though, if necessary.</blockquote><div><br></div><div>Note that it is *extremely* important that RISC-V relaxations only ever make the code shorter, never longer.</div><div><br></div><div>If the instructions stay the same size, it can not be permitted to replace one instruction with two.</div><div><br></div><div>Changing a 32 bit instruction to two 16 bit instructions could be ok, but I'm struggling to think of an example when that would be beneficial. </div></div></div>