Move the object size intrinsic optimization to inst-combine and make
authorEric Christopher <echristo@apple.com>
Wed, 6 Jan 2010 20:04:44 +0000 (20:04 +0000)
committerEric Christopher <echristo@apple.com>
Wed, 6 Jan 2010 20:04:44 +0000 (20:04 +0000)
it work for any integer size return type.

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

lib/Transforms/InstCombine/InstCombineCalls.cpp
lib/Transforms/Scalar/SimplifyLibCalls.cpp

index 6aacf5dd0ef443b13fdf2dacfbdb9a68f4802b9d..e34360087c645ed6e6e1c3630454a048d1ea3cb5 100644 (file)
@@ -632,6 +632,18 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
       return EraseInstFromFunction(CI);
     break;
   }
+  case Intrinsic::objectsize: {
+    ConstantInt *Const = dyn_cast<ConstantInt>(II->getOperand(2));
+
+    if (!Const) return 0;
+
+    const Type *Ty = CI.getType();
+
+    if (Const->getZExtValue() == 0)
+      return ReplaceInstUsesWith(CI, Constant::getAllOnesValue(Ty));
+    else
+      return ReplaceInstUsesWith(CI, ConstantInt::get(Ty, 0));
+  }
   }
 
   return visitCallSite(II);
index c67c9cf03f27c3ee68848d80ebc4df0d3d6cd230..9183f3aac1fb1c2c57fffef2b1df22b5ee1678cd 100644 (file)
@@ -1094,27 +1094,6 @@ struct MemSetOpt : public LibCallOptimization {
 // Object Size Checking Optimizations
 //===----------------------------------------------------------------------===//
 
-//===---------------------------------------===//
-// 'object size'
-namespace {
-struct SizeOpt : public LibCallOptimization {
-  virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
-    // TODO: We can do more with this, but delaying to here should be no change
-    // in behavior.
-    ConstantInt *Const = dyn_cast<ConstantInt>(CI->getOperand(2));
-
-    if (!Const) return 0;
-
-    const Type *Ty = Callee->getFunctionType()->getReturnType();
-
-    if (Const->getZExtValue() == 0)
-      return Constant::getAllOnesValue(Ty);
-    else
-      return ConstantInt::get(Ty, 0);
-  }
-};
-}
-
 //===---------------------------------------===//
 // 'memcpy_chk' Optimizations
 
@@ -1745,7 +1724,6 @@ namespace {
     FWriteOpt FWrite; FPutsOpt FPuts; FPrintFOpt FPrintF;
 
     // Object Size Checking
-    SizeOpt ObjectSize;
     MemCpyChkOpt MemCpyChk; MemSetChkOpt MemSetChk; MemMoveChkOpt MemMoveChk;
 
     bool Modified;  // This is only used by doInitialization.
@@ -1855,8 +1833,6 @@ void SimplifyLibCalls::InitOptimizations() {
   Optimizations["fprintf"] = &FPrintF;
 
   // Object Size Checking
-  Optimizations["llvm.objectsize.i32"] = &ObjectSize;
-  Optimizations["llvm.objectsize.i64"] = &ObjectSize;
   Optimizations["__memcpy_chk"] = &MemCpyChk;
   Optimizations["__memset_chk"] = &MemSetChk;
   Optimizations["__memmove_chk"] = &MemMoveChk;