Skip to content

Conversation

@maleadt
Copy link
Member

@maleadt maleadt commented Nov 13, 2020

julia-debug: /home/tim/Julia/julia/deps/srccache/llvm-11.0.0/lib/IR/Instructions.cpp:2873: static llvm::CastInst* llvm::CastInst::Create(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*, const llvm::Twine&, llvm::Instruction*): Assertion `castIsValid(op, S, Ty) && "Invalid cast!"' failed.

#4  0x00007ffff33e5d58 in llvm::CastInst::Create (op=llvm::Instruction::BitCast, S=0x5555582d6cf0, Ty=0x55555676b0a0, Name=..., InsertBefore=0x0) at /home/tim/Julia/julia/deps/srccache/llvm-11.0.0/lib/IR/Instructions.cpp:2873
#5  0x00007ffff73e0166 in llvm::IRBuilderBase::CreateCast (this=0x7fffffffa800, Op=llvm::Instruction::BitCast, V=0x5555582d6cf0, DestTy=0x55555676b0a0, Name=...)
    at /home/tim/Julia/julia/build/release/usr/include/llvm/IR/IRBuilder.h:2097
#6  0x00007ffff73e001b in llvm::IRBuilderBase::CreateBitCast (this=0x7fffffffa800, V=0x5555582d6cf0, DestTy=0x55555676b0a0, Name=...) at /home/tim/Julia/julia/build/release/usr/include/llvm/IR/IRBuilder.h:2056
#7  0x00007ffff736f255 in emit_inttoptr (ctx=..., v=0x5555583d1ef0, ty=0x55555676b0a0) at /home/tim/Julia/julia/src/codegen.cpp:1218
#8  0x00007ffff7394a5d in generic_bitcast (ctx=..., argv=0x7fffffff8b10) at /home/tim/Julia/julia/src/intrinsics.cpp:491
#9  0x00007ffff73978c8 in emit_intrinsic (ctx=..., f=JL_I::bitcast, args=0x7fff94c7a7b0, nargs=2) at /home/tim/Julia/julia/src/intrinsics.cpp:910
#10 0x00007ffff73a6102 in emit_call (ctx=..., ex=0x7fff94c63370, rt=0x7fff9b1570d0) at /home/tim/Julia/julia/src/codegen.cpp:3484

@maleadt maleadt added compiler:codegen Generation of LLVM IR and native code bugfix This change fixes an existing bug labels Nov 13, 2020
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.

@maleadt
Copy link
Member Author

maleadt commented Nov 18, 2020

Both CI failures unrelated, and happen on current master too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix This change fixes an existing bug compiler:codegen Generation of LLVM IR and native code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants