Add 'cold' attribute to functions
Diego Novillo
dnovillo at google.com
Tue May 14 18:09:52 PDT 2013
On 2013-04-11 09:18 , Duncan Sands wrote:
> Hi Diego,
>
> On 10/04/13 23:33, Diego Novillo wrote:
>> This patch adds a new function attribute 'cold' to functions.
>
> can you please add a testcase or two checking that this works properly
> when the callsite has the 'cold' attribute but the called function does
> not. (It should work automagically, but it would be best to be sure).
> This could be useful if the function is not always cold, but some calls
> to it are known cold by the front-end somehow.
Sure. Interestingly, the analysis triggers correctly on the following:
[ ... ]
entry:
%gep1 = getelementptr i32* %a, i32 1
%val1 = load i32* %gep1
%cond1 = icmp ugt i32 %val1, 1
br i1 %cond1, label %then, label %else
then:
; This function is not declared cold, but this call site is.
%val4 = call i32 @regular_function(i32 %val1) cold
br label %exit
else:
%gep2 = getelementptr i32* %a, i32 2
%val2 = load i32* %gep2
%val3 = call i32 @regular_function(i32 %val2)
br label %exit
[ ... ]
The entry->else is marked hot with a high weight. However, code
generation still merges the calls to 'regular_function' in the two
branches, which makes code layout put the call at the bottom. I think
this should not be happening, though.
.globl test_cold_call_sites
.align 16, 0x90
.type test_cold_call_sites, at function
test_cold_call_sites: # @test_cold_call_sites
.cfi_startproc
# BB#0: # %entry
pushq %rax.Ltmp71:
.cfi_def_cfa_offset 16
movq %rdi, %rax
movl 4(%rax), %edi
cmpl $2, %edi
jae .LBB22_2
# BB#1: # %else
movl 8(%rax), %edi
.LBB22_2: # %else
callq regular_function
popq %rdx
ret
Where should I look into this?
I've added an analysis test, but I have not added a code gen test for
it. I need to figure out whether this can be changed.
Thanks. Diego.
More information about the llvm-commits
mailing list