diff --git a/src/CodeGen_Internal.cpp b/src/CodeGen_Internal.cpp index c9c633b3646a..df12727bd4d3 100644 --- a/src/CodeGen_Internal.cpp +++ b/src/CodeGen_Internal.cpp @@ -91,20 +91,20 @@ void unpack_closure(const Closure &closure, int idx = 0; for (const auto &v : closure.vars) { Value *ptr = builder->CreateConstInBoundsGEP2_32(type, src, 0, idx++); - LoadInst *load = builder->CreateLoad(ptr); + LoadInst *load = builder->CreateLoad(ptr->getType()->getPointerElementType(), ptr); dst.push(v.first, load); load->setName(v.first); } for (const auto &b : closure.buffers) { { Value *ptr = builder->CreateConstInBoundsGEP2_32(type, src, 0, idx++); - LoadInst *load = builder->CreateLoad(ptr); + LoadInst *load = builder->CreateLoad(ptr->getType()->getPointerElementType(), ptr); dst.push(b.first, load); load->setName(b.first); } { Value *ptr = builder->CreateConstInBoundsGEP2_32(type, src, 0, idx++); - LoadInst *load = builder->CreateLoad(ptr); + LoadInst *load = builder->CreateLoad(ptr->getType()->getPointerElementType(), ptr); dst.push(b.first + ".buffer", load); load->setName(b.first + ".buffer"); } diff --git a/src/CodeGen_LLVM.cpp b/src/CodeGen_LLVM.cpp index bced1536dde2..133f5d20f779 100644 --- a/src/CodeGen_LLVM.cpp +++ b/src/CodeGen_LLVM.cpp @@ -905,14 +905,14 @@ llvm::Function *CodeGen_LLVM::add_argv_wrapper(llvm::Function *fn, for (llvm::Function::arg_iterator i = fn->arg_begin(); i != fn->arg_end(); i++) { // Get the address of the nth argument llvm::Value *ptr = builder->CreateConstGEP1_32(arg_array, wrapper_args.size()); - ptr = builder->CreateLoad(ptr); + ptr = builder->CreateLoad(ptr->getType()->getPointerElementType(), ptr); if (i->getType() == halide_buffer_t_type->getPointerTo()) { // Cast the argument to a halide_buffer_t * wrapper_args.push_back(builder->CreatePointerCast(ptr, halide_buffer_t_type->getPointerTo())); } else { // Cast to the appropriate type and load ptr = builder->CreatePointerCast(ptr, i->getType()->getPointerTo()); - wrapper_args.push_back(builder->CreateLoad(ptr)); + wrapper_args.push_back(builder->CreateLoad(ptr->getType()->getPointerElementType(), ptr)); } } debug(4) << "Creating call from wrapper to actual function\n"; @@ -923,7 +923,7 @@ llvm::Function *CodeGen_LLVM::add_argv_wrapper(llvm::Function *fn, if (result_in_argv) { llvm::Value *result_in_argv_ptr = builder->CreateConstGEP1_32(arg_array, wrapper_args.size()); if (fn->getReturnType() != void_t) { - result_in_argv_ptr = builder->CreateLoad(result_in_argv_ptr); + result_in_argv_ptr = builder->CreateLoad(result_in_argv_ptr->getType()->getPointerElementType(), result_in_argv_ptr); // Cast to the appropriate type and store result_in_argv_ptr = builder->CreatePointerCast(result_in_argv_ptr, fn->getReturnType()->getPointerTo()); builder->CreateStore(result, result_in_argv_ptr); @@ -1901,7 +1901,7 @@ void CodeGen_LLVM::visit(const Load *op) { if (op->type.is_scalar()) { // Scalar loads Value *ptr = codegen_buffer_pointer(op->name, op->type, op->index); - LoadInst *load = builder->CreateAlignedLoad(ptr, llvm::Align(op->type.bytes())); + LoadInst *load = builder->CreateAlignedLoad(ptr->getType()->getPointerElementType(), ptr, llvm::Align(op->type.bytes())); add_tbaa_metadata(load, op->name, op->index); value = load; } else { @@ -1996,7 +1996,7 @@ void CodeGen_LLVM::visit(const Load *op) { value = UndefValue::get(llvm_type_of(op->type)); for (int i = 0; i < ramp->lanes; i++) { Value *lane = ConstantInt::get(i32_t, i); - LoadInst *val = builder->CreateLoad(ptr); + LoadInst *val = builder->CreateLoad(ptr->getType()->getPointerElementType(), ptr); add_tbaa_metadata(val, op->name, op->index); value = builder->CreateInsertElement(value, val, lane); ptr = builder->CreateInBoundsGEP(ptr, stride); @@ -2011,7 +2011,7 @@ void CodeGen_LLVM::visit(const Load *op) { for (int i = 0; i < op->type.lanes(); i++) { Expr idx = extract_lane(op->index, i); Value *ptr = codegen_buffer_pointer(op->name, op->type.element_of(), idx); - LoadInst *val = builder->CreateLoad(ptr); + LoadInst *val = builder->CreateLoad(ptr->getType()->getPointerElementType(), ptr); add_tbaa_metadata(val, op->name, op->index); vec = builder->CreateInsertElement(vec, val, ConstantInt::get(i32_t, i)); } @@ -2023,7 +2023,7 @@ void CodeGen_LLVM::visit(const Load *op) { for (int i = 0; i < op->type.lanes(); i++) { Value *idx = builder->CreateExtractElement(index, ConstantInt::get(i32_t, i)); Value *ptr = codegen_buffer_pointer(op->name, op->type.element_of(), idx); - LoadInst *val = builder->CreateLoad(ptr); + LoadInst *val = builder->CreateLoad(ptr->getType()->getPointerElementType(), ptr); add_tbaa_metadata(val, op->name, op->index); vec = builder->CreateInsertElement(vec, val, ConstantInt::get(i32_t, i)); } @@ -2315,7 +2315,7 @@ llvm::Value *CodeGen_LLVM::codegen_dense_vector_load(const Type &type, const std load_inst = builder->CreateMaskedLoad(vec_ptr, align_bytes, slice_mask); #endif } else { - load_inst = builder->CreateAlignedLoad(vec_ptr, llvm::Align(align_bytes)); + load_inst = builder->CreateAlignedLoad(vec_ptr->getType()->getPointerElementType(), vec_ptr, llvm::Align(align_bytes)); } add_tbaa_metadata(load_inst, name, slice_index); slices.push_back(load_inst); @@ -2469,7 +2469,7 @@ void CodeGen_LLVM::codegen_atomic_store(const Store *op) { Value *idx = builder->CreateExtractElement(vec_index, ConstantInt::get(i32_t, lane_id)); ptr = codegen_buffer_pointer(op->name, value_type.element_of(), idx); } - LoadInst *orig = builder->CreateAlignedLoad(ptr, llvm::Align(value_type.bytes())); + LoadInst *orig = builder->CreateAlignedLoad(ptr->getType()->getPointerElementType(), ptr, llvm::Align(value_type.bytes())); orig->setOrdering(AtomicOrdering::Monotonic); add_tbaa_metadata(orig, op->name, op->index); // Explicit fall through from the current block to the cas loop body. @@ -3068,7 +3068,7 @@ void CodeGen_LLVM::visit(const Call *op) { GlobalValue::PrivateLinkage, ConstantPointerNull::get(base_fn->getType()), global_name); - LoadInst *loaded_value = builder->CreateLoad(global); + LoadInst *loaded_value = builder->CreateLoad(global->getType()->getPointerElementType(), global); BasicBlock *global_inited_bb = BasicBlock::Create(*context, "global_inited_bb", function); BasicBlock *global_not_inited_bb = BasicBlock::Create(*context, "global_not_inited_bb", function);