Consider three functions:
foo1() = (Vector() ; 0)
foo2() = (Vector(undef, 2^50) ; 0)
foo3() = (Vector(undef, -1) ; 0)
On the current master, creation of Vector seems to be eliminated in foo1, foo2, and not eliminated in foo3 :
julia> @code_native debuginfo=:none dump_module=false foo1()
.text
endbr64
mov rax, qword ptr [rcx + 56]
ret
nop dword ptr [rax]
julia> @code_native debuginfo=:none dump_module=false foo2()
.text
endbr64
mov rax, qword ptr [rcx + 56]
ret
nop dword ptr [rax]
julia> @code_native debuginfo=:none dump_module=false foo3()
.text
push rbp
mov rbp, rsp
mov rax, qword ptr [r13 + 16]
mov rax, qword ptr [rax + 16]
mov rax, qword ptr [rax]
movabs rax, offset jl_alloc_genericmemory
movabs rdi, offset jl_system_image_data
mov rsi, -1
call rax
xor eax, eax
pop rbp
ret
How does the compiler decide which code to eliminate here? Thanks for the answer!
I bring this example because both foo2 and foo3 (edit: should) have apparently observable effects (OOM and ArgumentError, resp.), yet the behaviour is different.