part of PR4405: disable a contentious optimization for
authorChris Lattner <sabre@nondot.org>
Fri, 19 Jun 2009 04:17:36 +0000 (04:17 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 19 Jun 2009 04:17:36 +0000 (04:17 +0000)
strcmp -> memcmp when the lengths of the strings are unknown.

Patch by Nick Lewycky!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73751 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/SimplifyLibCalls.cpp
test/Transforms/SimplifyLibCalls/2008-12-20-StrcmpMemcmp.ll [deleted file]

index 7d0c35e54091a2dea3508379dbc3fb38ab5043ff..bbcb79255eefb8a5a51dec7d20ad3077dbbffbd3 100644 (file)
@@ -709,12 +709,10 @@ struct VISIBILITY_HIDDEN StrCmpOpt : public LibCallOptimization {
     // strcmp(P, "x") -> memcmp(P, "x", 2)
     uint64_t Len1 = GetStringLength(Str1P);
     uint64_t Len2 = GetStringLength(Str2P);
-    if (Len1 || Len2) {
-      // Choose the smallest Len excluding 0 which means 'unknown'.
-      if (!Len1 || (Len2 && Len2 < Len1))
-        Len1 = Len2;
+    if (Len1 && Len2) {
       return EmitMemCmp(Str1P, Str2P,
-                        ConstantInt::get(TD->getIntPtrType(), Len1), B);
+                        ConstantInt::get(TD->getIntPtrType(),
+                        std::min(Len1, Len2)), B);
     }
 
     return 0;
diff --git a/test/Transforms/SimplifyLibCalls/2008-12-20-StrcmpMemcmp.ll b/test/Transforms/SimplifyLibCalls/2008-12-20-StrcmpMemcmp.ll
deleted file mode 100644 (file)
index d35da8d..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-; RUN: llvm-as < %s | opt -simplify-libcalls | llvm-dis | grep call.*memcmp
-
-@.str = internal constant [2 x i8] c"x\00"
-
-declare i32 @strcmp(i8* %dest, i8* %src)
-
-define i32 @foo(i8* %x, i8* %y) {
-  %A = call i32 @strcmp(i8* %x, i8* getelementptr ([2 x i8]* @.str, i32 0, i32 0))
-  ret i32 %A
-}