1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 19:52:54 +01:00

[InstCombine] use pattern matchers for fsub --> fadd folds

This allows folding for vectors with undef elements.

llvm-svn: 329316
This commit is contained in:
Sanjay Patel 2018-04-05 17:06:45 +00:00
parent 54e725ee42
commit 616ed63ebd
2 changed files with 11 additions and 7 deletions

View File

@ -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))) {

View File

@ -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