[PATCH] D86725: [MemLoc] Support memcmp in MemoryLocation::getForArgument.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 27 09:45:22 PDT 2020
fhahn created this revision.
fhahn added reviewers: sanjoy, hfinkel, efriedma, asbirlea.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
fhahn requested review of this revision.
This patch adds support for memcmp in MemoryLocation::getForArgument.
memcmp reads from the first 2 arguments up to the number of bytes of the
third argument.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D86725
Files:
llvm/lib/Analysis/MemoryLocation.cpp
llvm/test/Analysis/BasicAA/libfuncs.ll
llvm/test/Transforms/DeadStoreElimination/MSSA/libcalls.ll
Index: llvm/test/Transforms/DeadStoreElimination/MSSA/libcalls.ll
===================================================================
--- llvm/test/Transforms/DeadStoreElimination/MSSA/libcalls.ll
+++ llvm/test/Transforms/DeadStoreElimination/MSSA/libcalls.ll
@@ -85,10 +85,6 @@
; CHECK-NEXT: store i8 49, i8* [[STACK_PTR]], align 1
; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr i8, i8* [[STACK_PTR]], i64 1
; CHECK-NEXT: store i8 50, i8* [[GEP_1]], align 1
-; CHECK-NEXT: [[GEP_2:%.*]] = getelementptr i8, i8* [[STACK_PTR]], i64 2
-; CHECK-NEXT: store i8 51, i8* [[GEP_2]], align 1
-; CHECK-NEXT: [[GEP_3:%.*]] = getelementptr i8, i8* [[STACK_PTR]], i64 3
-; CHECK-NEXT: store i8 52, i8* [[GEP_3]], align 1
; CHECK-NEXT: [[RES:%.*]] = call i32 @memcmp(i8* nonnull dereferenceable(2) [[FOO:%.*]], i8* nonnull dereferenceable(2) [[STACK_PTR]], i64 2)
; CHECK-NEXT: ret i32 [[RES]]
;
Index: llvm/test/Analysis/BasicAA/libfuncs.ll
===================================================================
--- llvm/test/Analysis/BasicAA/libfuncs.ll
+++ llvm/test/Analysis/BasicAA/libfuncs.ll
@@ -7,9 +7,9 @@
; CHECK: Just Ref: Ptr: i8* %a <-> %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 4)
; CHECK-NEXT: Just Ref: Ptr: i8* %b <-> %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 4)
; CHECK-NEXT: Just Ref: Ptr: i8* %a.gep.1 <-> %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 4)
-; CHECK-NEXT: Just Ref: Ptr: i8* %a.gep.5 <-> %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 4)
+; CHECK-NEXT: NoModRef: Ptr: i8* %a.gep.5 <-> %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 4)
; CHECK-NEXT: Just Ref: Ptr: i8* %b.gep.1 <-> %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 4)
-; CHECK-NEXT: Just Ref: Ptr: i8* %b.gep.5 <-> %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 4)
+; CHECK-NEXT: NoModRef: Ptr: i8* %b.gep.5 <-> %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 4)
define i32 @test_memcmp_const_size(i8* noalias %a, i8* noalias %b) {
entry:
%res = tail call i32 @memcmp(i8* %a, i8* %b, i64 4)
Index: llvm/lib/Analysis/MemoryLocation.cpp
===================================================================
--- llvm/lib/Analysis/MemoryLocation.cpp
+++ llvm/lib/Analysis/MemoryLocation.cpp
@@ -211,16 +211,29 @@
// whenever possible.
LibFunc F;
if (TLI && Call->getCalledFunction() &&
- TLI->getLibFunc(*Call->getCalledFunction(), F) &&
- F == LibFunc_memset_pattern16 && TLI->has(F)) {
- assert((ArgIdx == 0 || ArgIdx == 1) &&
- "Invalid argument index for memset_pattern16");
- if (ArgIdx == 1)
- return MemoryLocation(Arg, LocationSize::precise(16), AATags);
- if (const ConstantInt *LenCI =
- dyn_cast<ConstantInt>(Call->getArgOperand(2)))
- return MemoryLocation(Arg, LocationSize::precise(LenCI->getZExtValue()),
- AATags);
+ TLI->getLibFunc(*Call->getCalledFunction(), F) && TLI->has(F)) {
+ switch (F) {
+ case LibFunc_memset_pattern16:
+ assert((ArgIdx == 0 || ArgIdx == 1) &&
+ "Invalid argument index for memset_pattern16");
+ if (ArgIdx == 1)
+ return MemoryLocation(Arg, LocationSize::precise(16), AATags);
+ if (const ConstantInt *LenCI =
+ dyn_cast<ConstantInt>(Call->getArgOperand(2)))
+ return MemoryLocation(Arg, LocationSize::precise(LenCI->getZExtValue()),
+ AATags);
+ break;
+ case LibFunc_memcmp:
+ assert((ArgIdx == 0 || ArgIdx == 1) &&
+ "Invalid argument index for memcmp");
+ if (const ConstantInt *LenCI =
+ dyn_cast<ConstantInt>(Call->getArgOperand(2)))
+ return MemoryLocation(Arg, LocationSize::precise(LenCI->getZExtValue()),
+ AATags);
+ break;
+ default:
+ break;
+ };
}
// FIXME: Handle memset_pattern4 and memset_pattern8 also.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86725.288372.patch
Type: text/x-patch
Size: 3909 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200827/20b7c234/attachment.bin>
More information about the llvm-commits
mailing list