Skip to content
Merged
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
9 changes: 7 additions & 2 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1214,8 +1214,13 @@ static Value *emit_inttoptr(jl_codectx_t &ctx, Value *v, Type *ty)
{
// Almost all of our inttoptr are generated due to representing `Ptr` with `T_size`
// in LLVM and most of these integers are generated from `ptrtoint` in the first place.
if (auto I = dyn_cast<PtrToIntInst>(v))
return ctx.builder.CreateBitCast(I->getOperand(0), ty);
if (auto I = dyn_cast<PtrToIntInst>(v)) {
auto ptr = I->getOperand(0);
if (ty->getPointerAddressSpace() == ptr->getType()->getPointerAddressSpace())
return ctx.builder.CreateBitCast(ptr, ty);
else if (ty->getPointerElementType() == ptr->getType()->getPointerElementType())
return ctx.builder.CreateAddrSpaceCast(ptr, ty);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a lit test?

Also what happens when As != As && eType !== eType?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just an optimization so falling through is fine.
I assume this is for non-default codegen with normal non default address space?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default codegen, but with LLVMPtr:

(gdb) call jl_(lam)
map(typeof(CUDA.cudaconvert), Tuple{CUDA.CuArray{Float32, 2}, CUDA.CuArray{Float32, 2}, CUDA.CuArray{Float32, 2}}) from map(Any, Tuple{Any, Any, Any})

(gdb) call jl_(src)
Core.CodeInfo(code=Array{Any, (44,)}[
  Expr(:call, Base.getfield, Core.Argument(n=3), 1, true),
  Expr(:call, Base.getfield, SSAValue(1), :(:dims)),
  Expr(:call, Base.getfield, SSAValue(1), :(:baseptr)),
  Base.bitcast,
  Expr(:call, SSAValue(4), CUDA.CuPtr{Float32}, SSAValue(3)),
  Expr(:call, Base.getfield, SSAValue(1), :(:offset)),
  Base.add_ptr,
  Base.bitcast,
  Expr(:call, SSAValue(8), CUDA.UInt, SSAValue(5)),
  Expr(:call, Base.bitcast, UInt64, SSAValue(6)),
  Expr(:call, SSAValue(7), SSAValue(9), SSAValue(10)),
  Expr(:call, #<intrinsic #0 bitcast>, CUDA.CuPtr{Float32}, SSAValue(11)),
  Expr(:call, Base.bitcast, Core.LLVMPtr{Float32, 1}, SSAValue(12)),
  ...

I couldn't find an easy reproducer though.

}
return ctx.builder.CreateIntToPtr(v, ty);
}

Expand Down