[llvm] r329350 - [InstCombine] nsz: -(X - Y) --> Y - X
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 5 14:37:18 PDT 2018
Author: spatel
Date: Thu Apr 5 14:37:17 2018
New Revision: 329350
URL: http://llvm.org/viewvc/llvm-project?rev=329350&view=rev
Log:
[InstCombine] nsz: -(X - Y) --> Y - X
This restores part of the fold that was removed with rL73243 (PR4374).
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=329350&r1=329349&r2=329350&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp Thu Apr 5 14:37:17 2018
@@ -1698,10 +1698,17 @@ Instruction *InstCombiner::visitFSub(Bin
SQ.getWithInstruction(&I)))
return replaceInstUsesWith(I, V);
- // Subtraction from -0.0 is the canonical form of fneg.
- // fsub nsz 0, X ==> fsub nsz -0.0, X
- if (I.getFastMathFlags().noSignedZeros() && match(Op0, m_PosZeroFP()))
- return BinaryOperator::CreateFNegFMF(Op1, &I);
+ if (I.hasNoSignedZeros()) {
+ // Subtraction from -0.0 is the canonical form of fneg.
+ // fsub nsz 0, X ==> fsub nsz -0.0, X
+ if (match(Op0, m_PosZeroFP()))
+ return BinaryOperator::CreateFNegFMF(Op1, &I);
+
+ // With no-signed-zeros: -(X - Y) --> Y - X
+ Value *X, *Y;
+ if (match(Op0, m_NegZeroFP()) && match(Op1, m_FSub(m_Value(X), m_Value(Y))))
+ return BinaryOperator::CreateFSubFMF(Y, X, &I);
+ }
if (isa<Constant>(Op0))
if (SelectInst *SI = dyn_cast<SelectInst>(Op1))
Modified: llvm/trunk/test/Transforms/InstCombine/fsub.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fsub.ll?rev=329350&r1=329349&r2=329350&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fsub.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fsub.ll Thu Apr 5 14:37:17 2018
@@ -19,8 +19,7 @@ define float @test1(float %x, float %y)
define float @neg_sub(float %x, float %y) {
; CHECK-LABEL: @neg_sub(
-; CHECK-NEXT: [[T1:%.*]] = fsub float [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT: [[T2:%.*]] = fsub nsz float -0.000000e+00, [[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