| Issue |
76482
|
| Summary |
Missed optimization for x86 when optimizing for size
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
lhmouse
|
https://gcc.godbolt.org/z/sTs3E9EP1
```c++
struct stack
{
void** base;
unsigned int top, cap;
};
struct context
{
void* data;
stack* st;
};
int
clear_stack(context& ctx)
{
ctx.st->top = 0;
return 0;
}
```
This compiles to 14 bytes:
```asm
clear_stack(context&):
mov rax,QWORD PTR [rdi+0x8] # 48 8b 47 08
mov DWORD PTR [rax+0x8],0x0 # c7 40 08 00 00 00 00
xor eax,eax # 31 c0
ret # c3
```
We notice that the EAX register is cleared at the end, which could have been done earlier, so this code would compile to 10 bytes:
```asm
clear_stack_2(context&):
mov rcx,QWORD PTR [rdi+0x8] # 48 8b 4f 08
xor eax,eax # 31 c0
mov DWORD PTR [rcx+0x8],eax # 89 41 08
ret # c3
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs