llvm / llvm/llvm-project

Inefficient handling of returning bools (`i1`)

Open
#199,611 2 comments 0 reactions 1 assignee Claimed by @iamaayushrivastava View on GitHub
backend:X86 llvm:codegen missed-optimization
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

https://godbolt.org/z/hK6vs9sh6

```c++
#include

bool test_dil(size_t x, int* y) {
if (x % 4 == 0) {
*y = 0;

return true;
} else {
return false;
}
}

char fixed(size_t x, int* y) {
if (x % 4 == 0) {
*y = 0;

return 1;
} else {
return 0;
}
}
```

```assembly
test_dil(unsigned long, int*):
test dil, 3
je .LBB0_1
test dil, 3 ; unnecessary
sete al
ret
.LBB0_1:
mov dword ptr [rsi], 0
test dil, 3 ; unnecessary
sete al
ret

fixed(unsigned long, int*):
test dil, 3
je .LBB1_2
xor eax, eax
ret
.LBB1_2:
mov dword ptr [rsi], 0
mov al, 1
ret
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.