<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/100290>100290</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[lld][RISC-V] `mv rd rd` used in global symbol address calculation could be eliminated.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
lld
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
wan-yuqi
</td>
</tr>
</table>
<pre>
When compiling a pragma which uses a global symbol and targets `riscv*`, it will generate a sequence instructions for calculating address:
```
foo:
lui a0, %hi(Var)
addi a0, a0, %lo(Var)
```
When the address of `Var` is aligned to 0x1000, such as 0x20000, calculation instructions will be:
```
foo:
lui a0, 20
mv a0, a0 # pseudo instruction of `addi a0, a0, 0`
```
I think `mv a0, a0` could be eliminated by linker relaxation (which the target and source registers are the same and R_RISCV_LO12_I is `ADDI`) to reduce unnecessary instructions. But it' s not mentioned in riscv-elf-psabi-doc. Is there any negative impact?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8U12L4zgQ_DXKS5OgyLGdPPhhZkMgcHCwB3OPQ1vq2LqVpaxaykz-_SEnO193LBhsS6WurlI1MtvBE3WifhT1foE5jSF2L-iX1_zTLvpgrt3fI3nQYTpbZ_0ACOeIw4TwMlo9QmZiQBhc6NEBX6c-OEBvIGEcKDGIRkbL-iLUg2ikUN_AJnixzsFAniImAgSmn5m8JrCeU8w62eAZTiGCRqezwzRTGxOJWVQPIOReyLng7Zl_TyGI6uH2DS5bAJwJhapHK9T2CaNQu_t-qWbvgDeYC19gXxhmL9JIv1qBcCoCy4lGgmVAVww1kALI17WUc2HOegRkkK9K3pfeZAX_WfPsTE9vOn4n8aNGJX8tTheAN10AIFQFZ6Zswkeme-f_MeGd6gvzEdJo_Y9yaLq8H2kk6JCdgZ6AnJ2sx0QG-is4639QhEgOX29ChdreQlMcvOVjjgqHHDVBpMFyosiAkWYM40Qz4vvz9-Nf356e__hzrZ6PxWjRyIf9_jhHalfsjmSyJsjekyZmjNdPxq7gMSewSagWGHxIMJEvO2TAepgjuiR3Wp4Ze7s0Qa_gyKWLWFq4gqcBk70Q2OmMOonqcPNlYbrK7KodLqhbt2rdbrdNWy3GrtdGNifcrOuqJ8R-127rU71bb3a40Ua1C9spqTayVRupqrauVhVuN327Xbey17JpWrGRNKF1K-cu0yrEYWGZM3VrKdVOLhz25HieXaWcM0KpMsSxK_BlnwcWG-ksJ34vkGxy87gXfL0X9WMxdvkk6v39ZqOBaMq1Zr5Z82W078H_GOD_CcBqkaPrxpTOZVyFOgh1GGwac7_SYRLqUDq6v5bnGP4hnYQ6zPpYqMNd4qVT_wYAAP__8GBxXA">