aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms
diff options
context:
space:
mode:
authorEric Christopher <echristo@apple.com>2010-02-09 21:24:27 +0000
committerEric Christopher <echristo@apple.com>2010-02-09 21:24:27 +0000
commit415326b4edcc967dfb03c5ab41923b195e7c3cb1 (patch)
tree4347e6a4db0dd0f941fb9b57288af31097ffac43 /lib/Transforms
parent32f9a2c54e6fbb980146c8c92894bed22cd67610 (diff)
downloadexternal_llvm-415326b4edcc967dfb03c5ab41923b195e7c3cb1.zip
external_llvm-415326b4edcc967dfb03c5ab41923b195e7c3cb1.tar.gz
external_llvm-415326b4edcc967dfb03c5ab41923b195e7c3cb1.tar.bz2
Move Intrinsic::objectsize lowering back to InstCombineCalls and
enable constant 0 offset lowering. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95691 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/InstCombine/InstCombineCalls.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineCalls.cpp b/lib/Transforms/InstCombine/InstCombineCalls.cpp
index fa42b6e..4929f40 100644
--- a/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -230,7 +230,6 @@ Instruction *InstCombiner::SimplifyMemSet(MemSetInst *MI) {
return 0;
}
-
/// visitCallInst - CallInst simplification. This mostly only handles folding
/// of intrinsic instructions. For normal calls, it allows visitCallSite to do
/// the heavy lifting.
@@ -304,6 +303,25 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
switch (II->getIntrinsicID()) {
default: break;
+ case Intrinsic::objectsize: {
+ const Type *ReturnTy = CI.getType();
+ Value *Op1 = II->getOperand(1);
+ bool Min = (cast<ConstantInt>(II->getOperand(2))->getZExtValue() == 1);
+
+ if (!TD) break;
+ Op1 = Op1->stripPointerCasts();
+
+ if (GlobalVariable *GV = dyn_cast<GlobalVariable>(Op1)) {
+ if (GV->hasDefinitiveInitializer()) {
+ Constant *C = GV->getInitializer();
+ size_t globalSize = TD->getTypeAllocSize(C->getType());
+ return ReplaceInstUsesWith(CI, ConstantInt::get(ReturnTy, globalSize));
+ } else {
+ Constant *RetVal = ConstantInt::get(ReturnTy, Min ? 0 : -1ULL);
+ return ReplaceInstUsesWith(CI, RetVal);
+ }
+ }
+ }
case Intrinsic::bswap:
// bswap(bswap(x)) -> x
if (IntrinsicInst *Operand = dyn_cast<IntrinsicInst>(II->getOperand(1)))