@@ -795,19 +795,21 @@ static Value *emit_nthptr_addr(jl_codectx_t &ctx, Value *v, Value *idx)
795795 idx);
796796}
797797
798- static LoadInst *emit_nthptr_recast (jl_codectx_t &ctx, Value *v, Value *idx, MDNode *tbaa, Type *ptype )
798+ static LoadInst *emit_nthptr_recast (jl_codectx_t &ctx, Value *v, Value *idx, MDNode *tbaa, Type *type )
799799{
800- // p = (jl_value_t**)v; *(ptype )&p[n]
800+ // p = (jl_value_t**)v; *(type* )&p[n]
801801 Value *vptr = emit_nthptr_addr (ctx, v, idx);
802- return cast<LoadInst>(tbaa_decorate (tbaa, ctx.builder .CreateLoad (emit_bitcast (ctx, vptr, ptype))));
802+ return cast<LoadInst>(tbaa_decorate (tbaa, ctx.builder .CreateLoad (type,
803+ emit_bitcast (ctx, vptr, PointerType::get (type, 0 )))));
803804}
804805
805- static LoadInst *emit_nthptr_recast (jl_codectx_t &ctx, Value *v, ssize_t n, MDNode *tbaa, Type *ptype )
806+ static LoadInst *emit_nthptr_recast (jl_codectx_t &ctx, Value *v, ssize_t n, MDNode *tbaa, Type *type )
806807{
807- // p = (jl_value_t**)v; *(ptype )&p[n]
808+ // p = (jl_value_t**)v; *(type* )&p[n]
808809 Value *vptr = emit_nthptr_addr (ctx, v, n);
809- return cast<LoadInst>(tbaa_decorate (tbaa, ctx.builder .CreateLoad (emit_bitcast (ctx, vptr, ptype))));
810- }
810+ return cast<LoadInst>(tbaa_decorate (tbaa, ctx.builder .CreateLoad (type,
811+ emit_bitcast (ctx, vptr, PointerType::get (type, 0 )))));
812+ }
811813
812814static Value *boxed (jl_codectx_t &ctx, const jl_cgval_t &v);
813815
@@ -1506,7 +1508,7 @@ static jl_cgval_t typed_load(jl_codectx_t &ctx, Value *ptr, Value *idx_0based, j
15061508 alignment = sizeof (void *);
15071509 else if (!alignment)
15081510 alignment = julia_alignment (jltype);
1509- LoadInst *load = ctx.builder .CreateAlignedLoad (data, Align (alignment), false );
1511+ LoadInst *load = ctx.builder .CreateAlignedLoad (elty, data, Align (alignment), false );
15101512 load->setOrdering (Order);
15111513 if (aliasscope)
15121514 load->setMetadata (" alias.scope" , aliasscope);
@@ -1519,7 +1521,7 @@ static jl_cgval_t typed_load(jl_codectx_t &ctx, Value *ptr, Value *idx_0based, j
15191521 instr = ctx.builder .CreateTrunc (instr, realelty);
15201522 if (intcast) {
15211523 ctx.builder .CreateStore (instr, ctx.builder .CreateBitCast (intcast, instr->getType ()->getPointerTo ()));
1522- instr = ctx.builder .CreateLoad (intcast);
1524+ instr = ctx.builder .CreateLoad (intcast-> getAllocatedType (), intcast );
15231525 }
15241526 if (maybe_null_if_boxed) {
15251527 Value *first_ptr = isboxed ? instr : extract_first_ptr (ctx, instr);
@@ -1586,7 +1588,7 @@ static jl_cgval_t typed_store(jl_codectx_t &ctx,
15861588 return emit_new_struct (ctx, (jl_value_t *)rettyp, 2 , argv);
15871589 }
15881590 }
1589- Value *intcast = nullptr ;
1591+ AllocaInst *intcast = nullptr ;
15901592 if (!isboxed && Order != AtomicOrdering::NotAtomic && !elty->isIntOrPtrTy ()) {
15911593 const DataLayout &DL = jl_data_layout;
15921594 unsigned nb = DL.getTypeSizeInBits (elty);
@@ -1736,7 +1738,7 @@ static jl_cgval_t typed_store(jl_codectx_t &ctx,
17361738 if (intcast) {
17371739 ctx.builder .CreateStore (realCompare, ctx.builder .CreateBitCast (intcast, realCompare->getType ()->getPointerTo ()));
17381740 if (maybe_null_if_boxed)
1739- realCompare = ctx.builder .CreateLoad (intcast);
1741+ realCompare = ctx.builder .CreateLoad (intcast-> getAllocatedType (), intcast );
17401742 }
17411743 if (maybe_null_if_boxed) {
17421744 Value *first_ptr = isboxed ? Compare : extract_first_ptr (ctx, Compare);
@@ -1816,7 +1818,7 @@ static jl_cgval_t typed_store(jl_codectx_t &ctx,
18161818 ctx.builder .CreateStore (realinstr, ctx.builder .CreateBitCast (intcast, realinstr->getType ()->getPointerTo ()));
18171819 oldval = mark_julia_slot (intcast, jltype, NULL , tbaa_stack);
18181820 if (maybe_null_if_boxed)
1819- realinstr = ctx.builder .CreateLoad (intcast);
1821+ realinstr = ctx.builder .CreateLoad (intcast-> getAllocatedType (), intcast );
18201822 }
18211823 else {
18221824 oldval = mark_julia_type (ctx, realinstr, isboxed, jltype);
@@ -1876,7 +1878,7 @@ static jl_cgval_t typed_store(jl_codectx_t &ctx,
18761878 instr = ctx.builder .Insert (CastInst::Create (Instruction::Trunc, instr, realelty));
18771879 if (intcast) {
18781880 ctx.builder .CreateStore (instr, ctx.builder .CreateBitCast (intcast, instr->getType ()->getPointerTo ()));
1879- instr = ctx.builder .CreateLoad (intcast);
1881+ instr = ctx.builder .CreateLoad (intcast-> getAllocatedType (), intcast );
18801882 }
18811883 if (maybe_null_if_boxed) {
18821884 Value *first_ptr = isboxed ? instr : extract_first_ptr (ctx, instr);
@@ -1949,18 +1951,18 @@ static void emit_memcpy_llvm(jl_codectx_t &ctx, Value *dst, MDNode *tbaa_dst, Va
19491951 dstty = dstel->getPointerTo ();
19501952 }
19511953
1952- bool direct = false ;
1954+ llvm::Type *directel = nullptr ;
19531955 if (srcel->isSized () && srcel->isSingleValueType () && DL.getTypeStoreSize (srcel) == sz) {
1954- direct = true ;
1956+ directel = srcel ;
19551957 dst = emit_bitcast (ctx, dst, srcty);
19561958 }
19571959 else if (dstel->isSized () && dstel->isSingleValueType () &&
19581960 DL.getTypeStoreSize (dstel) == sz) {
1959- direct = true ;
1961+ directel = dstel ;
19601962 src = emit_bitcast (ctx, src, dstty);
19611963 }
1962- if (direct ) {
1963- auto val = tbaa_decorate (tbaa_src, ctx.builder .CreateAlignedLoad (src, Align (align), is_volatile));
1964+ if (directel ) {
1965+ auto val = tbaa_decorate (tbaa_src, ctx.builder .CreateAlignedLoad (directel, src, Align (align), is_volatile));
19641966 tbaa_decorate (tbaa_dst, ctx.builder .CreateAlignedStore (val, dst, Align (align), is_volatile));
19651967 return ;
19661968 }
@@ -2430,7 +2432,7 @@ static Value *emit_arraysize(jl_codectx_t &ctx, const jl_cgval_t &tinfo, Value *
24302432 auto load = emit_nthptr_recast (ctx,
24312433 t,
24322434 ctx.builder .CreateAdd (dim, ConstantInt::get (dim->getType (), o)),
2433- tbaa, T_psize );
2435+ tbaa, T_size );
24342436 MDBuilder MDB (jl_LLVMContext);
24352437 auto rng = MDB.createRange (V_size0, ConstantInt::get (T_size, arraytype_maxsize (tinfo.typ )));
24362438 load->setMetadata (LLVMContext::MD_range, rng);
@@ -2466,7 +2468,7 @@ static Value *emit_arraylen_prim(jl_codectx_t &ctx, const jl_cgval_t &tinfo)
24662468 Value *addr = ctx.builder .CreateStructGEP (jl_array_llvmt,
24672469 emit_bitcast (ctx, decay_derived (ctx, t), jl_parray_llvmt),
24682470 1 ); // index (not offset) of length field in jl_parray_llvmt
2469- LoadInst *len = ctx.builder .CreateAlignedLoad (addr, Align (sizeof (size_t )));
2471+ LoadInst *len = ctx.builder .CreateAlignedLoad (T_size, addr, Align (sizeof (size_t )));
24702472 len->setOrdering (AtomicOrdering::NotAtomic);
24712473 MDBuilder MDB (jl_LLVMContext);
24722474 auto rng = MDB.createRange (V_size0, ConstantInt::get (T_size, arraytype_maxsize (tinfo.typ )));
@@ -2519,7 +2521,8 @@ static Value *emit_arrayptr_internal(jl_codectx_t &ctx, const jl_cgval_t &tinfo,
25192521 PointerType::get (PPT->getElementType (), AS),
25202522 PT->getAddressSpace ()));
25212523 }
2522- LoadInst *LI = ctx.builder .CreateAlignedLoad (addr, Align (sizeof (char *)));
2524+ LoadInst *LI = ctx.builder .CreateAlignedLoad (
2525+ cast<PointerType>(addr->getType ())->getElementType (), addr, Align (sizeof (char *)));
25232526 LI->setOrdering (AtomicOrdering::NotAtomic);
25242527 LI->setMetadata (LLVMContext::MD_nonnull, MDNode::get (jl_LLVMContext, None));
25252528 tbaa_decorate (tbaa, LI);
@@ -2828,9 +2831,9 @@ static Value *as_value(jl_codectx_t &ctx, Type *to, const jl_cgval_t &v)
28282831static Value *load_i8box (jl_codectx_t &ctx, Value *v, jl_datatype_t *ty)
28292832{
28302833 auto jvar = ty == jl_int8_type ? jlboxed_int8_cache : jlboxed_uint8_cache;
2831- Constant *gv = prepare_global_in (jl_Module, jvar);
2834+ GlobalVariable *gv = prepare_global_in (jl_Module, jvar);
28322835 Value *idx[] = {ConstantInt::get (T_int32, 0 ), ctx.builder .CreateZExt (v, T_int32)};
2833- auto slot = ctx.builder .CreateInBoundsGEP (gv, idx);
2836+ auto slot = ctx.builder .CreateInBoundsGEP (gv-> getType ()-> getElementType (), gv , idx);
28342837 return tbaa_decorate (tbaa_const, maybe_mark_load_dereferenceable (
28352838 ctx.builder .CreateAlignedLoad (T_pjlvalue, slot, Align (sizeof (void *))), false ,
28362839 (jl_value_t *)ty));
0 commit comments