Skip to content

Commit 03f8523

Browse files
authored
Add propagate_inbounds_meta to atomic genericmemory ops (#55902)
`memoryref(mem, i)` will otherwise emit a boundscheck. ``` ; │ @ /home/vchuravy/WorkstealingQueues/src/CLL.jl:53 within `setindex_atomic!` @ genericmemory.jl:329 ; │┌ @ boot.jl:545 within `memoryref` %ptls_field = getelementptr inbounds i8, ptr %tls_pgcstack, i64 16 %ptls_load = load ptr, ptr %ptls_field, align 8 %"box::GenericMemoryRef" = call noalias nonnull align 8 dereferenceable(32) ptr @ijl_gc_small_alloc(ptr %ptls_load, i32 552, i32 32, i64 23456076646928) #9 %"box::GenericMemoryRef.tag_addr" = getelementptr inbounds i64, ptr %"box::GenericMemoryRef", i64 -1 store atomic i64 23456076646928, ptr %"box::GenericMemoryRef.tag_addr" unordered, align 8 store ptr %memoryref_data, ptr %"box::GenericMemoryRef", align 8 %.repack8 = getelementptr inbounds { ptr, ptr }, ptr %"box::GenericMemoryRef", i64 0, i32 1 store ptr %memoryref_mem, ptr %.repack8, align 8 call void @ijl_bounds_error_int(ptr nonnull %"box::GenericMemoryRef", i64 %7) unreachable ``` For the Julia code: ```julia function Base.setindex_atomic!(buf::WSBuffer{T}, order::Symbol, val::T, idx::Int64) where T @inbounds Base.setindex_atomic!(buf.buffer, order, val,((idx - 1) & buf.mask) + 1) end ``` from https://github.com/gbaraldi/WorkstealingQueues.jl/blob/0ebc57237cf0c90feedf99e4338577d04b67805b/src/CLL.jl#L41
1 parent 75393f6 commit 03f8523

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

base/genericmemory.jl

+6
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,13 @@ end
320320

321321
# get, set(once), modify, swap and replace at index, atomically
322322
function getindex_atomic(mem::GenericMemory, order::Symbol, i::Int)
323+
@_propagate_inbounds_meta
323324
memref = memoryref(mem, i)
324325
return memoryrefget(memref, order, @_boundscheck)
325326
end
326327

327328
function setindex_atomic!(mem::GenericMemory, order::Symbol, val, i::Int)
329+
@_propagate_inbounds_meta
328330
T = eltype(mem)
329331
memref = memoryref(mem, i)
330332
return memoryrefset!(
@@ -342,6 +344,7 @@ function setindexonce_atomic!(
342344
val,
343345
i::Int,
344346
)
347+
@_propagate_inbounds_meta
345348
T = eltype(mem)
346349
memref = memoryref(mem, i)
347350
return Core.memoryrefsetonce!(
@@ -354,11 +357,13 @@ function setindexonce_atomic!(
354357
end
355358

356359
function modifyindex_atomic!(mem::GenericMemory, order::Symbol, op, val, i::Int)
360+
@_propagate_inbounds_meta
357361
memref = memoryref(mem, i)
358362
return Core.memoryrefmodify!(memref, op, val, order, @_boundscheck)
359363
end
360364

361365
function swapindex_atomic!(mem::GenericMemory, order::Symbol, val, i::Int)
366+
@_propagate_inbounds_meta
362367
T = eltype(mem)
363368
memref = memoryref(mem, i)
364369
return Core.memoryrefswap!(
@@ -377,6 +382,7 @@ function replaceindex_atomic!(
377382
desired,
378383
i::Int,
379384
)
385+
@_propagate_inbounds_meta
380386
T = eltype(mem)
381387
memref = memoryref(mem, i)
382388
return Core.memoryrefreplace!(

0 commit comments

Comments
 (0)