forked from OSchip/llvm-project
[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
This commit is contained in:
parent
77e990d887
commit
1170daa277
|
@ -1308,14 +1308,13 @@ Instruction *InstCombiner::visitFAdd(BinaryOperator &I) {
|
||||||
if (Instruction *FoldedFAdd = foldBinOpIntoSelectOrPhi(I))
|
if (Instruction *FoldedFAdd = foldBinOpIntoSelectOrPhi(I))
|
||||||
return FoldedFAdd;
|
return FoldedFAdd;
|
||||||
|
|
||||||
// -A + B --> B - A
|
Value *X;
|
||||||
if (Value *LHSV = dyn_castFNegVal(LHS))
|
// (-X) + Y --> Y - X
|
||||||
return BinaryOperator::CreateFSubFMF(RHS, LHSV, &I);
|
if (match(LHS, m_FNeg(m_Value(X))))
|
||||||
|
return BinaryOperator::CreateFSubFMF(RHS, X, &I);
|
||||||
// A + -B --> A - B
|
// Y + (-X) --> Y - X
|
||||||
if (!isa<Constant>(RHS))
|
if (match(RHS, m_FNeg(m_Value(X))))
|
||||||
if (Value *V = dyn_castFNegVal(RHS))
|
return BinaryOperator::CreateFSubFMF(LHS, X, &I);
|
||||||
return BinaryOperator::CreateFSubFMF(LHS, V, &I);
|
|
||||||
|
|
||||||
// Check for (fadd double (sitofp x), y), see if we can merge this into an
|
// Check for (fadd double (sitofp x), y), see if we can merge this into an
|
||||||
// integer add followed by a promotion.
|
// integer add followed by a promotion.
|
||||||
|
|
|
@ -376,7 +376,6 @@ private:
|
||||||
bool shouldChangeType(unsigned FromBitWidth, unsigned ToBitWidth) const;
|
bool shouldChangeType(unsigned FromBitWidth, unsigned ToBitWidth) const;
|
||||||
bool shouldChangeType(Type *From, Type *To) const;
|
bool shouldChangeType(Type *From, Type *To) const;
|
||||||
Value *dyn_castNegVal(Value *V) const;
|
Value *dyn_castNegVal(Value *V) const;
|
||||||
Value *dyn_castFNegVal(Value *V, bool NoSignedZero = false) const;
|
|
||||||
Type *FindElementAtOffset(PointerType *PtrTy, int64_t Offset,
|
Type *FindElementAtOffset(PointerType *PtrTy, int64_t Offset,
|
||||||
SmallVectorImpl<Value *> &NewIndices);
|
SmallVectorImpl<Value *> &NewIndices);
|
||||||
|
|
||||||
|
|
|
@ -790,23 +790,6 @@ Value *InstCombiner::dyn_castNegVal(Value *V) const {
|
||||||
return nullptr;
|
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,
|
static Value *foldOperationIntoSelectOperand(Instruction &I, Value *SO,
|
||||||
InstCombiner::BuilderTy &Builder) {
|
InstCombiner::BuilderTy &Builder) {
|
||||||
if (auto *Cast = dyn_cast<CastInst>(&I))
|
if (auto *Cast = dyn_cast<CastInst>(&I))
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
||||||
|
; RUN: opt < %s -instcombine -S | FileCheck %s
|
||||||
|
|
||||||
|
; -x + y => y - x
|
||||||
|
|
||||||
|
define float @fneg_op0(float %x, float %y) {
|
||||||
|
; CHECK-LABEL: @fneg_op0(
|
||||||
|
; CHECK-NEXT: [[ADD:%.*]] = fsub float [[Y:%.*]], [[X:%.*]]
|
||||||
|
; CHECK-NEXT: ret float [[ADD]]
|
||||||
|
;
|
||||||
|
%neg = fsub float -0.0, %x
|
||||||
|
%add = fadd float %neg, %y
|
||||||
|
ret float %add
|
||||||
|
}
|
||||||
|
|
||||||
|
; x + -y => x - y
|
||||||
|
|
||||||
|
define float @fneg_op1(float %x, float %y) {
|
||||||
|
; CHECK-LABEL: @fneg_op1(
|
||||||
|
; CHECK-NEXT: [[ADD:%.*]] = fsub float [[X:%.*]], [[Y:%.*]]
|
||||||
|
; CHECK-NEXT: ret float [[ADD]]
|
||||||
|
;
|
||||||
|
%neg = fsub float -0.0, %y
|
||||||
|
%add = fadd float %x, %neg
|
||||||
|
ret float %add
|
||||||
|
}
|
||||||
|
|
|
@ -406,30 +406,6 @@ define float @fold13_reassoc(float %x) {
|
||||||
ret float %sub
|
ret float %sub
|
||||||
}
|
}
|
||||||
|
|
||||||
; -x + y => y - x
|
|
||||||
; This is always safe. No FMF required.
|
|
||||||
define float @fold14(float %x, float %y) {
|
|
||||||
; CHECK-LABEL: @fold14(
|
|
||||||
; CHECK-NEXT: [[ADD:%.*]] = fsub float [[Y:%.*]], [[X:%.*]]
|
|
||||||
; CHECK-NEXT: ret float [[ADD]]
|
|
||||||
;
|
|
||||||
%neg = fsub float -0.0, %x
|
|
||||||
%add = fadd float %neg, %y
|
|
||||||
ret float %add
|
|
||||||
}
|
|
||||||
|
|
||||||
; x + -y => x - y
|
|
||||||
; This is always safe. No FMF required.
|
|
||||||
define float @fold15(float %x, float %y) {
|
|
||||||
; CHECK-LABEL: @fold15(
|
|
||||||
; CHECK-NEXT: [[ADD:%.*]] = fsub float [[X:%.*]], [[Y:%.*]]
|
|
||||||
; CHECK-NEXT: ret float [[ADD]]
|
|
||||||
;
|
|
||||||
%neg = fsub float -0.0, %y
|
|
||||||
%add = fadd float %x, %neg
|
|
||||||
ret float %add
|
|
||||||
}
|
|
||||||
|
|
||||||
; (select X+Y, X-Y) => X + (select Y, -Y)
|
; (select X+Y, X-Y) => X + (select Y, -Y)
|
||||||
; This is always safe. No FMF required.
|
; This is always safe. No FMF required.
|
||||||
define float @fold16(float %x, float %y) {
|
define float @fold16(float %x, float %y) {
|
||||||
|
|
Loading…
Reference in New Issue