Skip to content

Commit 2ec52b4

Browse files
committed
Change memory indexing to use the type as index instead of i8, also add nsw/nuw flags whenever possible.
1 parent 40fbc88 commit 2ec52b4

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/cgutils.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -4671,7 +4671,7 @@ static jl_cgval_t emit_memoryref(jl_codectx_t &ctx, const jl_cgval_t &ref, jl_cg
46714671
bool isunion = layout->flags.arrayelem_isunion;
46724672
bool isghost = layout->size == 0;
46734673
if ((!isboxed && isunion) || isghost) {
4674-
newdata = ctx.builder.CreateAdd(data, offset);
4674+
newdata = ctx.builder.CreateAdd(data, offset, "", true, true);
46754675
setName(ctx.emission_context, newdata, "memoryref_data+offset");
46764676
if (bc) {
46774677
BasicBlock *failBB, *endBB;
@@ -4710,10 +4710,9 @@ static jl_cgval_t emit_memoryref(jl_codectx_t &ctx, const jl_cgval_t &ref, jl_cg
47104710
setName(ctx.emission_context, ovflw, "memoryref_ovflw");
47114711
}
47124712
#endif
4713-
boffset = ctx.builder.CreateMul(offset, elsz);
4714-
setName(ctx.emission_context, boffset, "memoryref_byteoffset");
4715-
newdata = ctx.builder.CreateGEP(getInt8Ty(ctx.builder.getContext()), data, boffset);
4716-
setName(ctx.emission_context, newdata, "memoryref_data_byteoffset");
4713+
Type *elty = isboxed ? ctx.types().T_prjlvalue : julia_type_to_llvm(ctx, jl_tparam1(ref.typ));
4714+
newdata = ctx.builder.CreateGEP(elty, data, offset);
4715+
setName(ctx.emission_context, newdata, "memoryref_data_offset");
47174716
(void)boffset; // LLVM is very bad at handling GEP with types different from the load
47184717
if (bc) {
47194718
BasicBlock *failBB, *endBB;

0 commit comments

Comments
 (0)