I was optimizing some code in the hot path and was surprised to see that constants written as
10^6 were being evaluated at run-time. Isn’t evaluating constants like this one of the simplest optimizations? Why wouldn’t Julia simplify it?
julia> function f(x) x*10^6 end f (generic function with 1 method) julia> @code_native f(1) .text ; ┌ @ REPL:1 within `f' pushq %rbx movq %rdi, %rbx ; │ @ REPL:2 within `f' ; │┌ @ none within `literal_pow' ; ││┌ @ none within `macro expansion' ; │││┌ @ intfuncs.jl:273 within `^' movabsq $power_by_squaring, %rax movl $10, %edi movl $6, %esi callq *%rax ; │└└└ ; │┌ @ int.jl:87 within `*' imulq %rbx, %rax ; │└ popq %rbx retq ; └