Index: lib/Transforms/Utils/LoopRotationUtils.cpp =================================================================== --- lib/Transforms/Utils/LoopRotationUtils.cpp +++ lib/Transforms/Utils/LoopRotationUtils.cpp @@ -334,6 +334,10 @@ !Inst->mayWriteToMemory() && !Inst->isTerminator() && !isa(Inst) && !isa(Inst)) { Inst->moveBefore(LoopEntryBranch); + if (MSSAU) + if (MemoryUseOrDef *MUD = cast_or_null( + MSSAU->getMemorySSA()->getMemoryAccess(Inst))) + MSSAU->moveToPlace(MUD, OrigPreheader, MemorySSA::End); continue; } Index: test/Analysis/MemorySSA/loop-rotate-disablebasicaa.ll =================================================================== --- /dev/null +++ test/Analysis/MemorySSA/loop-rotate-disablebasicaa.ll @@ -0,0 +1,23 @@ +; RUN: opt -disable-basicaa -loop-rotate -enable-mssa-loop-dependency -verify-memoryssa -S < %s | FileCheck %s +; REQUIRES: asserts + +; CHECK-LABEL: @main +define void @main() { +entry: + br label %for.cond120 + +for.cond120: ; preds = %for.body127, %entry + call void @foo() + br i1 undef, label %for.body127, label %for.cond.cleanup126 + +for.cond.cleanup126: ; preds = %for.cond120 + unreachable + +for.body127: ; preds = %for.cond120 + %0 = load i16**, i16*** undef, align 1 + br label %for.cond120 +} + +declare void @foo() readnone + +