Skip to content

Commit fdb78f8

Browse files
committed
InstCombine: fdiv -x, -y -> fdiv x, y
llvm-svn: 291611
1 parent 20d252c commit fdb78f8

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,16 @@ Instruction *InstCombiner::visitFDiv(BinaryOperator &I) {
14431443
}
14441444
}
14451445

1446+
Value *LHS;
1447+
Value *RHS;
1448+
1449+
// -x / -y -> x / y
1450+
if (match(Op0, m_FNeg(m_Value(LHS))) && match(Op1, m_FNeg(m_Value(RHS)))) {
1451+
I.setOperand(0, LHS);
1452+
I.setOperand(1, RHS);
1453+
return &I;
1454+
}
1455+
14461456
return nullptr;
14471457
}
14481458

llvm/test/Transforms/InstCombine/fdiv.ll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,21 @@ define float @test6(float %x, float %y, float %z) nounwind readnone ssp {
4949
; CHECK-NEXT: fmul fast
5050
; CHECK-NEXT: fdiv fast
5151
}
52+
53+
; CHECK-LABEL @fdiv_fneg_fneg(
54+
; CHECK: %div = fdiv float %x, %y
55+
define float @fdiv_fneg_fneg(float %x, float %y) {
56+
%x.fneg = fsub float -0.0, %x
57+
%y.fneg = fsub float -0.0, %y
58+
%div = fdiv float %x.fneg, %y.fneg
59+
ret float %div
60+
}
61+
62+
; CHECK-LABEL @fdiv_fneg_fneg_fast(
63+
; CHECK: %div = fdiv fast float %x, %y
64+
define float @fdiv_fneg_fneg_fast(float %x, float %y) {
65+
%x.fneg = fsub float -0.0, %x
66+
%y.fneg = fsub float -0.0, %y
67+
%div = fdiv fast float %x.fneg, %y.fneg
68+
ret float %div
69+
}

0 commit comments

Comments
 (0)