julia> function f(a, i, j)
v1 = a[i, j]
ccall(:jl_breakpoint, Nothing, (Any,), a)
v2 = a[i, j]
return v1 + v2
end
f (generic function with 1 method)
julia> @code_llvm f(zeros(2, 2), 1, 1)
; Function f
; Location: REPL[2]:2
define double @julia_f_36027(%jl_value_t addrspace(10)* nonnull align 16 dereferenceable(40), i64, i64) {
top:
; Function getindex; {
; Location: array.jl:732
%3 = add i64 %1, -1
%4 = addrspacecast %jl_value_t addrspace(10)* %0 to %jl_value_t addrspace(11)*
%5 = bitcast %jl_value_t addrspace(11)* %4 to %jl_value_t addrspace(10)* addrspace(11)*
%6 = getelementptr inbounds %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)* addrspace(11)* %5, i64 3
%7 = bitcast %jl_value_t addrspace(10)* addrspace(11)* %6 to i64 addrspace(11)*
%8 = load i64, i64 addrspace(11)* %7, align 8
%9 = icmp ult i64 %3, %8
br i1 %9, label %ib, label %oob
ib: ; preds = %top
%10 = add i64 %2, -1
%11 = getelementptr inbounds %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)* addrspace(11)* %5, i64 4
%12 = bitcast %jl_value_t addrspace(10)* addrspace(11)* %11 to i64 addrspace(11)*
%13 = load i64, i64 addrspace(11)* %12, align 8
%14 = icmp ult i64 %10, %13
br i1 %14, label %idxend3, label %oob
oob: ; preds = %ib, %top
%15 = alloca [2 x i64], align 8
%.sub = getelementptr inbounds [2 x i64], [2 x i64]* %15, i64 0, i64 0
store i64 %1, i64* %.sub, align 8
%16 = getelementptr inbounds [2 x i64], [2 x i64]* %15, i64 0, i64 1
store i64 %2, i64* %16, align 8
%17 = addrspacecast %jl_value_t addrspace(10)* %0 to %jl_value_t addrspace(12)*
call void @jl_bounds_error_ints(%jl_value_t addrspace(12)* %17, i64* nonnull %.sub, i64 2)
unreachable
idxend3: ; preds = %ib
%18 = mul i64 %8, %10
%19 = add i64 %3, %18
%20 = bitcast %jl_value_t addrspace(11)* %4 to double addrspace(13)* addrspace(11)*
%21 = load double addrspace(13)*, double addrspace(13)* addrspace(11)* %20, align 8
%22 = getelementptr inbounds double, double addrspace(13)* %21, i64 %19
%23 = load double, double addrspace(13)* %22, align 8
;}
; Location: REPL[2]:3
call void inttoptr (i64 139974466181328 to void (%jl_value_t addrspace(10)*)*)(%jl_value_t addrspace(10)* nonnull %0)
; Location: REPL[2]:4
; Function getindex; {
; Location: array.jl:732
%24 = load double, double addrspace(13)* %22, align 8
;}
; Location: REPL[2]:5
; Function +; {
; Location: float.jl:395
%25 = fadd double %23, %24
;}
ret double %25
}
Note that the second boundscheck (as well as the size dependent index and pointer calculation) is gone.