[llvm-commits] [llvm] r64460 - in /llvm/trunk: lib/Transforms/Scalar/SimplifyLibCalls.cpp test/Transforms/SimplifyLibCalls/2009-02-12-StrTo.ll

Nick Lewycky nicholas at mxc.ca
Fri Feb 13 09:08:33 PST 2009


Author: nicholas
Date: Fri Feb 13 11:08:33 2009
New Revision: 64460

URL: http://llvm.org/viewvc/llvm-project?rev=64460&view=rev
Log:
Mark strto* as readonly when the endptr is null.

Modified:
    llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp
    llvm/trunk/test/Transforms/SimplifyLibCalls/2009-02-12-StrTo.ll

Modified: llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp?rev=64460&r1=64459&r2=64460&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp Fri Feb 13 11:08:33 2009
@@ -733,8 +733,10 @@
       return 0;
 
     Value *EndPtr = CI->getOperand(2);
-    if (isa<ConstantPointerNull>(EndPtr))
+    if (isa<ConstantPointerNull>(EndPtr)) {
+      CI->setOnlyReadsMemory();
       CI->addAttribute(1, Attribute::NoCapture);
+    }
 
     return 0;
   }

Modified: llvm/trunk/test/Transforms/SimplifyLibCalls/2009-02-12-StrTo.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyLibCalls/2009-02-12-StrTo.ll?rev=64460&r1=64459&r2=64460&view=diff

==============================================================================
--- llvm/trunk/test/Transforms/SimplifyLibCalls/2009-02-12-StrTo.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyLibCalls/2009-02-12-StrTo.ll Fri Feb 13 11:08:33 2009
@@ -1,13 +1,14 @@
 ; RUN: llvm-as < %s | opt -simplify-libcalls | llvm-dis > %t
 ; RUN: grep nocapture %t | count 2
 ; RUN: grep null %t | grep nocapture | count 1
+; RUN: grep null %t | grep call | grep readonly | count 1
 
-; Test that we do add nocapture to the declaration, and to the second call only.
+; Test that we add nocapture to the declaration, and to the second call only.
 
-declare float @strtof(i8* %s, i8** %endptr, i32 %base)
+declare float @strtol(i8* %s, i8** %endptr, i32 %base)
 
 define void @foo(i8* %x, i8** %endptr) {
-  call float @strtof(i8* %x, i8** %endptr, i32 0)
-  call float @strtof(i8* %x, i8** null, i32 0)
+  call float @strtol(i8* %x, i8** %endptr, i32 10)
+  call float @strtol(i8* %x, i8** null, i32 10)
   ret void
 }





More information about the llvm-commits mailing list