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

[InstSimplify] fold fsub+fadd with common operand

llvm-svn: 339176
This commit is contained in:
Sanjay Patel 2018-08-07 20:32:55 +00:00
parent e2f9ad1467
commit 737ecebced
2 changed files with 10 additions and 6 deletions

View File

@ -4359,6 +4359,14 @@ static Value *SimplifyFAddInst(Value *Op0, Value *Op1, FastMathFlags FMF,
match(Op1, m_FSub(m_AnyZeroFP(), m_Specific(Op0)))))
return ConstantFP::getNullValue(Op0->getType());
// (X - Y) + Y --> X
// Y + (X - Y) --> X
Value *X;
if (FMF.noSignedZeros() && FMF.allowReassoc() &&
(match(Op0, m_FSub(m_Value(X), m_Specific(Op1))) ||
match(Op1, m_FSub(m_Value(X), m_Specific(Op0)))))
return X;
return nullptr;
}

View File

@ -849,9 +849,7 @@ define float @fadd_fsub_common_op_wrong_commute_commute(float %x, float %y) {
define <2 x float> @fsub_fadd_common_op_vec(<2 x float> %x, <2 x float> %y) {
; CHECK-LABEL: @fsub_fadd_common_op_vec(
; CHECK-NEXT: [[S:%.*]] = fsub <2 x float> [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[R:%.*]] = fadd reassoc nsz <2 x float> [[Y]], [[S]]
; CHECK-NEXT: ret <2 x float> [[R]]
; CHECK-NEXT: ret <2 x float> [[X:%.*]]
;
%s = fsub <2 x float> %x, %y
%r = fadd reassoc nsz <2 x float> %y, %s
@ -862,9 +860,7 @@ define <2 x float> @fsub_fadd_common_op_vec(<2 x float> %x, <2 x float> %y) {
define float @fsub_fadd_common_op_commute(float %x, float %y) {
; CHECK-LABEL: @fsub_fadd_common_op_commute(
; CHECK-NEXT: [[S:%.*]] = fsub float [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[R:%.*]] = fadd reassoc nsz float [[S]], [[Y]]
; CHECK-NEXT: ret float [[R]]
; CHECK-NEXT: ret float [[X:%.*]]
;
%s = fsub float %x, %y
%r = fadd reassoc nsz float %s, %y