How to force compile-time evaluation of literal calculations?

This seems to work (tested on Julia 1.6):

julia> f(x) = x + Int(1e6)
f (generic function with 1 method)

julia> @code_llvm f(1)
;  @ REPL[18]:1 within `f'
define i64 @julia_f_277(i64 signext %0) {
top:
; ┌ @ int.jl:87 within `+'
   %1 = add i64 %0, 1000000
; └
  ret i64 %1
}
3 Likes