summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2018-04-16 14:13:57 +0000
committerSanjay Patel <spatel@rotateright.com>2018-04-16 14:13:57 +0000
commit1170daa2775bbbc865e98e457bc5aed1bafa767b (patch)
tree18566bb7dd96d354cc6997b9f929dd3ae8e83985 /llvm/lib/Transforms
parent77e990d88700c52ef5aa7d5e0cb5487928b26533 (diff)
downloadbcm5719-llvm-1170daa2775bbbc865e98e457bc5aed1bafa767b.tar.gz
bcm5719-llvm-1170daa2775bbbc865e98e457bc5aed1bafa767b.zip
[InstCombine] simplify fneg+fadd folds; NFC
Two cleanups: 1. As noted in D45453, we had tests that don't need FMF that were misplaced in the 'fast-math.ll' test file. 2. This removes the final uses of dyn_castFNegVal, so that can be deleted. We use 'match' now. llvm-svn: 330126
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp15
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineInternal.h1
-rw-r--r--llvm/lib/Transforms/InstCombine/InstructionCombining.cpp17
3 files changed, 7 insertions, 26 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index 11cf4d21b61..f5b0d5be21a 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1308,14 +1308,13 @@ Instruction *InstCombiner::visitFAdd(BinaryOperator &I) {
if (Instruction *FoldedFAdd = foldBinOpIntoSelectOrPhi(I))
return FoldedFAdd;
- // -A + B --> B - A
- if (Value *LHSV = dyn_castFNegVal(LHS))
- return BinaryOperator::CreateFSubFMF(RHS, LHSV, &I);
-
- // A + -B --> A - B
- if (!isa<Constant>(RHS))
- if (Value *V = dyn_castFNegVal(RHS))
- return BinaryOperator::CreateFSubFMF(LHS, V, &I);
+ Value *X;
+ // (-X) + Y --> Y - X
+ if (match(LHS, m_FNeg(m_Value(X))))
+ return BinaryOperator::CreateFSubFMF(RHS, X, &I);
+ // Y + (-X) --> Y - X
+ if (match(RHS, m_FNeg(m_Value(X))))
+ return BinaryOperator::CreateFSubFMF(LHS, X, &I);
// Check for (fadd double (sitofp x), y), see if we can merge this into an
// integer add followed by a promotion.
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
index 40cfc3051c2..915047ec3e7 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
+++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
@@ -376,7 +376,6 @@ private:
bool shouldChangeType(unsigned FromBitWidth, unsigned ToBitWidth) const;
bool shouldChangeType(Type *From, Type *To) const;
Value *dyn_castNegVal(Value *V) const;
- Value *dyn_castFNegVal(Value *V, bool NoSignedZero = false) const;
Type *FindElementAtOffset(PointerType *PtrTy, int64_t Offset,
SmallVectorImpl<Value *> &NewIndices);
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 167023c4ac9..af4449a9dd2 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -790,23 +790,6 @@ Value *InstCombiner::dyn_castNegVal(Value *V) const {
return nullptr;
}
-/// Given a 'fsub' instruction, return the RHS of the instruction if the LHS is
-/// a constant negative zero (which is the 'negate' form).
-Value *InstCombiner::dyn_castFNegVal(Value *V, bool IgnoreZeroSign) const {
- if (BinaryOperator::isFNeg(V, IgnoreZeroSign))
- return BinaryOperator::getFNegArgument(V);
-
- // Constants can be considered to be negated values if they can be folded.
- if (ConstantFP *C = dyn_cast<ConstantFP>(V))
- return ConstantExpr::getFNeg(C);
-
- if (ConstantDataVector *C = dyn_cast<ConstantDataVector>(V))
- if (C->getType()->getElementType()->isFloatingPointTy())
- return ConstantExpr::getFNeg(C);
-
- return nullptr;
-}
-
static Value *foldOperationIntoSelectOperand(Instruction &I, Value *SO,
InstCombiner::BuilderTy &Builder) {
if (auto *Cast = dyn_cast<CastInst>(&I))
OpenPOWER on IntegriCloud