aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2005-06-18 17:46:28 +0000
committerReid Spencer <rspencer@reidspencer.com>2005-06-18 17:46:28 +0000
commit134d2e4af861d29176631cb716b27ce1780b6f96 (patch)
tree2c9232e6acaa06c216a54b2b4056bf6ea15a6336
parent4b828e6384e1e6c9936130dd9fe805c2140b05fc (diff)
Fix a problem with the strcmp optimization checking the wrong string and
not casting to the correct type. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22250 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/IPO/SimplifyLibCalls.cpp29
1 files changed, 16 insertions, 13 deletions
diff --git a/lib/Transforms/IPO/SimplifyLibCalls.cpp b/lib/Transforms/IPO/SimplifyLibCalls.cpp
index 382bbb879e..a2ca692147 100644
--- a/lib/Transforms/IPO/SimplifyLibCalls.cpp
+++ b/lib/Transforms/IPO/SimplifyLibCalls.cpp
@@ -367,8 +367,9 @@ ModulePass *llvm::createSimplifyLibCallsPass()
// auto registers it into the "optlist" global above.
namespace {
-// Forward declare a utility function.
+// Forward declare utility functions.
bool getConstantStringLength(Value* V, uint64_t& len, ConstantArray** A = 0 );
+Value *CastToCStr(Value *V, Instruction &IP);
/// This LibCallOptimization will find instances of a call to "exit" that occurs
/// within the "main" function and change it to a simple "ret" instruction with
@@ -663,7 +664,8 @@ public:
if (len_1 == 0)
{
// strcmp("",x) -> *x
- LoadInst* load = new LoadInst(s1,ci->getName()+".load",ci);
+ LoadInst* load =
+ new LoadInst(CastToCStr(s2,*ci), ci->getName()+".load",ci);
CastInst* cast =
new CastInst(load,Type::IntTy,ci->getName()+".int",ci);
ci->replaceAllUsesWith(cast);
@@ -681,7 +683,8 @@ public:
if (len_2 == 0)
{
// strcmp(x,"") -> *x
- LoadInst* load = new LoadInst(s2,ci->getName()+".val",ci);
+ LoadInst* load =
+ new LoadInst(CastToCStr(s1,*ci),ci->getName()+".val",ci);
CastInst* cast =
new CastInst(load,Type::IntTy,ci->getName()+".int",ci);
ci->replaceAllUsesWith(cast);
@@ -1242,16 +1245,6 @@ public:
}
} PowOptimizer;
-/// CastToCStr - Return V if it is an sbyte*, otherwise cast it to sbyte*,
-/// inserting the cast before IP, and return the cast.
-/// @brief Cast a value to a "C" string.
-static Value *CastToCStr(Value *V, Instruction &IP) {
- const Type *SBPTy = PointerType::get(Type::SByteTy);
- if (V->getType() != SBPTy)
- return new CastInst(V, SBPTy, V->getName(), &IP);
- return V;
-}
-
/// This LibCallOptimization will simplify calls to the "fprintf" library
/// function. It looks for cases where the result of fprintf is not used and the
/// operation can be reduced to something simpler.
@@ -1889,6 +1882,16 @@ bool getConstantStringLength(Value* V, uint64_t& len, ConstantArray** CA )
return true; // success!
}
+/// CastToCStr - Return V if it is an sbyte*, otherwise cast it to sbyte*,
+/// inserting the cast before IP, and return the cast.
+/// @brief Cast a value to a "C" string.
+Value *CastToCStr(Value *V, Instruction &IP) {
+ const Type *SBPTy = PointerType::get(Type::SByteTy);
+ if (V->getType() != SBPTy)
+ return new CastInst(V, SBPTy, V->getName(), &IP);
+ return V;
+}
+
// TODO:
// Additional cases that we need to add to this file:
//