Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make allocopt respect the GC verifier rules with non usual address spaces #51520

Merged
merged 1 commit into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/llvm-alloc-opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,8 +642,6 @@ void Optimizer::moveToStack(CallInst *orig_inst, size_t sz, bool has_ref)
}
insertLifetime(ptr, ConstantInt::get(Type::getInt64Ty(prolog_builder.getContext()), sz), orig_inst);
Instruction *new_inst = cast<Instruction>(prolog_builder.CreateBitCast(ptr, JuliaType::get_pjlvalue_ty(prolog_builder.getContext(), buff->getType()->getPointerAddressSpace())));
if (orig_inst->getModule()->getDataLayout().getAllocaAddrSpace() != 0)
new_inst = cast<Instruction>(prolog_builder.CreateAddrSpaceCast(new_inst, JuliaType::get_pjlvalue_ty(prolog_builder.getContext(), orig_inst->getType()->getPointerAddressSpace())));
new_inst->takeName(orig_inst);

auto simple_replace = [&] (Instruction *orig_i, Instruction *new_i) {
Expand Down Expand Up @@ -691,7 +689,7 @@ void Optimizer::moveToStack(CallInst *orig_inst, size_t sz, bool has_ref)
else if (auto call = dyn_cast<CallInst>(user)) {
auto callee = call->getCalledOperand();
if (pass.pointer_from_objref_func == callee) {
call->replaceAllUsesWith(new_i);
call->replaceAllUsesWith(prolog_builder.CreateAddrSpaceCast(new_i, call->getCalledFunction()->getReturnType()));
call->eraseFromParent();
return;
}
Expand Down
11 changes: 6 additions & 5 deletions test/llvmpasses/alloc-opt-gcframe-addrspaces.ll
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ declare {}* @julia.pointer_from_objref({} addrspace(11)*)
; Test that non-0 addrspace allocas are properly emitted and handled

; CHECK-LABEL: @non_zero_addrspace
; CHECK: %1 = alloca i32, align 8, addrspace(5)
; TYPED: %1 = alloca i32, align 8, addrspace(5)

; TYPED: %2 = bitcast i32 addrspace(5)* %1 to i8 addrspace(5)*
; TYPED: %3 = bitcast i8 addrspace(5)* %2 to {} addrspace(5)*
; TYPED: %var1 = addrspacecast {} addrspace(5)* %3 to {} addrspace(10)*
; TYPED: %var1 = bitcast i8 addrspace(5)* %2 to {} addrspace(5)*
; TYPED: %3 = addrspacecast {} addrspace(5)* %var1 to {}*
; TYPED: call void @llvm.lifetime.start.p5i8(i64 4, i8 addrspace(5)* %2)

; OPAQUE: %var1 = addrspacecast ptr addrspace(5) %1 to ptr addrspace(10)
; OPAQUE: call void @llvm.lifetime.start.p5(i64 4, ptr addrspace(5) %1)
; OPAQUE: %var1 = alloca i32, align 8, addrspace(5)
; OPAQUE: %1 = addrspacecast ptr addrspace(5) %var1 to ptr
; OPAQUE: call void @llvm.lifetime.start.p5(i64 4, ptr addrspace(5) %var1)

; CHECK: ret void
define void @non_zero_addrspace() {
Expand Down