diff options
author | Eric Christopher <echristo@apple.com> | 2010-03-11 19:24:34 +0000 |
---|---|---|
committer | Eric Christopher <echristo@apple.com> | 2010-03-11 19:24:34 +0000 |
commit | 607de1de53d429f56a4482db257d6195cf984a7a (patch) | |
tree | 5c1719d93a480755821075135b368c321743f506 /llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp | |
parent | 31fe835bf2771bca3e1d76666438b4cec806070d (diff) | |
download | bcm5719-llvm-607de1de53d429f56a4482db257d6195cf984a7a.tar.gz bcm5719-llvm-607de1de53d429f56a4482db257d6195cf984a7a.zip |
Lower stpcpy_chk when possible.
llvm-svn: 98274
Diffstat (limited to 'llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp')
-rw-r--r-- | llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp b/llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp index f5ccebfdefa..c428d2b0b0c 100644 --- a/llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp +++ b/llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp @@ -624,11 +624,6 @@ bool CodeGenPrepare::OptimizeCallInst(CallInst *CI) { ConstantInt *SizeCI = dyn_cast<ConstantInt>(CI->getOperand(3)); if (!SizeCI) return 0; - // If a) we don't have any length information, or b) we know this will - // fit then just lower to a plain strcpy. Otherwise we'll keep our - // strcpy_chk call which may fail at runtime if the size is too long. - // TODO: It might be nice to get a maximum length out of the possible - // string lengths for varying. if (SizeCI->isAllOnesValue()) { Value *Ret = EmitStrCpy(CI->getOperand(1), CI->getOperand(2), B, TD); CI->replaceAllUsesWith(Ret); @@ -638,8 +633,16 @@ bool CodeGenPrepare::OptimizeCallInst(CallInst *CI) { return 0; } - // Should be similar to strcpy. if (Name == "__stpcpy_chk") { + ConstantInt *SizeCI = dyn_cast<ConstantInt>(CI->getOperand(3)); + if (!SizeCI) + return 0; + if (SizeCI->isAllOnesValue()) { + Value *Ret = EmitStpCpy(CI->getOperand(1), CI->getOperand(2), B, TD); + CI->replaceAllUsesWith(Ret); + CI->eraseFromParent(); + return true; + } return 0; } |