- if (!CI->use_empty()) {
- Instruction *RetVal = NewCI;
- if (F->getReturnType() != NewFn->getReturnType()) {
- RetVal = new CastInst(NewCI, NewFn->getReturnType(),
+ switch(NewFn->getIntrinsicID()) {
+ default: assert(0 && "Unknown function for CallInst upgrade.");
+ case Intrinsic::ctlz:
+ case Intrinsic::ctpop:
+ case Intrinsic::cttz:
+ // Build a small vector of the 1..(N-1) operands, which are the
+ // parameters.
+ SmallVector<Value*, 8> Operands(CI->op_begin()+1, CI->op_end());
+
+ // Construct a new CallInst
+ CallInst *NewCI = new CallInst(NewFn, Operands.begin(), Operands.end(),
+ "upgraded."+CI->getName(), CI);
+ NewCI->setTailCall(CI->isTailCall());
+ NewCI->setCallingConv(CI->getCallingConv());
+
+ // Handle any uses of the old CallInst.
+ if (!CI->use_empty()) {
+ // Check for sign extend parameter attributes on the return values.
+ bool SrcSExt = NewFnTy->getParamAttrs() &&
+ NewFnTy->getParamAttrs()->paramHasAttr(0,ParamAttr::SExt);
+ bool DestSExt = FTy->getParamAttrs() &&
+ FTy->getParamAttrs()->paramHasAttr(0,ParamAttr::SExt);
+
+ // Construct an appropriate cast from the new return type to the old.
+ CastInst *RetCast = CastInst::create(
+ CastInst::getCastOpcode(NewCI, SrcSExt,
+ F->getReturnType(),
+ DestSExt),
+ NewCI, F->getReturnType(),