diff options
| author | Sanjay Patel <spatel@rotateright.com> | 2018-04-05 17:06:45 +0000 |
|---|---|---|
| committer | Sanjay Patel <spatel@rotateright.com> | 2018-04-05 17:06:45 +0000 |
| commit | deaf4f354ee0dab9163891532f7264b181876d95 (patch) | |
| tree | fccbdffea9df16d7bedf9446006c8184832224c3 /llvm | |
| parent | cfd44a2e69fa0897d944bc66ca517a7d079c135d (diff) | |
| download | bcm5719-llvm-deaf4f354ee0dab9163891532f7264b181876d95.tar.gz bcm5719-llvm-deaf4f354ee0dab9163891532f7264b181876d95.zip | |
[InstCombine] use pattern matchers for fsub --> fadd folds
This allows folding for vectors with undef elements.
llvm-svn: 329316
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | 13 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstCombine/fsub.ll | 5 |
2 files changed, 11 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp index 1f04a8b3a3a..578ba23604d 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp @@ -1708,10 +1708,15 @@ Instruction *InstCombiner::visitFSub(BinaryOperator &I) { 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))) { diff --git a/llvm/test/Transforms/InstCombine/fsub.ll b/llvm/test/Transforms/InstCombine/fsub.ll index 359462638d3..9323a2dd772 100644 --- a/llvm/test/Transforms/InstCombine/fsub.ll +++ b/llvm/test/Transforms/InstCombine/fsub.ll @@ -49,7 +49,7 @@ define <2 x float> @constant_op1_vec(<2 x float> %x, <2 x float> %y) { 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 float> %x, <2 x float> %y) { 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 |

