Move the object size intrinsic optimization to inst-combine and make
[oota-llvm.git] / lib / Transforms / InstCombine / InstCombineCalls.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);