[PATCH] D89885: [MemLoc] Adjust memccpy support in MemoryLocation::getForArgument

Dávid Bolvanský via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 21 07:56:17 PDT 2020


xbolva00 created this revision.
xbolva00 added a reviewer: fhahn.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
xbolva00 requested review of this revision.

Based on post-commit feedback by fhahn:

"Thinking about this again, I am not sure if this is a good idea to do for the destination argument, because it gives the impression that exactly `LenCI` bytes are written, when this is not the case.

I think for reads the larger size is the conservative option  and fine, but for writing it could mis-lead clients into thinking the call writes more bytes than it actually does, leading to potentially invalid optimizations."


https://reviews.llvm.org/D89885

Files:
  llvm/lib/Analysis/MemoryLocation.cpp
  llvm/test/Analysis/BasicAA/libfuncs.ll


Index: llvm/test/Analysis/BasicAA/libfuncs.ll
===================================================================
--- llvm/test/Analysis/BasicAA/libfuncs.ll
+++ llvm/test/Analysis/BasicAA/libfuncs.ll
@@ -110,7 +110,7 @@
 ; CHECK-NEXT: Just Ref:  Ptr: i8* %b        <->  %res = call i8* @memccpy(i8* %a, i8* %b, i32 42, i64 4)
 ; CHECK-NEXT: Both ModRef:  Ptr: i8* %res   <->  %res = call i8* @memccpy(i8* %a, i8* %b, i32 42, i64 4)
 ; CHECK-NEXT: Both ModRef:  Ptr: i8* %a.gep.1       <->  %res = call i8* @memccpy(i8* %a, i8* %b, i32 42, i64 4)
-; CHECK-NEXT: NoModRef:  Ptr: i8* %a.gep.5  <->  %res = call i8* @memccpy(i8* %a, i8* %b, i32 42, i64 4)
+; CHECK-NEXT: Both ModRef:  Ptr: i8* %a.gep.5       <->  %res = call i8* @memccpy(i8* %a, i8* %b, i32 42, i64 4)
 ; CHECK-NEXT: Just Ref:  Ptr: i8* %b.gep.1  <->  %res = call i8* @memccpy(i8* %a, i8* %b, i32 42, i64 4)
 ; CHECK-NEXT: NoModRef:  Ptr: i8* %b.gep.5  <->  %res = call i8* @memccpy(i8* %a, i8* %b, i32 42, i64 4)
 define i8* @test_memccpy_const_size(i8* noalias %a, i8* noalias %b) {
Index: llvm/lib/Analysis/MemoryLocation.cpp
===================================================================
--- llvm/lib/Analysis/MemoryLocation.cpp
+++ llvm/lib/Analysis/MemoryLocation.cpp
@@ -257,6 +257,9 @@
     case LibFunc_memccpy:
       assert((ArgIdx == 0 || ArgIdx == 1) &&
              "Invalid argument index for memccpy");
+      if (ArgIdx == 0)
+        // It is not known how many bytes are written to the dest arg.
+        break;
       if (const ConstantInt *LenCI =
               dyn_cast<ConstantInt>(Call->getArgOperand(3)))
         return MemoryLocation(Arg, LocationSize::precise(LenCI->getZExtValue()),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89885.299691.patch
Type: text/x-patch
Size: 1683 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201021/7bf15415/attachment.bin>


More information about the llvm-commits mailing list