<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/56448>56448</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [RISCV] BranchRelaxation calculates overly conservative size when a branch branches over compressible branch instructions
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:RISC-V
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          topperc
      </td>
    </tr>
</table>

<pre>
    The BranchFolding pass tries to determine if a branch target is too far away for the 12-bit immediate of a conditional branch. If the offset is too large it inverts the branch uses a short branch over an unconditional jump to have a larger offset.

To do this it calls getInstSize to calculate the size of all of the instructions that are branched over. If there are any compressible branches (c.bez, c.bnez), getInstSize will not calculate the compressed size for them because their offset is inherently dependent on the relaxation process. This leads to a more conservative estimate of size and can lead to more relaxation than needed.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxtU0tv4yAQ_jX2ZRTLwXabHHzoQ5Vybavex2Yc08VgAU42_fU7sEmTrlayMAwz32OAzspT-z4SPDo0_fhitVRmDzN6D8Ep4tGCpEBuUoZADYDQpVQI6PYUQMUUCwM6wCOeYLAOAgOuxapTvD1NJBUGAhtre2ukCsoa1GecAnZDKrDD4K94OqJDBDAHcsGnlDPz4lkXgh-tC5eY5SxAA4u5pfhcpjk6GPFAXJFA3ZmpyMrnrHz4O76zS8sczM6cPWrtgd3tjA9v6osiBgf7RUcnUYqP0WhJ6_iLIcXJbukjdZSLAdBdNJNMCi9mOR730Jy4I9PsyHvV6e9kD5nY9EVHX5l4Ap6YONvGxa2oo2JyY8M_0i6IzJlUnk9kgo565N7FhXI3_VYmKjJBn_ioZzKS52BNAnOk8TdGTzA72zNsAe-xTZpQptuBMFkXWY0nd-BUbjX5oKbzoScNaCSrNKkqFqWSG2xulwFDJEkWuWwrua22mAcVNLVZ8_i6e3v6yJrn8zV9vRZ-W_epwfr0U0giP45krvf2u8fpyvyn_T8OMl-cbscQZp9VD5l44W-vwrh0BVfyQuvD5bfiBn1SH3ipvF_I86S5q-tNPraiEk3Ty7te1MNQdwPey7psqvKuFPdYbmWusSPto9dMiA77X3wMzBiNrz44xOZz1YpSiPK-3IhyXVXrYsODXA_NmqG2G6qzuqQJlS6inMK6fe7apKxb9p43tfLBXzf5kas9Nz2xMj4ugZ9UG-w8k-vzZKJNDv4AAZl1Jg">