mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-01 05:01:59 +01:00
[InstCombine] Handle -(X-Y) --> (Y-X) for unary fneg when NSZ
Differential Revision: https://reviews.llvm.org/D62612 llvm-svn: 363082
This commit is contained in:
parent
f743742a51
commit
e131342efa
@ -1857,13 +1857,22 @@ static Instruction *foldFNegIntoConstant(Instruction &I) {
|
||||
}
|
||||
|
||||
Instruction *InstCombiner::visitFNeg(UnaryOperator &I) {
|
||||
if (Value *V = SimplifyFNegInst(I.getOperand(0), I.getFastMathFlags(),
|
||||
Value *Op = I.getOperand(0);
|
||||
|
||||
if (Value *V = SimplifyFNegInst(Op, I.getFastMathFlags(),
|
||||
SQ.getWithInstruction(&I)))
|
||||
return replaceInstUsesWith(I, V);
|
||||
|
||||
if (Instruction *X = foldFNegIntoConstant(I))
|
||||
return X;
|
||||
|
||||
Value *X, *Y;
|
||||
|
||||
// If we can ignore the sign of zeros: -(X - Y) --> (Y - X)
|
||||
if (I.hasNoSignedZeros() &&
|
||||
match(Op, m_OneUse(m_FSub(m_Value(X), m_Value(Y)))))
|
||||
return BinaryOperator::CreateFSubFMF(Y, X, &I);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -38,11 +38,9 @@ define float @neg_sub_nsz(float %x, float %y) {
|
||||
ret float %t2
|
||||
}
|
||||
|
||||
; FIXME: This combine isn't working.
|
||||
define float @unary_neg_sub_nsz(float %x, float %y) {
|
||||
; CHECK-LABEL: @unary_neg_sub_nsz(
|
||||
; CHECK-NEXT: [[T1:%.*]] = fsub float [[X:%.*]], [[Y:%.*]]
|
||||
; CHECK-NEXT: [[T2:%.*]] = fneg nsz float [[T1]]
|
||||
; CHECK-NEXT: [[T2:%.*]] = fsub nsz float [[Y:%.*]], [[X:%.*]]
|
||||
; CHECK-NEXT: ret float [[T2]]
|
||||
;
|
||||
%t1 = fsub float %x, %y
|
||||
|
Loading…
x
Reference in New Issue
Block a user