Issue 162599
Summary [ARM] [Clang] Missed optimization for bool return val arithmetic operations
Labels clang
Assignees
Reporter xieyuanbin1-huawei
    ```c
bool xxxx();
int kkk()
{
    return xxxx() + 1;
}
```
https://godbolt.org/z/YoM1PYE1n

llvm:
```
kkk:
        push {r11, lr}
        bl      xxxx
        mov     r1, #1
        cmp r0, #0
        movwne  r1, #2
        mov     r0, r1
        pop     {r11, pc}
```
gcc:
```
kkk:
        push    {r4, lr}
        bl      xxxx
 add     r0, r0, #1
        pop     {r4, pc}
```

According to ARM's ABI (I'm not sure if there is documentation to support this, but both GCC and LLVM compilers behave this way), in the aforementioned use case, the return value of the bool type is stored in the r0 register, and the value of r0 is 0 (false) or 1 (true).
However, the LLVM compiler seems to have missed some optimizations when performing arithmetic operations on return values.
No similar issues have been identified on other architectures at this time.


_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to