<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/59366>59366</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[RISCV] missed optimization with pointer induction in loop
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
vsukhoml
</td>
</tr>
</table>
<pre>
In example https://godbolt.org/z/b8z5P1KEz
```
size_t strlen2(const char *s)
{
const char *s1 = s;
while (*s++) ;
return (size_t)(s-s1-1);
}
```
gcc frequently produce kernel loop with 3 instructions (sometimes with bad block splitting in other variants):
```
.L8:
lbu a4,0(a5)
addi a5,a5,1
bne a4,zero,.L8
```
while llvm produce 4 instructions:
```
.LBB2_1: # =>This Inner Loop Header: Depth=1
add a2, a0, a1
lbu a2, 0(a2)
addi a1, a1, 1
bnez a2, .LBB2_1
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0VN1uqzgQfprhZpQIxoHABRf5abTV9mK1u9rbygYneGtsjm3a0zz9kSFNT9sUWR4n883fNx5z79XJSFlDvoV8n_AxdNbVz3586myvE2Hb1_reoPzJ-0FL7EIYPLAN0AHocLKtsDosrTsBHc5AB1Ge87-yP-_OkO4h3UCRXtb006uzfAzog9PSEFDZWOMDNh13CLTxQNXFbr2dD4iIn0AZAtujB3aBQFq9dEpLBCpnJ9tpVfgb5AJ0MozOROScSgxIpV_4bJHF89Vgvb9ZwKlp8Ojkj1GaoF9xcLYdG4lP0hmpUVs74IsKHTJUxgc3NkFZ46d4tpdB9dLPAMFbFNo2T-gHrUJQ5oTKoA2ddPjMneImTHSwzc1Elg_lVYWXT4txknwFtEuBSp5fCX3D8LZVGP_fTVv2USuMfPdwls4C7WKkWxngTLrWz_2Vh9WHsr_PfbulxwzYNe53HxCLzQZ292-nPN4bIx0-RJb_kLyVLrrYyyF0wPbZl0JnSUA75Om0Z18Jm_UTW3SbrSiziznt8Ctl5_c4b6XdKjtpa9ZWrOKJrLNinbI8Z1QlXZ2ykoo2K9bFcZUKsUqJ5RmJIufHltExTVRNKVFGaZFVLCe2XLWCNSxbN-tSHPOmgVUqe670MnYjTmOivB9lnVesKBLNhdR-mnAiI19wUgJRHHhXR5uFGE8eVqlWPvh3L0EFPT0Nf9__s_sP8j32ynvZoh2C6tWZxz7PF3qwygTpUJl2bn-8znEgktHp-tOzoUI3imVje6BDDHYRi8HZ_2UTgA5Tih7oMJXwKwAA__8n-0u-">