[llvm] r284630 - [AliasSetTracker] Add support for memcpy and memmove.
Chad Rosier via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 19 12:09:03 PDT 2016
Author: mcrosier
Date: Wed Oct 19 14:09:03 2016
New Revision: 284630
URL: http://llvm.org/viewvc/llvm-project?rev=284630&view=rev
Log:
[AliasSetTracker] Add support for memcpy and memmove.
Differential Revision: https://reviews.llvm.org/D25776
Added:
llvm/trunk/test/Analysis/AliasSet/memtransfer.ll
Modified:
llvm/trunk/include/llvm/Analysis/AliasSetTracker.h
llvm/trunk/lib/Analysis/AliasSetTracker.cpp
Modified: llvm/trunk/include/llvm/Analysis/AliasSetTracker.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/AliasSetTracker.h?rev=284630&r1=284629&r2=284630&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/AliasSetTracker.h (original)
+++ llvm/trunk/include/llvm/Analysis/AliasSetTracker.h Wed Oct 19 14:09:03 2016
@@ -349,6 +349,7 @@ public:
void add(StoreInst *SI);
void add(VAArgInst *VAAI);
void add(MemSetInst *MSI);
+ void add(MemTransferInst *MTI);
void add(Instruction *I); // Dispatch to one of the other add methods...
void add(BasicBlock &BB); // Add all instructions in basic block
void add(const AliasSetTracker &AST); // Add alias relations from another AST
Modified: llvm/trunk/lib/Analysis/AliasSetTracker.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/AliasSetTracker.cpp?rev=284630&r1=284629&r2=284630&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/AliasSetTracker.cpp (original)
+++ llvm/trunk/lib/Analysis/AliasSetTracker.cpp Wed Oct 19 14:09:03 2016
@@ -389,6 +389,27 @@ void AliasSetTracker::add(MemSetInst *MS
AS.setVolatile();
}
+void AliasSetTracker::add(MemTransferInst *MTI) {
+ AAMDNodes AAInfo;
+ MTI->getAAMetadata(AAInfo);
+
+ uint64_t Len;
+ if (ConstantInt *C = dyn_cast<ConstantInt>(MTI->getLength()))
+ Len = C->getZExtValue();
+ else
+ Len = MemoryLocation::UnknownSize;
+
+ AliasSet &ASSrc =
+ addPointer(MTI->getRawSource(), Len, AAInfo, AliasSet::RefAccess);
+ if (MTI->isVolatile())
+ ASSrc.setVolatile();
+
+ AliasSet &ASDst =
+ addPointer(MTI->getRawDest(), Len, AAInfo, AliasSet::ModAccess);
+ if (MTI->isVolatile())
+ ASDst.setVolatile();
+}
+
void AliasSetTracker::addUnknown(Instruction *Inst) {
if (isa<DbgInfoIntrinsic>(Inst))
return; // Ignore DbgInfo Intrinsics.
@@ -415,8 +436,9 @@ void AliasSetTracker::add(Instruction *I
return add(VAAI);
if (MemSetInst *MSI = dyn_cast<MemSetInst>(I))
return add(MSI);
+ if (MemTransferInst *MTI = dyn_cast<MemTransferInst>(I))
+ return add(MTI);
return addUnknown(I);
- // FIXME: add support of memcpy and memmove.
}
void AliasSetTracker::add(BasicBlock &BB) {
Added: llvm/trunk/test/Analysis/AliasSet/memtransfer.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/AliasSet/memtransfer.ll?rev=284630&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/AliasSet/memtransfer.ll (added)
+++ llvm/trunk/test/Analysis/AliasSet/memtransfer.ll Wed Oct 19 14:09:03 2016
@@ -0,0 +1,114 @@
+; RUN: opt -basicaa -print-alias-sets -S -o - < %s 2>&1 | FileCheck %s
+
+ at s = global i8 1, align 1
+ at d = global i8 2, align 1
+
+; CHECK: Alias sets for function 'test1':
+; CHECK: Alias Set Tracker: 3 alias sets for 4 pointer values.
+; CHECK: AliasSet[0x{{[0-9a-f]+}}, 1] must alias, Mod Pointers: (i8* %a, 1)
+; CHECK-NOT: 1 Unknown instructions
+; CHECK: AliasSet[0x{{[0-9a-f]+}}, 2] may alias, Mod/Ref Pointers: (i8* %s, 1), (i8* %d, 1)
+; CHECK: AliasSet[0x{{[0-9a-f]+}}, 1] must alias, Mod Pointers: (i8* %b, 1)
+define void @test1(i8* %s, i8* %d) {
+entry:
+ %a = alloca i8, align 1
+ %b = alloca i8, align 1
+ store i8 1, i8* %a, align 1
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* %d, i8* %s, i64 1, i32 1, i1 false)
+ store i8 1, i8* %b, align 1
+ ret void
+}
+
+; CHECK: Alias sets for function 'test2':
+; CHECK: Alias Set Tracker: 3 alias sets for 4 pointer values.
+; CHECK: AliasSet[0x{{[0-9a-f]+}}, 1] must alias, Mod Pointers: (i8* %a, 1)
+; CHECK-NOT: 1 Unknown instructions
+; CHECK: AliasSet[0x{{[0-9a-f]+}}, 2] may alias, Mod/Ref [volatile] Pointers: (i8* %s, 1), (i8* %d, 1)
+; CHECK: AliasSet[0x{{[0-9a-f]+}}, 1] must alias, Mod Pointers: (i8* %b, 1)
+define void @test2(i8* %s, i8* %d) {
+entry:
+ %a = alloca i8, align 1
+ %b = alloca i8, align 1
+ store i8 1, i8* %a, align 1
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* %d, i8* %s, i64 1, i32 1, i1 true)
+ store i8 1, i8* %b, align 1
+ ret void
+}
+
+; CHECK: Alias sets for function 'test3':
+; CHECK: Alias Set Tracker: 3 alias sets for 4 pointer values.
+; CHECK: AliasSet[0x{{[0-9a-f]+}}, 1] must alias, Mod Pointers: (i8* %a, 1)
+; CHECK-NOT: 1 Unknown instructions
+; CHECK: AliasSet[0x{{[0-9a-f]+}}, 2] may alias, Mod/Ref Pointers: (i8* %s, 1), (i8* %d, 1)
+; CHECK: AliasSet[0x{{[0-9a-f]+}}, 1] must alias, Mod Pointers: (i8* %b, 1)
+define void @test3(i8* %s, i8* %d) {
+entry:
+ %a = alloca i8, align 1
+ %b = alloca i8, align 1
+ store i8 1, i8* %a, align 1
+ call void @llvm.memmove.p0i8.p0i8.i64(i8* %d, i8* %s, i64 1, i32 1, i1 false)
+ store i8 1, i8* %b, align 1
+ ret void
+}
+
+; CHECK: Alias sets for function 'test4':
+; CHECK: Alias Set Tracker: 3 alias sets for 4 pointer values.
+; CHECK: AliasSet[0x{{[0-9a-f]+}}, 1] must alias, Mod Pointers: (i8* %a, 1)
+; CHECK-NOT: 1 Unknown instructions
+; CHECK: AliasSet[0x{{[0-9a-f]+}}, 2] may alias, Mod/Ref [volatile] Pointers: (i8* %s, 1), (i8* %d, 1)
+; CHECK: AliasSet[0x{{[0-9a-f]+}}, 1] must alias, Mod Pointers: (i8* %b, 1)
+define void @test4(i8* %s, i8* %d) {
+entry:
+ %a = alloca i8, align 1
+ %b = alloca i8, align 1
+ store i8 1, i8* %a, align 1
+ call void @llvm.memmove.p0i8.p0i8.i64(i8* %d, i8* %s, i64 1, i32 1, i1 true)
+ store i8 1, i8* %b, align 1
+ ret void
+}
+
+; CHECK: Alias sets for function 'test5':
+; CHECK: Alias Set Tracker: 2 alias sets for 2 pointer values.
+; CHECK: AliasSet[0x{{[0-9a-f]+}}, 1] must alias, Mod/Ref Pointers: (i8* %a, 1)
+; CHECK: AliasSet[0x{{[0-9a-f]+}}, 1] must alias, Mod Pointers: (i8* %b, 1)
+define void @test5() {
+entry:
+ %a = alloca i8, align 1
+ %b = alloca i8, align 1
+ store i8 1, i8* %a, align 1
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* %b, i8* %a, i64 1, i32 1, i1 false)
+ store i8 1, i8* %b, align 1
+ ret void
+}
+
+; CHECK: Alias sets for function 'test6':
+; CHECK: Alias Set Tracker: 2 alias sets for 2 pointer values.
+; CHECK: AliasSet[0x{{[0-9a-f]+}}, 1] must alias, Mod/Ref Pointers: (i8* %a, 1)
+; CHECK: AliasSet[0x{{[0-9a-f]+}}, 1] must alias, Mod Pointers: (i8* %b, 1)
+define void @test6() {
+entry:
+ %a = alloca i8, align 1
+ %b = alloca i8, align 1
+ store i8 1, i8* %a, align 1
+ call void @llvm.memmove.p0i8.p0i8.i64(i8* %b, i8* %a, i64 1, i32 1, i1 false)
+ store i8 1, i8* %b, align 1
+ ret void
+}
+
+; CHECK: Alias sets for function 'test7':
+; CHECK: Alias Set Tracker: 2 alias sets for 2 pointer values.
+; CHECK: AliasSet[0x{{[0-9a-f]+}}, 1] must alias, Mod/Ref Pointers: (i8* %a, 1)
+; CHECK: AliasSet[0x{{[0-9a-f]+}}, 1] must alias, Mod/Ref Pointers: (i8* %b, 1)
+define void @test7() {
+entry:
+ %a = alloca i8, align 1
+ %b = alloca i8, align 1
+ store i8 1, i8* %a, align 1
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* %b, i8* %a, i64 1, i32 1, i1 false)
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* %a, i8* %b, i64 1, i32 1, i1 false)
+ store i8 1, i8* %b, align 1
+ ret void
+}
+
+declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i32, i1)
+declare void @llvm.memmove.p0i8.p0i8.i64(i8* nocapture, i8* nocapture readonly, i64, i32, i1)
More information about the llvm-commits
mailing list