LoopIdiom: Fix a serious missed optimization: we only turned top-level loops into memmove.
Thanks to Preston Briggs for catching this!
llvm-svn: 167045
diff --git a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
index bc8ae66..249cb9d 100644
--- a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
@@ -555,10 +555,11 @@
// can safely emit a memcpy.
OwningPtr<Dependence> Dep(DA.depends(SI, LI, true));
if (Dep) {
- // If there is a dependence but the direction is positive we can still
- // safely turn this into memmove.
- if (Dep->getLevels() != 1 ||
- Dep->getDirection(1) != Dependence::DVEntry::GT)
+ // If there is a dependence but the direction is positive (or none) we can
+ // still safely turn this into memmove.
+ unsigned Direction = Dep->getDirection(Dep->getLevels());
+ if (Direction != Dependence::DVEntry::NONE &&
+ Direction != Dependence::DVEntry::GT)
return false;
isMemcpySafe = false;
}