[llvm-commits] [llvm] r79384 - in /llvm/trunk: lib/Analysis/ValueTracking.cpp lib/Transforms/Scalar/SimplifyLibCalls.cpp test/Transforms/SimplifyLibCalls/weak-symbols.ll

Dan Gohman gohman at apple.com
Tue Aug 18 17:11:13 PDT 2009


Author: djg
Date: Tue Aug 18 19:11:12 2009
New Revision: 79384

URL: http://llvm.org/viewvc/llvm-project?rev=79384&view=rev
Log:
Fix SimplifyLibcalls and ValueTracking to check mayBeOverridden
before performing optimizations based on constant string values.

Added:
    llvm/trunk/test/Transforms/SimplifyLibCalls/weak-symbols.ll
Modified:
    llvm/trunk/lib/Analysis/ValueTracking.cpp
    llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp

Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=79384&r1=79383&r2=79384&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp Tue Aug 18 19:11:12 2009
@@ -1061,7 +1061,8 @@
   // variable that is a constant and is initialized. The referenced constant
   // initializer is the array that we'll use for optimization.
   GlobalVariable* GV = dyn_cast<GlobalVariable>(V);
-  if (!GV || !GV->isConstant() || !GV->hasInitializer())
+  if (!GV || !GV->isConstant() || !GV->hasInitializer() ||
+      GV->mayBeOverridden())
     return false;
   Constant *GlobalInit = GV->getInitializer();
   

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

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp Tue Aug 18 19:11:12 2009
@@ -438,7 +438,8 @@
   // variable that is a constant and is initialized. The referenced constant
   // initializer is the array that we'll use for optimization.
   GlobalVariable* GV = dyn_cast<GlobalVariable>(GEP->getOperand(0));
-  if (!GV || !GV->isConstant() || !GV->hasInitializer())
+  if (!GV || !GV->isConstant() || !GV->hasInitializer() ||
+      GV->mayBeOverridden())
     return 0;
   Constant *GlobalInit = GV->getInitializer();
   

Added: llvm/trunk/test/Transforms/SimplifyLibCalls/weak-symbols.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyLibCalls/weak-symbols.ll?rev=79384&view=auto

==============================================================================
--- llvm/trunk/test/Transforms/SimplifyLibCalls/weak-symbols.ll (added)
+++ llvm/trunk/test/Transforms/SimplifyLibCalls/weak-symbols.ll Tue Aug 18 19:11:12 2009
@@ -0,0 +1,26 @@
+; RUN: llvm-as < %s | opt -simplify-libcalls | llvm-dis | FileCheck %s
+; PR4738
+
+; SimplifyLibcalls shouldn't assume anything about weak symbols.
+
+ at real_init = weak_odr constant [2 x i8] c"y\00"
+ at fake_init = weak constant [2 x i8] c"y\00"
+ at .str = private constant [2 x i8] c"y\00"
+
+; CHECK: define i32 @foo
+; CHECK: call i32 @strcmp
+define i32 @foo() nounwind {
+entry:
+  %t0 = call i32 @strcmp(i8* getelementptr inbounds ([2 x i8]* @fake_init, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8]* @.str, i64 0, i64 0)) nounwind readonly
+  ret i32 %t0
+}
+
+; CHECK: define i32 @bar
+; CHECK: ret i32 0
+define i32 @bar() nounwind {
+entry:
+  %t0 = call i32 @strcmp(i8* getelementptr inbounds ([2 x i8]* @real_init, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8]* @.str, i64 0, i64 0)) nounwind readonly
+  ret i32 %t0
+}
+
+declare i32 @strcmp(i8*, i8*) nounwind readonly





More information about the llvm-commits mailing list