+
+ // Test that we don't eliminate bitcasts between different address spaces,
+ // or if we don't have available pointer size information.
+ DataLayout DL("e-p:32:32:32-p1:16:16:16-p2:64:64:64-i1:8:8-i8:8:8-i16:16:16"
+ "-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64"
+ "-v128:128:128-a:0:64-s:64:64-f80:128:128-n8:16:32:64-S128");
+
+ Type* Int64PtrTyAS1 = Type::getInt64PtrTy(C, 1);
+ Type* Int64PtrTyAS2 = Type::getInt64PtrTy(C, 2);
+
+ IntegerType *Int16SizePtr = DL.getIntPtrType(C, 1);
+ IntegerType *Int64SizePtr = DL.getIntPtrType(C, 2);
+
+ // Cannot simplify inttoptr, addrspacecast
+ EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::IntToPtr,
+ CastInst::AddrSpaceCast,
+ Int16Ty, Int64PtrTyAS1, Int64PtrTyAS2,
+ nullptr, Int16SizePtr, Int64SizePtr),
+ 0U);
+
+ // Cannot simplify addrspacecast, ptrtoint
+ EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::AddrSpaceCast,
+ CastInst::PtrToInt,
+ Int64PtrTyAS1, Int64PtrTyAS2, Int16Ty,
+ Int64SizePtr, Int16SizePtr, nullptr),
+ 0U);
+
+ // Pass since the bitcast address spaces are the same
+ EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::IntToPtr,
+ CastInst::BitCast,
+ Int16Ty, Int64PtrTyAS1, Int64PtrTyAS1,
+ nullptr, nullptr, nullptr),
+ CastInst::IntToPtr);
+
+}
+
+TEST(InstructionsTest, CloneCall) {
+ LLVMContext &C(getGlobalContext());
+ Type *Int32Ty = Type::getInt32Ty(C);
+ Type *ArgTys[] = {Int32Ty, Int32Ty, Int32Ty};
+ Type *FnTy = FunctionType::get(Int32Ty, ArgTys, /*isVarArg=*/false);
+ Value *Callee = Constant::getNullValue(FnTy->getPointerTo());
+ Value *Args[] = {
+ ConstantInt::get(Int32Ty, 1),
+ ConstantInt::get(Int32Ty, 2),
+ ConstantInt::get(Int32Ty, 3)
+ };
+ std::unique_ptr<CallInst> Call(CallInst::Create(Callee, Args, "result"));
+
+ // Test cloning the tail call kind.
+ CallInst::TailCallKind Kinds[] = {CallInst::TCK_None, CallInst::TCK_Tail,
+ CallInst::TCK_MustTail};
+ for (CallInst::TailCallKind TCK : Kinds) {
+ Call->setTailCallKind(TCK);
+ std::unique_ptr<CallInst> Clone(cast<CallInst>(Call->clone()));
+ EXPECT_EQ(Call->getTailCallKind(), Clone->getTailCallKind());
+ }
+ Call->setTailCallKind(CallInst::TCK_None);
+
+ // Test cloning an attribute.
+ {
+ AttrBuilder AB;
+ AB.addAttribute(Attribute::ReadOnly);
+ Call->setAttributes(AttributeSet::get(C, AttributeSet::FunctionIndex, AB));
+ std::unique_ptr<CallInst> Clone(cast<CallInst>(Call->clone()));
+ EXPECT_TRUE(Clone->onlyReadsMemory());
+ }