<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63339>63339</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
GCC generate better code than Clang related to the update of post-increment index
</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>
* test: https://gcc.godbolt.org/z/fco3j7sfd
```
for(i=0; i<N; i++){
x = comp[i];
if(x<a) Out_ref[n++]=B[i];
}
```
* gcc:
```
.L4:
ldr w5, [x2, x0] // x = comp[i]
cmp w7, w5
ble .L3
ldr w5, [x4, x0] // B[i]
str w5, [x3, w1, sxtw 2] // Out_ref[n]=B[i]
add w1, w1, 1 // n++
.L3:
add x0, x0, 4
cmp x6, x0
bne .L4
```
* clang: have more insns in the loop body
```
.LBB0_2: // in Loop: Header=BB0_3 Depth=1
add x4, x4, #4
subs x9, x9, #1
b.eq .LBB0_6
.LBB0_3: // =>This Inner Loop Header: Depth=1
ldr w10, [x2], #4 // x = comp[i]
cmp w10, w8
b.ge .LBB0_2
ldr w11, [x4] // B[i]
add w10, w1, #1 // tmp = ++n, use a temporary reg is redundant
str w11, [x3, w1, sxtw #2] // Out_ref[n]=B[i]
mov w1, w10 // update n
b .LBB0_2
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVUGPszYQ_TXDZbQR2EDgwCGEpq20ai-9rwwMhE-AqW02-frrK4OTbPJltWtFmMgzb_ye52GhddeORBlEOUSFJ2ZzlCp7b-qm8UpZ_8yA7dCQNsB3eDRm0sB3wA7ADm1VbVpZl7I3G6laYIf_gB2aSvIfW93U4Bfg7yD23W_5i4iNVMCSDnjhA8-xA77_a31h-fJLYZu76DMCL7CSwwRR3kFUAM-vQIjYNcCSM_C9AJbi37N5U9RAlI8OyyYU-ZNc2BZP9-eebIdtVVmmz4I2r-F1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