<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/101808>101808</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Loop] Eliminate the loop branch when the loop iteration is small
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
vfdff
</td>
</tr>
</table>
<pre>
* I don't exactly know why gcc can eliminate loops, but it may is related to the length of array.
> when I enlarge the Length, such as 100, them it doesn't eliminate the loop branch.
test: https://gcc.godbolt.org/z/8qbdvqx9n
```
#include <string.h>
#define N 100
#define Length 4
void foo_restrict (float *__restrict dest,
float *__restrict src, int n)
{
float buf[Length];
memcpy(buf, src, sizeof(buf));
// #pragma clang loop vectorize(assume_safety)
for (int j = 0; j < n; j++) {
dest[j] += buf[j];
}
}
```
* gcc's assemble: It doesn't have loop branch
```
foo_restrict(float*, float*, int):
sub sp, sp, #16
ldp x4, x5, [x1]
stp x4, x5, [sp]
cmp w2, 0
ble .L1
whilelo p7.s, wzr, w2
ld1w z31.s, p7/z, [x0]
ld1w z30.s, p7/z, [sp]
fadd z31.s, p7/m, z31.s, z30.s
st1w z31.s, p7, [x0]
.L1:
add sp, sp, 16
ret
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0VduOszoPfZr0xvoqSEqBCy7a6VQaafS_wiiAgcwfEr4k9PT0Wwn0uLsRwiFZsZeXg-HWilYhFiTZkmS34KPrtCkOTd00i1LX54LQDXxBrRWhqQM88crJM_xf6SMcuzO0VQUVV4BS9EJxhyC1HiyhH1CODoSDnp9BWDAoucManAbXIUhUretAN8CN4ecliXYk2gAQ9gnHDhV8ASrJTYsB_h3g3qsdqw64hTiK_KvrsPdRao12pnhjEuJoPUBpuKq6Ocb0dGgdYRvonBssYRtC94Tu26patroutXRLbVpC9xdC99nfsj78PeVqdrCO5nt6pUyoSo41AmEf1hm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