-
- bool NewIsVoid = NewFn->getReturnType() == Type::VoidTy;
-
- CallInst *NewCI = new CallInst(NewFn, Oprnds,
- NewIsVoid ? "" : CI->getName(),
- CI);
- NewCI->setTailCall(CI->isTailCall());
- NewCI->setCallingConv(CI->getCallingConv());
-
- if (!CI->use_empty()) {
- if (NewIsVoid) {
- CI->replaceAllUsesWith(UndefValue::get(CI->getType()));
- } else {
- Instruction *RetVal = NewCI;
-
- if (F->getReturnType() != NewFn->getReturnType()) {
- RetVal = new CastInst(NewCI, F->getReturnType(),
- NewCI->getName(), CI);
- NewCI->moveBefore(RetVal);
- }
+
+ switch (NewFn->getIntrinsicID()) {
+ default: assert(0 && "Unknown function for CallInst upgrade.");
+ case Intrinsic::x86_mmx_psll_d:
+ case Intrinsic::x86_mmx_psll_q:
+ case Intrinsic::x86_mmx_psll_w:
+ case Intrinsic::x86_mmx_psra_d:
+ case Intrinsic::x86_mmx_psra_w:
+ case Intrinsic::x86_mmx_psrl_d:
+ case Intrinsic::x86_mmx_psrl_q:
+ case Intrinsic::x86_mmx_psrl_w: {
+ Value *Operands[2];
+
+ Operands[0] = CI->getOperand(1);
+
+ // Cast the second parameter to the correct type.
+ BitCastInst *BC = new BitCastInst(CI->getOperand(2),
+ NewFn->getFunctionType()->getParamType(1),
+ "upgraded.", CI);
+ Operands[1] = BC;
+
+ // Construct a new CallInst
+ CallInst *NewCI = CallInst::Create(NewFn, Operands, Operands+2,
+ "upgraded."+CI->getName(), CI);
+ NewCI->setTailCall(CI->isTailCall());
+ NewCI->setCallingConv(CI->getCallingConv());
+
+ // Handle any uses of the old CallInst.
+ if (!CI->use_empty())
+ // Replace all uses of the old call with the new cast which has the
+ // correct type.
+ CI->replaceAllUsesWith(NewCI);
+
+ // Clean up the old call now that it has been completely upgraded.
+ CI->eraseFromParent();
+ break;
+ }
+ 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 = CallInst::Create(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 = NewFn->getAttributes().paramHasAttr(0, Attribute::SExt);
+ bool DestSExt = F->getAttributes().paramHasAttr(0, Attribute::SExt);