[llvm] r329316 - [InstCombine] use pattern matchers for fsub --> fadd folds
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 5 10:06:45 PDT 2018
Author: spatel
Date: Thu Apr 5 10:06:45 2018
New Revision: 329316
URL: http://llvm.org/viewvc/llvm-project?rev=329316&view=rev
Log:
[InstCombine] use pattern matchers for fsub --> fadd folds
This allows folding for vectors with undef elements.
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=329316&r1=329315&r2=329316&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp Thu Apr 5 10:06:45 2018
@@ -1708,10 +1708,15 @@ Instruction *InstCombiner::visitFSub(Bin
if (Instruction *NV = FoldOpIntoSelect(I, SI))
return NV;
- // If this is a 'B = x-(-A)', change to B = x+A, potentially looking
- // through FP extensions/truncations along the way.
- if (Value *V = dyn_castFNegVal(Op1))
- return BinaryOperator::CreateFAddFMF(Op0, V, &I);
+ // X - C --> X + (-C)
+ Constant *C;
+ if (match(Op1, m_Constant(C)))
+ return BinaryOperator::CreateFAddFMF(Op0, ConstantExpr::getFNeg(C), &I);
+
+ // X - (-Y) --> X + Y
+ Value *Y;
+ if (match(Op1, m_FNeg(m_Value(Y))))
+ return BinaryOperator::CreateFAddFMF(Op0, Y, &I);
if (FPTruncInst *FPTI = dyn_cast<FPTruncInst>(Op1)) {
if (Value *V = dyn_castFNegVal(FPTI->getOperand(0))) {
Modified: llvm/trunk/test/Transforms/InstCombine/fsub.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fsub.ll?rev=329316&r1=329315&r2=329316&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fsub.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fsub.ll Thu Apr 5 10:06:45 2018
@@ -49,7 +49,7 @@ define <2 x float> @constant_op1_vec(<2
define <2 x float> @constant_op1_vec_undef(<2 x float> %x, <2 x float> %y) {
; CHECK-LABEL: @constant_op1_vec_undef(
-; CHECK-NEXT: [[R:%.*]] = fsub <2 x float> [[X:%.*]], <float undef, float -4.200000e+01>
+; CHECK-NEXT: [[R:%.*]] = fadd <2 x float> [[X:%.*]], <float 0x7FF8000000000000, float 4.200000e+01>
; CHECK-NEXT: ret <2 x float> [[R]]
;
%r = fsub <2 x float> %x, <float undef, float -42.0>
@@ -80,8 +80,7 @@ define <2 x float> @neg_op1_vec(<2 x flo
define <2 x float> @neg_op1_vec_undef(<2 x float> %x, <2 x float> %y) {
; CHECK-LABEL: @neg_op1_vec_undef(
-; CHECK-NEXT: [[NEGY:%.*]] = fsub <2 x float> <float -0.000000e+00, float undef>, [[Y:%.*]]
-; CHECK-NEXT: [[R:%.*]] = fsub <2 x float> [[X:%.*]], [[NEGY]]
+; CHECK-NEXT: [[R:%.*]] = fadd <2 x float> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret <2 x float> [[R]]
;
%negy = fsub <2 x float> <float -0.0, float undef>, %y
More information about the llvm-commits
mailing list