[PATCH] D67291: Teach the IRBuilder about constrained FPToSI and FPToUI
Kevin P. Neal via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 6 11:03:31 PDT 2019
This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL371235: [FPEnv] Teach the IRBuilder about constrained FPToSI and FPToUI. (authored by kpn, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D67291?vs=219137&id=219144#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D67291/new/
https://reviews.llvm.org/D67291
Files:
llvm/trunk/include/llvm/IR/IRBuilder.h
llvm/trunk/unittests/IR/IRBuilderTest.cpp
Index: llvm/trunk/include/llvm/IR/IRBuilder.h
===================================================================
--- llvm/trunk/include/llvm/IR/IRBuilder.h
+++ llvm/trunk/include/llvm/IR/IRBuilder.h
@@ -1913,11 +1913,17 @@
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);
}
@@ -2059,7 +2065,6 @@
MDNode *FPMathTag = nullptr,
Optional<ConstrainedFPIntrinsic::RoundingMode> Rounding = None,
Optional<ConstrainedFPIntrinsic::ExceptionBehavior> Except = None) {
- Value *RoundingV = getConstrainedFPRounding(Rounding);
Value *ExceptV = getConstrainedFPExcept(Except);
FastMathFlags UseFMF = FMF;
@@ -2067,13 +2072,22 @@
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
Index: llvm/trunk/unittests/IR/IRBuilderTest.cpp
===================================================================
--- llvm/trunk/unittests/IR/IRBuilderTest.cpp
+++ llvm/trunk/unittests/IR/IRBuilderTest.cpp
@@ -171,6 +171,7 @@
IRBuilder<> Builder(BB);
Value *V;
Value *VDouble;
+ Value *VInt;
CallInst *Call;
IntrinsicInst *II;
GlobalVariable *GVDouble = new GlobalVariable(*M, Type::getDoubleTy(Ctx),
@@ -208,6 +209,16 @@
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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67291.219144.patch
Type: text/x-patch
Size: 3553 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190906/a2a44875/attachment.bin>
More information about the llvm-commits
mailing list