Skip to content

view emits a boundscheck that can't be turned off. #39308

@vchuravy

Description

@vchuravy
using StaticArrays
@inbounds function f(data, idx)
         arr = MArray{Tuple{3,3}}(data...)
         va = view(arr, :, idx)
         va[2] = 2
         return SArray(arr)
end

emits a boundscheck despite the @inbounds.

@_inline_meta
should probably use @propagate_inbounds.

;  @ REPL[23]:3 within `f'
; ┌ @ subarray.jl:167 within `view'
   %24 = getelementptr inbounds { i64 }, { i64 }* %4, i64 0, i32 0
   store i64 %2, i64* %24, align 8
; │┌ @ abstractarray.jl:610 within `checkbounds' @ abstractarray.jl:589
; ││┌ @ abstractarray.jl:636 within `checkbounds_indices' @ abstractarray.jl:636
; │││┌ @ abstractarray.jl:667 within `checkindex'
; ││││┌ @ bool.jl:36 within `&'
       %.off = add i64 %2, -1
       %25 = icmp ugt i64 %.off, 2
; ││└└└
; ││ @ abstractarray.jl:610 within `checkbounds'
    br i1 %25, label %L21, label %L24

L21:                                              ; preds = %top
    %26 = getelementptr inbounds [3 x {}*], [3 x {}*]* %gcframe61, i64 0, i64 2
    store {}* %18, {}** %26, align 16
    %27 = call nonnull {}* @j_throw_boundserror_711({}* nonnull %18, { i64 }* nocapture readonly %4)
    call void @llvm.trap()
    unreachable

The bounds-check itself wouldn't be that bad if it in turn wouldn't cause us to capture the MArray and thus preventing allocating it on the stack, so an alternative fix would be for Base.throw_boundserror to not capture the array it's based off.

Metadata

Metadata

Assignees

No one assigned

    Labels

    gpuAffects running Julia on a GPUperformanceMust go faster

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions