<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64998>64998</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Attributes likely and unlikely (C++ 20) not used by hot cold splitting.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
bug,
enhancement
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
hiraditya
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
hiraditya
</td>
</tr>
</table>
<pre>
In the example below, the hot cold splitting doesnot outline the cold block unless attribute cold is specified on a function in the basic block.
https://godbolt.org/z/T5z96ssv1
```cpp
#include <cstddef>
#include <utility>
#include <cstdio>
#ifdef COLD
#define COLD __attribute__((cold))
#else
#define COLD
#endif
struct IntPairVector {
void push_back(int a, int b);
COLD void ExpandCapacity();
std::pair<int, int>* data_;
size_t size_;
size_t capacity_;
};
void IntPairVector::push_back(int a, int b) {
if (size_ == capacity_) [[unlikely]] {
printf("asdflasjfd");
printf("asdflasjfd");
printf("asdflasjfd");
printf("asdflasjfd");
printf("asdflasjfd");
ExpandCapacity();
}
data_[size_++] = std::make_pair(a, b);
}
```
$ clang++ -O3 -std=c++2b -mllvm -hot-cold-split
```asm
IntPairVector::push_back(int, int): # @IntPairVector::push_back(int, int)
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %edx, %ebx
movl %esi, %ebp
movq %rdi, %r14
movq 8(%rdi), %rax
cmpq 16(%rdi), %rax
je .LBB0_1
.LBB0_2:
movq (%r14), %rcx
leaq 1(%rax), %rdx
movq %rdx, 8(%r14)
movl %ebp, (%rcx,%rax,8)
movl %ebx, 4(%rcx,%rax,8)
addq $8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
.LBB0_1:
leaq .L.str(%rip), %r15
movq %r15, %rdi
xorl %eax, %eax
callq printf@PLT
movq %r15, %rdi
xorl %eax, %eax
callq printf@PLT
movq %r15, %rdi
xorl %eax, %eax
callq printf@PLT
movq %r15, %rdi
xorl %eax, %eax
callq printf@PLT
movq %r15, %rdi
xorl %eax, %eax
callq printf@PLT
movq %r14, %rdi
callq IntPairVector::ExpandCapacity()@PLT
movq 8(%r14), %rax
jmp .LBB0_2
.L.str:
.asciz "asdflasjfd"
```
$ clang++ -O3 -std=c++2b -mllvm -hot-cold-split -DCOLD
```asm
IntPairVector::push_back(int, int): # @IntPairVector::push_back(int, int)
pushq %rbp
pushq %r14
pushq %rbx
subq $16, %rsp
movl %edx, %ebx
movl %esi, %ebp
movq %rdi, %r14
movq 8(%rdi), %rax
cmpq 16(%rdi), %rax
je .LBB0_1
.LBB0_2:
movq (%r14), %rcx
leaq 1(%rax), %rdx
movq %rdx, 8(%r14)
movl %ebp, (%rcx,%rax,8)
movl %ebx, 4(%rcx,%rax,8)
addq $16, %rsp
popq %rbx
popq %r14
popq %rbp
retq
.LBB0_1:
leaq 8(%r14), %rsi
leaq 8(%rsp), %rdx
movq %r14, %rdi
callq IntPairVector::push_back(int, int) [clone .cold.1]
movq 8(%rsp), %rax
jmp .LBB0_2
IntPairVector::push_back(int, int) [clone .cold.1]: # @IntPairVector::push_back(int, int) [clone .cold.1]
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
leaq .L.str(%rip), %r12
movq %r12, %rdi
xorl %eax, %eax
callq printf@PLT
movq %r12, %rdi
xorl %eax, %eax
callq printf@PLT
movq %r12, %rdi
xorl %eax, %eax
callq printf@PLT
movq %r12, %rdi
xorl %eax, %eax
callq printf@PLT
movq %r12, %rdi
xorl %eax, %eax
callq printf@PLT
movq %r15, %rdi
callq IntPairVector::ExpandCapacity()@PLT
movq (%r14), %rax
movq %rax, (%rbx)
addq $8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
.L.str:
.asciz "asdflasjfd"
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcGE1v4jj015jLE1HiEBoOHAoM0kiVZ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