summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2012-10-27 15:18:28 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2012-10-27 15:18:28 +0000
commitbadffcf8fddf3978acf9843a43e66766e9e830c6 (patch)
tree14095ac554d0100cdb8f797d6d44b409b8641c37
parentd11c5d08a5f4f030d6e357378d0d46d93efd9a59 (diff)
downloadexternal_llvm-badffcf8fddf3978acf9843a43e66766e9e830c6.zip
external_llvm-badffcf8fddf3978acf9843a43e66766e9e830c6.tar.gz
external_llvm-badffcf8fddf3978acf9843a43e66766e9e830c6.tar.bz2
LoopIdiom: Add checks to avoid turning memmove into an infinite loop.
I don't think this is possible with the current implementation but that may change eventually. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166877 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Scalar/LoopIdiomRecognize.cpp4
-rw-r--r--test/Transforms/LoopIdiom/memset_noidiom.ll53
2 files changed, 54 insertions, 3 deletions
diff --git a/lib/Transforms/Scalar/LoopIdiomRecognize.cpp b/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
index 495d403..bc8ae66 100644
--- a/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
+++ b/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
@@ -178,7 +178,7 @@ bool LoopIdiomRecognize::runOnLoop(Loop *L, LPPassManager &LPM) {
// Disable loop idiom recognition if the function's name is a common idiom.
StringRef Name = L->getHeader()->getParent()->getName();
- if (Name == "memset" || Name == "memcpy")
+ if (Name == "memset" || Name == "memcpy" || Name == "memmove")
return false;
// The trip count of the loop must be analyzable.
@@ -524,7 +524,7 @@ processLoopStoreOfLoopLoad(StoreInst *SI, unsigned StoreSize,
const SCEVAddRecExpr *LoadEv,
const SCEV *BECount) {
// If we're not allowed to form memcpy, we fail.
- if (!TLI->has(LibFunc::memcpy))
+ if (!TLI->has(LibFunc::memcpy) || !TLI->has(LibFunc::memmove))
return false;
LoadInst *LI = cast<LoadInst>(SI->getValueOperand());
diff --git a/test/Transforms/LoopIdiom/memset_noidiom.ll b/test/Transforms/LoopIdiom/memset_noidiom.ll
index 168eb95..27ef4f6 100644
--- a/test/Transforms/LoopIdiom/memset_noidiom.ll
+++ b/test/Transforms/LoopIdiom/memset_noidiom.ll
@@ -1,4 +1,4 @@
-; RUN: opt -loop-idiom < %s -S | FileCheck %s
+; RUN: opt -basicaa -loop-idiom < %s -S | FileCheck %s
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
target triple = "x86_64-apple-darwin10.0.0"
@@ -28,3 +28,54 @@ for.end: ; preds = %for.cond.for.end_cr
ret i8* %b
}
+; CHECK: @memcpy
+; CHECK-NOT: llvm.memcpy
+define i8* @memcpy(i8* noalias %dst, i8* noalias %src, i64 %n) nounwind {
+entry:
+ %tobool3 = icmp eq i64 %n, 0
+ br i1 %tobool3, label %while.end, label %while.body
+
+while.body: ; preds = %entry, %while.body
+ %c2.06 = phi i8* [ %incdec.ptr, %while.body ], [ %src, %entry ]
+ %c1.05 = phi i8* [ %incdec.ptr1, %while.body ], [ %dst, %entry ]
+ %n.addr.04 = phi i64 [ %dec, %while.body ], [ %n, %entry ]
+ %dec = add i64 %n.addr.04, -1
+ %incdec.ptr = getelementptr inbounds i8* %c2.06, i64 1
+ %0 = load i8* %c2.06, align 1
+ %incdec.ptr1 = getelementptr inbounds i8* %c1.05, i64 1
+ store i8 %0, i8* %c1.05, align 1
+ %tobool = icmp eq i64 %dec, 0
+ br i1 %tobool, label %while.end, label %while.body
+
+while.end: ; preds = %while.body, %entry
+ ret i8* %dst
+}
+
+; CHECK: @memmove
+; CHECK-NOT: llvm.memmove
+define i8* @memmove(i8* %dst, i8* nocapture %src, i64 %count) nounwind {
+entry:
+ %sub = add i64 %count, -1
+ %tobool9 = icmp eq i64 %count, 0
+ br i1 %tobool9, label %while.end, label %while.body.lr.ph
+
+while.body.lr.ph: ; preds = %entry
+ %add.ptr2 = getelementptr inbounds i8* %src, i64 %sub
+ %add.ptr = getelementptr inbounds i8* %dst, i64 %sub
+ br label %while.body
+
+while.body: ; preds = %while.body.lr.ph, %while.body
+ %b.012 = phi i8* [ %add.ptr2, %while.body.lr.ph ], [ %incdec.ptr, %while.body ]
+ %a.011 = phi i8* [ %add.ptr, %while.body.lr.ph ], [ %incdec.ptr3, %while.body ]
+ %count.addr.010 = phi i64 [ %count, %while.body.lr.ph ], [ %dec, %while.body ]
+ %dec = add i64 %count.addr.010, -1
+ %incdec.ptr = getelementptr inbounds i8* %b.012, i64 -1
+ %0 = load i8* %b.012, align 1
+ %incdec.ptr3 = getelementptr inbounds i8* %a.011, i64 -1
+ store i8 %0, i8* %a.011, align 1
+ %tobool = icmp eq i64 %dec, 0
+ br i1 %tobool, label %while.end, label %while.body
+
+while.end: ; preds = %while.body, %entry
+ ret i8* %dst
+}