<font size=2 face="sans-serif">Hi,</font><br><br><font size=2 face="sans-serif">This discussion caught my eye because
we are also looking at a very similar problem on PowerPC. </font><br><font size=2 face="sans-serif">We have a situation where we want to
align a given instruction to a 64 byte boundary. If it's not already aligned
we just add nops until it is aligned (We plan to do this in a custom PPCStreamer).
If the branch and the target of that branch are far enough away adding
a few nops in-between may actually overflow the 14 bits we have to represent
the offset in the branch instruction and in that case we have to do something
special and replace the branch with something else that, once again, is
not a single instruction.</font><br><br><font size=2 face="sans-serif">If </font><tt><font size=2>mayNeedRelaxation</font></tt><font size=2 face="sans-serif"> and relaxInstruction are not the way to do this is there any other
better way?</font><br><br><font size=2 face="sans-serif">Thanks, </font><br><font size=2 face="sans-serif">Stefan</font><br><br><br><br><br><font size=1 color=#5f5f5f face="sans-serif">From:      
 </font><font size=1 face="sans-serif">"Friedman, Eli
via llvm-dev" <llvm-dev@lists.llvm.org></font><br><font size=1 color=#5f5f5f face="sans-serif">To:      
 </font><font size=1 face="sans-serif">Paolo <paolo.savini@embecosm.com>,
llvm-dev@lists.llvm.org</font><br><font size=1 color=#5f5f5f face="sans-serif">Date:      
 </font><font size=1 face="sans-serif">2018/12/04 03:15 PM</font><br><font size=1 color=#5f5f5f face="sans-serif">Subject:    
   </font><font size=1 face="sans-serif">Re: [llvm-dev]
Branch relaxation at assembler level (RISCV)</font><br><font size=1 color=#5f5f5f face="sans-serif">Sent by:    
   </font><font size=1 face="sans-serif">"llvm-dev"
<llvm-dev-bounces@lists.llvm.org></font><br><hr noshade><br><br><br><tt><font size=2>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.<br><br>That said, I'm a little skeptical this is actually a good idea; the more
<br>"smart" the assembler is, the harder it becomes to understand
what it's <br>doing. No other in-tree target does this sort of transform.<br><br>-Eli<br><br>-- <br>Employee of Qualcomm Innovation Center, Inc.<br>Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux
Foundation Collaborative Project<br><br>_______________________________________________<br>LLVM Developers mailing list<br>llvm-dev@lists.llvm.org<br></font></tt><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev"><tt><font size=2>http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</font></tt></a><tt><font size=2><br><br></font></tt><br><BR>