Skip to content

Commit

Permalink
Fix MemorySSA bug, broken julia-licm test (#49900)
Browse files Browse the repository at this point in the history
  • Loading branch information
pchintalapudi authored May 20, 2023
1 parent 2bb26db commit e169d20
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions src/llvm-julia-licm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ static void eraseInstruction(Instruction &I,
//Stolen and modified from LICM.cpp
static void moveInstructionBefore(Instruction &I, Instruction &Dest,
MemorySSAUpdater &MSSAU,
ScalarEvolution *SE) {
ScalarEvolution *SE,
MemorySSA::InsertionPlace Place = MemorySSA::BeforeTerminator) {
I.moveBefore(&Dest);
if (MSSAU.getMemorySSA())
if (MemoryUseOrDef *OldMemAcc = cast_or_null<MemoryUseOrDef>(
MSSAU.getMemorySSA()->getMemoryAccess(&I)))
MSSAU.moveToPlace(OldMemAcc, Dest.getParent(),
MemorySSA::BeforeTerminator);
Place);
if (SE)
SE->forgetValue(&I);
}
Expand Down Expand Up @@ -227,7 +228,7 @@ struct JuliaLICM : public JuliaPassContext {
continue;
}
++SunkPreserveEnd;
moveInstructionBefore(*call, *exit_pts[0], MSSAU, SE);
moveInstructionBefore(*call, *exit_pts[0], MSSAU, SE, MemorySSA::Beginning);
for (unsigned i = 1; i < exit_pts.size(); i++) {
// Clone exit
auto CI = CallInst::Create(call, {}, exit_pts[i]);
Expand Down Expand Up @@ -290,20 +291,6 @@ struct JuliaLICM : public JuliaPassContext {
}
changed = true;
}
IRBuilder<> builder(preheader->getTerminator());
builder.SetCurrentDebugLocation(call->getDebugLoc());
auto obj_i8 = builder.CreateBitCast(call, Type::getInt8PtrTy(call->getContext(), call->getType()->getPointerAddressSpace()));
// Note that this alignment is assuming the GC allocates at least pointer-aligned memory
auto align = Align(DL.getPointerSize(0));
auto clear_obj = builder.CreateMemSet(obj_i8, ConstantInt::get(Type::getInt8Ty(call->getContext()), 0), call->getArgOperand(1), align);
if (MSSAU.getMemorySSA()) {
auto alloc_mdef = MSSAU.getMemorySSA()->getMemoryAccess(call);
assert(isa<MemoryDef>(alloc_mdef) && "Expected alloc to be associated with a memory def!");
auto clear_mdef = MSSAU.createMemoryAccessAfter(clear_obj, nullptr, alloc_mdef);
assert(isa<MemoryDef>(clear_mdef) && "Expected memset to be associated with a memory def!");
(void) clear_mdef;
}
changed = true;
}
}
}
Expand Down

0 comments on commit e169d20

Please sign in to comment.