[PATCH] D62612: [InstCombine] Handle -(X-Y) --> (Y-X) for unary fneg when NSZ
Phabricator via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 11 09:18:16 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363082: [InstCombine] Handle -(X-Y) --> (Y-X) for unary fneg when NSZ (authored by mcinally, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D62612?vs=201978&id=204083#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D62612/new/
https://reviews.llvm.org/D62612
Files:
llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/trunk/test/Transforms/InstCombine/fsub.ll
Index: llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
===================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1857,13 +1857,22 @@
}
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;
}
Index: llvm/trunk/test/Transforms/InstCombine/fsub.ll
===================================================================
--- llvm/trunk/test/Transforms/InstCombine/fsub.ll
+++ llvm/trunk/test/Transforms/InstCombine/fsub.ll
@@ -38,11 +38,9 @@
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62612.204083.patch
Type: text/x-patch
Size: 1583 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190611/49361f43/attachment.bin>
More information about the llvm-commits
mailing list