Missed optimization: movaps initialization of repetitive data
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
```c++
// Type your code here, or load an example.
int cube(int* num);
int square(int num) {
int nums[16] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
return cube(nums);
}
```
-O2 or -O3
Result:
```asm
square(int):
sub rsp, 72
movaps xmm0, xmmword ptr [rip + .L__const.square(int) (.nums)+48]
movaps xmmword ptr [rsp + 48], xmm0
movaps xmm0, xmmword ptr [rip + .L__const.square(int) (.nums)+32]
movaps xmmword ptr [rsp + 32], xmm0
movaps xmm0, xmmword ptr [rip + .L__const.square(int) (.nums)+16]
movaps xmmword ptr [rsp + 16], xmm0
movaps xmm0, xmmword ptr [rip + .L__const.square(int) (.nums)]
movaps xmmword ptr [rsp], xmm0
mov rdi, rsp
call cube(int*)@PLT
add rsp, 72
ret
.L__const.square(int) (.nums):
.long 1
.long 1
.long 1
.long 1
.long 1
.long 1
.long 1
.long 1
.long 1
.long 1
.long 1
.long 1
.long 1
.long 1
.long 1
.long 1
```
Expected: Deduplicate the 16-byte chunks in that table, like MSVC and GCC do. https://godbolt.org/z/z3bGf7Y5h
Contributor guide
Assessment
This issue has not been assessed yet.