Skip to content

Commit

Permalink
undo revert
Browse files Browse the repository at this point in the history
  • Loading branch information
oscardssmith committed Dec 5, 2024
1 parent 3e780d3 commit dfef35a
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 50 deletions.
13 changes: 2 additions & 11 deletions base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -382,17 +382,8 @@ default_access_order(a::GenericMemory{:atomic}) = :monotonic
default_access_order(a::GenericMemoryRef{:not_atomic}) = :not_atomic
default_access_order(a::GenericMemoryRef{:atomic}) = :monotonic

# bootstrap version for Memory{Any}
#getindex(A::Memory{Any}, i::Int) = (@_noub_if_noinbounds_meta;
# memoryrefget(memoryrefnew(memoryrefnew(A), i, @_boundscheck), default_access_order(A), false))

function getindex(A::GenericMemory, i::Int)
@_noub_if_noinbounds_meta
if @_boundscheck
ult_int(bitcast(UInt, sub_int(i, 1)), bitcast(UInt, A.length)) || throw_boundserror(A, (i,))
end
memoryrefget(memoryrefnew(memoryrefnew(A), i, false), default_access_order(A), false)
end
getindex(A::GenericMemory, i::Int) = (@_noub_if_noinbounds_meta;
memoryrefget(memoryrefnew(memoryrefnew(A), i, @_boundscheck), default_access_order(A), false))
getindex(A::GenericMemoryRef) = memoryrefget(A, default_access_order(A), @_boundscheck)

"""
Expand Down
7 changes: 3 additions & 4 deletions base/genericmemory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,9 @@ getindex(A::Memory, c::Colon) = copy(A)

## Indexing: setindex! ##

function _setindex!(A::Memory{T}, x::T, i::Int) where {T}
@boundscheck Core.Intrinsics.ult_int(i, A.length)
ref = memoryrefnew(memoryref(A), i, false)
memoryrefset!(ref, x, :not_atomic, false)
function _setindex!(A::Memory{T}, x::T, i1::Int) where {T}
ref = memoryrefnew(memoryref(A), i1, @_boundscheck)
memoryrefset!(ref, x, :not_atomic, @_boundscheck)
return A
end

Expand Down
4 changes: 2 additions & 2 deletions src/llvm-alloc-helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ void jl_alloc::runEscapeAnalysis(llvm::CallInst *I, EscapeAnalysisRequiredArgs r
return true;
}
if (required.pass.gc_loaded_func == callee) {
// TODO add manual load->store forwarding
push_inst(inst);
required.use_info.haspreserve = true;
required.use_info.hasload = true;
return true;
}
if (required.pass.typeof_func == callee) {
Expand Down
9 changes: 5 additions & 4 deletions src/llvm-alloc-opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,10 +752,11 @@ void Optimizer::moveToStack(CallInst *orig_inst, size_t sz, bool has_ref, AllocF
call->eraseFromParent();
return;
}
if (pass.gc_loaded_func == callee) {
user->replaceUsesOfWith(orig_i, Constant::getNullValue(orig_i->getType()));
return;
}
//if (pass.gc_loaded_func == callee) {
// call->replaceAllUsesWith(new_i);
// call->eraseFromParent();
// return;
//}
if (pass.typeof_func == callee) {
++RemovedTypeofs;
call->replaceAllUsesWith(tag);
Expand Down
1 change: 0 additions & 1 deletion src/pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,6 @@ static void buildIntrinsicLoweringPipeline(ModulePassManager &MPM, PassBuilder *
JULIA_PASS(FPM.addPass(LateLowerGCPass()));
JULIA_PASS(FPM.addPass(FinalLowerGCPass()));
if (O.getSpeedupLevel() >= 2) {
FPM.addPass(DSEPass());
FPM.addPass(GVNPass());
FPM.addPass(SCCPPass());
FPM.addPass(DCEPass());
Expand Down
28 changes: 0 additions & 28 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3295,31 +3295,3 @@ end
ref = memoryref(mem, 2)
@test parent(ref) === mem
end

@testset "Array/Memory escape analysis" begin
function no_allocate(T::Type{<:Union{Memory, Vector}})
v = T(undef, 2)
v[1] = 2
v[2] = 3
return v[1] + v[2]
end
function test_alloc(T; broken=false)
@test (@allocated no_allocate(T)) == 0 broken=broken
end
@testset "$T" for T in [Memory, Vector]
@testset "$ET" for ET in [Int, Union{Int, Float64}]
no_allocate(T{ET}) #compile
test_alloc(T{ET}, broken=(ET==Union{Int, Float64}) || T==Vector)
end
end
function f() # this was causing a bug on an in progress version of #55913.
m = Memory{Float64}(undef, 4)
m .= 1.0
s = 0.0
for x m
s += x
end
s
end
@test f() === 4.0
end

0 comments on commit dfef35a

Please sign in to comment.