[PATCH] D139583: [IRBuilder] Fix CreateFDivFMF ignoring source FMF
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 13 02:40:12 PST 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4f3b1c6dd6ef: [IRBuilder] Fix CreateFDivFMF ignoring source FMF (authored by dwoodwor-intel, committed by nikic).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D139583/new/
https://reviews.llvm.org/D139583
Files:
llvm/include/llvm/IR/IRBuilder.h
llvm/unittests/IR/IRBuilderTest.cpp
Index: llvm/unittests/IR/IRBuilderTest.cpp
===================================================================
--- llvm/unittests/IR/IRBuilderTest.cpp
+++ llvm/unittests/IR/IRBuilderTest.cpp
@@ -551,7 +551,7 @@
TEST_F(IRBuilderTest, FastMathFlags) {
IRBuilder<> Builder(BB);
Value *F, *FC;
- Instruction *FDiv, *FAdd, *FCmp, *FCall;
+ Instruction *FDiv, *FAdd, *FCmp, *FCall, *FNeg, *FSub, *FMul, *FRem;
F = Builder.CreateLoad(GV->getValueType(), GV);
F = Builder.CreateFAdd(F, F);
@@ -732,6 +732,36 @@
EXPECT_TRUE(FDiv->hasNoNaNs());
EXPECT_FALSE(FDiv->hasAllowReciprocal());
+ // Test that CreateF*FMF functions copy flags from the source instruction
+ // instead of using the builder default.
+ Instruction *const FMFSource = FAdd;
+ EXPECT_FALSE(Builder.getFastMathFlags().noNaNs());
+ EXPECT_TRUE(FMFSource->hasNoNaNs());
+
+ F = Builder.CreateFNegFMF(F, FMFSource);
+ ASSERT_TRUE(isa<Instruction>(F));
+ FNeg = cast<Instruction>(F);
+ EXPECT_TRUE(FNeg->hasNoNaNs());
+ F = Builder.CreateFAddFMF(F, F, FMFSource);
+ ASSERT_TRUE(isa<Instruction>(F));
+ FAdd = cast<Instruction>(F);
+ EXPECT_TRUE(FAdd->hasNoNaNs());
+ F = Builder.CreateFSubFMF(F, F, FMFSource);
+ ASSERT_TRUE(isa<Instruction>(F));
+ FSub = cast<Instruction>(F);
+ EXPECT_TRUE(FSub->hasNoNaNs());
+ F = Builder.CreateFMulFMF(F, F, FMFSource);
+ ASSERT_TRUE(isa<Instruction>(F));
+ FMul = cast<Instruction>(F);
+ EXPECT_TRUE(FMul->hasNoNaNs());
+ F = Builder.CreateFDivFMF(F, F, FMFSource);
+ ASSERT_TRUE(isa<Instruction>(F));
+ FDiv = cast<Instruction>(F);
+ EXPECT_TRUE(FDiv->hasNoNaNs());
+ F = Builder.CreateFRemFMF(F, F, FMFSource);
+ ASSERT_TRUE(isa<Instruction>(F));
+ FRem = cast<Instruction>(F);
+ EXPECT_TRUE(FRem->hasNoNaNs());
}
TEST_F(IRBuilderTest, WrapFlags) {
Index: llvm/include/llvm/IR/IRBuilder.h
===================================================================
--- llvm/include/llvm/IR/IRBuilder.h
+++ llvm/include/llvm/IR/IRBuilder.h
@@ -1543,6 +1543,7 @@
return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fdiv,
L, R, FMFSource, Name);
+ FastMathFlags FMF = FMFSource->getFastMathFlags();
if (Value *V = Folder.FoldBinOpFMF(Instruction::FDiv, L, R, FMF))
return V;
Instruction *I = setFPAttrs(BinaryOperator::CreateFDiv(L, R), nullptr, FMF);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139583.482406.patch
Type: text/x-patch
Size: 2379 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221213/ad017a71/attachment.bin>
More information about the llvm-commits
mailing list