summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Ilseman <milseman@apple.com>2013-12-05 00:32:09 +0000
committerMichael Ilseman <milseman@apple.com>2013-12-05 00:32:09 +0000
commitbe92bcb3419e37aacf02acaf989880d0e8238866 (patch)
tree8d2edc445abfb8d674e78fe2b547666b34429392
parent1c70b6795ba4c4c221480c9577e138652de1175c (diff)
downloadbcm5719-llvm-be92bcb3419e37aacf02acaf989880d0e8238866.tar.gz
bcm5719-llvm-be92bcb3419e37aacf02acaf989880d0e8238866.zip
Use present fast-math flags when applicable in CreateBinOp
We were previously not adding fast-math flags through CreateBinOp() when it happened to be making a floating point binary operator. This patch updates it to do so similarly to directly calling CreateF*(). llvm-svn: 196438
-rw-r--r--llvm/include/llvm/IR/IRBuilder.h8
-rw-r--r--llvm/unittests/IR/IRBuilderTest.cpp7
2 files changed, 13 insertions, 2 deletions
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index 56e818417aa..c9c11be89d6 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -832,11 +832,15 @@ public:
}
Value *CreateBinOp(Instruction::BinaryOps Opc,
- Value *LHS, Value *RHS, const Twine &Name = "") {
+ Value *LHS, Value *RHS, const Twine &Name = "",
+ MDNode *FPMathTag = 0) {
if (Constant *LC = dyn_cast<Constant>(LHS))
if (Constant *RC = dyn_cast<Constant>(RHS))
return Insert(Folder.CreateBinOp(Opc, LC, RC), Name);
- return Insert(BinaryOperator::Create(Opc, LHS, RHS), Name);
+ llvm::Instruction *BinOp = BinaryOperator::Create(Opc, LHS, RHS);
+ if (isa<FPMathOperator>(BinOp))
+ BinOp = AddFPMathAttributes(BinOp, FPMathTag, FMF);
+ return Insert(BinOp, Name);
}
Value *CreateNeg(Value *V, const Twine &Name = "",
diff --git a/llvm/unittests/IR/IRBuilderTest.cpp b/llvm/unittests/IR/IRBuilderTest.cpp
index 2f390f7f75a..fcb56779073 100644
--- a/llvm/unittests/IR/IRBuilderTest.cpp
+++ b/llvm/unittests/IR/IRBuilderTest.cpp
@@ -147,6 +147,13 @@ TEST_F(IRBuilderTest, FastMathFlags) {
FAdd = cast<Instruction>(F);
EXPECT_TRUE(FAdd->hasNoNaNs());
+ // Now, try it with CreateBinOp
+ F = Builder.CreateBinOp(Instruction::FAdd, F, F);
+ EXPECT_TRUE(Builder.getFastMathFlags().any());
+ ASSERT_TRUE(isa<Instruction>(F));
+ FAdd = cast<Instruction>(F);
+ EXPECT_TRUE(FAdd->hasNoNaNs());
+
F = Builder.CreateFDiv(F, F);
EXPECT_TRUE(Builder.getFastMathFlags().any());
EXPECT_TRUE(Builder.getFastMathFlags().UnsafeAlgebra);
OpenPOWER on IntegriCloud