InstCombine: fdiv -x, -y -> fdiv x, y

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291611 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Matt Arsenault 2017-01-10 23:08:54 +00:00
parent ada6595a52
commit 3aa9c7e336
2 changed files with 28 additions and 0 deletions

View File

@ -1443,6 +1443,16 @@ Instruction *InstCombiner::visitFDiv(BinaryOperator &I) {
}
}
Value *LHS;
Value *RHS;
// -x / -y -> x / y
if (match(Op0, m_FNeg(m_Value(LHS))) && match(Op1, m_FNeg(m_Value(RHS)))) {
I.setOperand(0, LHS);
I.setOperand(1, RHS);
return &I;
}
return nullptr;
}

View File

@ -49,3 +49,21 @@ define float @test6(float %x, float %y, float %z) nounwind readnone ssp {
; CHECK-NEXT: fmul fast
; CHECK-NEXT: fdiv fast
}
; CHECK-LABEL @fdiv_fneg_fneg(
; CHECK: %div = fdiv float %x, %y
define float @fdiv_fneg_fneg(float %x, float %y) {
%x.fneg = fsub float -0.0, %x
%y.fneg = fsub float -0.0, %y
%div = fdiv float %x.fneg, %y.fneg
ret float %div
}
; CHECK-LABEL @fdiv_fneg_fneg_fast(
; CHECK: %div = fdiv fast float %x, %y
define float @fdiv_fneg_fneg_fast(float %x, float %y) {
%x.fneg = fsub float -0.0, %x
%y.fneg = fsub float -0.0, %y
%div = fdiv fast float %x.fneg, %y.fneg
ret float %div
}