[llvm] r325730 - [InstCombine] add and use Create*FMF functions; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 21 14:18:55 PST 2018
Author: spatel
Date: Wed Feb 21 14:18:55 2018
New Revision: 325730
URL: http://llvm.org/viewvc/llvm-project?rev=325730&view=rev
Log:
[InstCombine] add and use Create*FMF functions; NFC
Modified:
llvm/trunk/include/llvm/IR/InstrTypes.h
llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
Modified: llvm/trunk/include/llvm/IR/InstrTypes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/InstrTypes.h?rev=325730&r1=325729&r2=325730&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/InstrTypes.h (original)
+++ llvm/trunk/include/llvm/IR/InstrTypes.h Wed Feb 21 14:18:55 2018
@@ -391,6 +391,27 @@ public:
return BO;
}
+ static BinaryOperator *CreateFAddFMF(Value *V1, Value *V2,
+ BinaryOperator *FMFSource,
+ const Twine &Name = "") {
+ return CreateWithCopiedFlags(Instruction::FAdd, V1, V2, FMFSource, Name);
+ }
+ static BinaryOperator *CreateFSubFMF(Value *V1, Value *V2,
+ BinaryOperator *FMFSource,
+ const Twine &Name = "") {
+ return CreateWithCopiedFlags(Instruction::FSub, V1, V2, FMFSource, Name);
+ }
+ static BinaryOperator *CreateFMulFMF(Value *V1, Value *V2,
+ BinaryOperator *FMFSource,
+ const Twine &Name = "") {
+ return CreateWithCopiedFlags(Instruction::FMul, V1, V2, FMFSource, Name);
+ }
+ static BinaryOperator *CreateFDivFMF(Value *V1, Value *V2,
+ BinaryOperator *FMFSource,
+ const Twine &Name = "") {
+ return CreateWithCopiedFlags(Instruction::FDiv, V1, V2, FMFSource, Name);
+ }
+
static BinaryOperator *CreateNSW(BinaryOps Opc, Value *V1, Value *V2,
const Twine &Name = "") {
BinaryOperator *BO = Create(Opc, V1, V2, Name);
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp?rev=325730&r1=325729&r2=325730&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp Wed Feb 21 14:18:55 2018
@@ -1294,8 +1294,7 @@ static Instruction *foldFDivConstantDivi
// -X / C --> X / -C
Value *X;
if (match(I.getOperand(0), m_FNeg(m_Value(X))))
- return BinaryOperator::CreateWithCopiedFlags(Instruction::FDiv, X,
- ConstantExpr::getFNeg(C), &I);
+ return BinaryOperator::CreateFDivFMF(X, ConstantExpr::getFNeg(C), &I);
// If the constant divisor has an exact inverse, this is always safe. If not,
// then we can still create a reciprocal if fast-math-flags allow it and the
@@ -1312,8 +1311,7 @@ static Instruction *foldFDivConstantDivi
return nullptr;
// X / C --> X * (1 / C)
- return BinaryOperator::CreateWithCopiedFlags(
- Instruction::FMul, I.getOperand(0), RecipC, &I);
+ return BinaryOperator::CreateFMulFMF(I.getOperand(0), RecipC, &I);
}
/// Remove negation and try to reassociate constant math.
@@ -1324,10 +1322,8 @@ static Instruction *foldFDivConstantDivi
// C / -X --> -C / X
Value *X;
- if (match(I.getOperand(1), m_FNeg(m_Value(X)))) {
- return BinaryOperator::CreateWithCopiedFlags(
- Instruction::FDiv, ConstantExpr::getFNeg(C), X, &I);
- }
+ if (match(I.getOperand(1), m_FNeg(m_Value(X))))
+ return BinaryOperator::CreateFDivFMF(ConstantExpr::getFNeg(C), X, &I);
if (!I.hasAllowReassoc() || !I.hasAllowReciprocal())
return nullptr;
@@ -1348,7 +1344,7 @@ static Instruction *foldFDivConstantDivi
if (!NewC || !NewC->isNormalFP())
return nullptr;
- return BinaryOperator::CreateWithCopiedFlags(Instruction::FDiv, NewC, X, &I);
+ return BinaryOperator::CreateFDivFMF(NewC, X, &I);
}
Instruction *InstCombiner::visitFDiv(BinaryOperator &I) {
@@ -1388,9 +1384,7 @@ Instruction *InstCombiner::visitFDiv(Bin
FMFIntersect &= cast<Instruction>(Op0)->getFastMathFlags();
YZInst->setFastMathFlags(FMFIntersect);
}
- Instruction *NewDiv = BinaryOperator::CreateFDiv(X, YZ);
- NewDiv->setFastMathFlags(I.getFastMathFlags());
- return NewDiv;
+ return BinaryOperator::CreateFDivFMF(X, YZ, &I);
}
if (match(Op1, m_OneUse(m_FDiv(m_Value(X), m_Value(Y)))) &&
(!isa<Constant>(Y) || !isa<Constant>(Op0))) {
@@ -1401,9 +1395,7 @@ Instruction *InstCombiner::visitFDiv(Bin
FMFIntersect &= cast<Instruction>(Op1)->getFastMathFlags();
YZInst->setFastMathFlags(FMFIntersect);
}
- Instruction *NewDiv = BinaryOperator::CreateFDiv(YZ, X);
- NewDiv->setFastMathFlags(I.getFastMathFlags());
- return NewDiv;
+ return BinaryOperator::CreateFDivFMF(YZ, X, &I);
}
}
More information about the llvm-commits
mailing list