[llvm] r363082 - [InstCombine] Handle -(X-Y) --> (Y-X) for unary fneg when NSZ
Cameron McInally via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 11 09:21:21 PDT 2019
Author: mcinally
Date: Tue Jun 11 09:21:21 2019
New Revision: 363082
URL: http://llvm.org/viewvc/llvm-project?rev=363082&view=rev
Log:
[InstCombine] Handle -(X-Y) --> (Y-X) for unary fneg when NSZ
Differential Revision: https://reviews.llvm.org/D62612
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/trunk/test/Transforms/InstCombine/fsub.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp?rev=363082&r1=363081&r2=363082&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp Tue Jun 11 09:21:21 2019
@@ -1857,13 +1857,22 @@ static Instruction *foldFNegIntoConstant
}
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;
}
Modified: llvm/trunk/test/Transforms/InstCombine/fsub.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fsub.ll?rev=363082&r1=363081&r2=363082&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fsub.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fsub.ll Tue Jun 11 09:21:21 2019
@@ -38,11 +38,9 @@ define float @neg_sub_nsz(float %x, floa
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
More information about the llvm-commits
mailing list