Issue 63339
Summary GCC generate better code than Clang related to the update of post-increment index
Labels new issue
Assignees
Reporter vfdff
    * 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
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to