[PATCH] D62612: [InstCombine] Handle -(X-Y) --> (Y-X) for unary fneg when NSZ
Cameron McInally via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 29 10:33:17 PDT 2019
cameron.mcinally created this revision.
cameron.mcinally added reviewers: spatel, craig.topper, andrew.w.kaylor, kpn, arsenm.
Herald added subscribers: llvm-commits, hiraditya, wdng.
Herald added a project: LLVM.
Repository:
rL LLVM
https://reviews.llvm.org/D62612
Files:
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/test/Transforms/InstCombine/fsub.ll
Index: llvm/test/Transforms/InstCombine/fsub.ll
===================================================================
--- llvm/test/Transforms/InstCombine/fsub.ll
+++ llvm/test/Transforms/InstCombine/fsub.ll
@@ -27,11 +27,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
Index: llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1845,13 +1845,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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62612.201978.patch
Type: text/x-patch
Size: 1547 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190529/97c3d4d5/attachment.bin>
More information about the llvm-commits
mailing list