Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 8ff0fbb

Browse files
committed
[InstCombine] add and use Create*FMF functions; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@325730 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 2f11b47 commit 8ff0fbb

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

include/llvm/IR/InstrTypes.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,27 @@ class BinaryOperator : public Instruction {
391391
return BO;
392392
}
393393

394+
static BinaryOperator *CreateFAddFMF(Value *V1, Value *V2,
395+
BinaryOperator *FMFSource,
396+
const Twine &Name = "") {
397+
return CreateWithCopiedFlags(Instruction::FAdd, V1, V2, FMFSource, Name);
398+
}
399+
static BinaryOperator *CreateFSubFMF(Value *V1, Value *V2,
400+
BinaryOperator *FMFSource,
401+
const Twine &Name = "") {
402+
return CreateWithCopiedFlags(Instruction::FSub, V1, V2, FMFSource, Name);
403+
}
404+
static BinaryOperator *CreateFMulFMF(Value *V1, Value *V2,
405+
BinaryOperator *FMFSource,
406+
const Twine &Name = "") {
407+
return CreateWithCopiedFlags(Instruction::FMul, V1, V2, FMFSource, Name);
408+
}
409+
static BinaryOperator *CreateFDivFMF(Value *V1, Value *V2,
410+
BinaryOperator *FMFSource,
411+
const Twine &Name = "") {
412+
return CreateWithCopiedFlags(Instruction::FDiv, V1, V2, FMFSource, Name);
413+
}
414+
394415
static BinaryOperator *CreateNSW(BinaryOps Opc, Value *V1, Value *V2,
395416
const Twine &Name = "") {
396417
BinaryOperator *BO = Create(Opc, V1, V2, Name);

lib/Transforms/InstCombine/InstCombineMulDivRem.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,8 +1294,7 @@ static Instruction *foldFDivConstantDivisor(BinaryOperator &I) {
12941294
// -X / C --> X / -C
12951295
Value *X;
12961296
if (match(I.getOperand(0), m_FNeg(m_Value(X))))
1297-
return BinaryOperator::CreateWithCopiedFlags(Instruction::FDiv, X,
1298-
ConstantExpr::getFNeg(C), &I);
1297+
return BinaryOperator::CreateFDivFMF(X, ConstantExpr::getFNeg(C), &I);
12991298

13001299
// If the constant divisor has an exact inverse, this is always safe. If not,
13011300
// then we can still create a reciprocal if fast-math-flags allow it and the
@@ -1312,8 +1311,7 @@ static Instruction *foldFDivConstantDivisor(BinaryOperator &I) {
13121311
return nullptr;
13131312

13141313
// X / C --> X * (1 / C)
1315-
return BinaryOperator::CreateWithCopiedFlags(
1316-
Instruction::FMul, I.getOperand(0), RecipC, &I);
1314+
return BinaryOperator::CreateFMulFMF(I.getOperand(0), RecipC, &I);
13171315
}
13181316

13191317
/// Remove negation and try to reassociate constant math.
@@ -1324,10 +1322,8 @@ static Instruction *foldFDivConstantDividend(BinaryOperator &I) {
13241322

13251323
// C / -X --> -C / X
13261324
Value *X;
1327-
if (match(I.getOperand(1), m_FNeg(m_Value(X)))) {
1328-
return BinaryOperator::CreateWithCopiedFlags(
1329-
Instruction::FDiv, ConstantExpr::getFNeg(C), X, &I);
1330-
}
1325+
if (match(I.getOperand(1), m_FNeg(m_Value(X))))
1326+
return BinaryOperator::CreateFDivFMF(ConstantExpr::getFNeg(C), X, &I);
13311327

13321328
if (!I.hasAllowReassoc() || !I.hasAllowReciprocal())
13331329
return nullptr;
@@ -1348,7 +1344,7 @@ static Instruction *foldFDivConstantDividend(BinaryOperator &I) {
13481344
if (!NewC || !NewC->isNormalFP())
13491345
return nullptr;
13501346

1351-
return BinaryOperator::CreateWithCopiedFlags(Instruction::FDiv, NewC, X, &I);
1347+
return BinaryOperator::CreateFDivFMF(NewC, X, &I);
13521348
}
13531349

13541350
Instruction *InstCombiner::visitFDiv(BinaryOperator &I) {
@@ -1388,9 +1384,7 @@ Instruction *InstCombiner::visitFDiv(BinaryOperator &I) {
13881384
FMFIntersect &= cast<Instruction>(Op0)->getFastMathFlags();
13891385
YZInst->setFastMathFlags(FMFIntersect);
13901386
}
1391-
Instruction *NewDiv = BinaryOperator::CreateFDiv(X, YZ);
1392-
NewDiv->setFastMathFlags(I.getFastMathFlags());
1393-
return NewDiv;
1387+
return BinaryOperator::CreateFDivFMF(X, YZ, &I);
13941388
}
13951389
if (match(Op1, m_OneUse(m_FDiv(m_Value(X), m_Value(Y)))) &&
13961390
(!isa<Constant>(Y) || !isa<Constant>(Op0))) {
@@ -1401,9 +1395,7 @@ Instruction *InstCombiner::visitFDiv(BinaryOperator &I) {
14011395
FMFIntersect &= cast<Instruction>(Op1)->getFastMathFlags();
14021396
YZInst->setFastMathFlags(FMFIntersect);
14031397
}
1404-
Instruction *NewDiv = BinaryOperator::CreateFDiv(YZ, X);
1405-
NewDiv->setFastMathFlags(I.getFastMathFlags());
1406-
return NewDiv;
1398+
return BinaryOperator::CreateFDivFMF(YZ, X, &I);
14071399
}
14081400
}
14091401

0 commit comments

Comments
 (0)