return V;
}
- Value *CreateFPToUI(Value *V, Type *DestTy, const Twine &Name = ""){
+ Value *CreateFPToUI(Value *V, Type *DestTy, const Twine &Name = "") {
+ if (IsFPConstrained)
+ return CreateConstrainedFPCast(Intrinsic::experimental_constrained_fptoui,
+ V, DestTy, nullptr, Name);
return CreateCast(Instruction::FPToUI, V, DestTy, Name);
}
- Value *CreateFPToSI(Value *V, Type *DestTy, const Twine &Name = ""){
+ Value *CreateFPToSI(Value *V, Type *DestTy, const Twine &Name = "") {
+ if (IsFPConstrained)
+ return CreateConstrainedFPCast(Intrinsic::experimental_constrained_fptosi,
+ V, DestTy, nullptr, Name);
return CreateCast(Instruction::FPToSI, V, DestTy, Name);
}
MDNode *FPMathTag = nullptr,
Optional<ConstrainedFPIntrinsic::RoundingMode> Rounding = None,
Optional<ConstrainedFPIntrinsic::ExceptionBehavior> Except = None) {
- Value *RoundingV = getConstrainedFPRounding(Rounding);
Value *ExceptV = getConstrainedFPExcept(Except);
FastMathFlags UseFMF = FMF;
UseFMF = FMFSource->getFastMathFlags();
CallInst *C;
- if (ID == Intrinsic::experimental_constrained_fpext)
- C = CreateIntrinsic(ID, {DestTy, V->getType()}, {V, ExceptV}, nullptr,
- Name);
- else
+ switch (ID) {
+ default: {
+ Value *RoundingV = getConstrainedFPRounding(Rounding);
C = CreateIntrinsic(ID, {DestTy, V->getType()}, {V, RoundingV, ExceptV},
nullptr, Name);
- return cast<CallInst>(setFPAttrs(C, FPMathTag, UseFMF));
+ } break;
+ case Intrinsic::experimental_constrained_fpext:
+ case Intrinsic::experimental_constrained_fptoui:
+ case Intrinsic::experimental_constrained_fptosi:
+ C = CreateIntrinsic(ID, {DestTy, V->getType()}, {V, ExceptV}, nullptr,
+ Name);
+ break;
+ }
+ if (isa<FPMathOperator>(C))
+ C = cast<CallInst>(setFPAttrs(C, FPMathTag, UseFMF));
+ return C;
}
// Provided to resolve 'CreateIntCast(Ptr, Ptr, "...")', giving a
IRBuilder<> Builder(BB);
Value *V;
Value *VDouble;
+ Value *VInt;
CallInst *Call;
IntrinsicInst *II;
GlobalVariable *GVDouble = new GlobalVariable(*M, Type::getDoubleTy(Ctx),
II = cast<IntrinsicInst>(V);
EXPECT_EQ(II->getIntrinsicID(), Intrinsic::experimental_constrained_frem);
+ VInt = Builder.CreateFPToUI(VDouble, Builder.getInt32Ty());
+ ASSERT_TRUE(isa<IntrinsicInst>(VInt));
+ II = cast<IntrinsicInst>(VInt);
+ EXPECT_EQ(II->getIntrinsicID(), Intrinsic::experimental_constrained_fptoui);
+
+ VInt = Builder.CreateFPToSI(VDouble, Builder.getInt32Ty());
+ ASSERT_TRUE(isa<IntrinsicInst>(VInt));
+ II = cast<IntrinsicInst>(VInt);
+ EXPECT_EQ(II->getIntrinsicID(), Intrinsic::experimental_constrained_fptosi);
+
V = Builder.CreateFPTrunc(VDouble, Type::getFloatTy(Ctx));
ASSERT_TRUE(isa<IntrinsicInst>(V));
II = cast<IntrinsicInst>(V);