Open
Description
When calling nextpow(2, x)
, it seems that it's expected that Base._nextpow2
is inlined.
Lines 575 to 578 in 4846c3d
However, with 1.11 through to nightly, it seems like this may not be the case. I see those lines were written in 2018, and needless to say a lot has changed since then.
julia> npow2constproptest(x) = nextpow(2, x)
npow2constproptest (generic function with 1 method)
julia> @code_native npow2constproptest(1234)
.file "npow2constproptest"
.section .ltext,"axl",@progbits
.globl julia_npow2constproptest_4029 # -- Begin function julia_npow2constproptest_4029
.p2align 4
.type julia_npow2constproptest_4029,@function
julia_npow2constproptest_4029: # @julia_npow2constproptest_4029
; Function Signature: npow2constproptest(Int64)
; ┌ @ REPL[4]:1 within `npow2constproptest`
# %bb.0: # %top
#DEBUG_VALUE: npow2constproptest:x <- $rdi
push rbp
mov rbp, rsp
mov rsi, rdi
movabs rax, offset j_nextpow_4031
mov edi, 2
call rax
pop rbp
ret
.Lfunc_end0:
.size julia_npow2constproptest_4029, .Lfunc_end0-julia_npow2constproptest_4029
; └
# -- End function
Is a Base.@constprop :aggressive
annotation needed here? From a quick check, it seems to help. There does seem to be some extra overhead compared to _nextpow2
though. Perhaps I'm being overly optimistic, but I hoped that npow2constproptest
would compile to the same instructions as _nextpow2
, and even with aggressive constant prop that doesn't seem to be the case.