diff --git a/lib/Analysis/InstructionSimplify.cpp b/lib/Analysis/InstructionSimplify.cpp index d0794364a73..22ced5a8665 100644 --- a/lib/Analysis/InstructionSimplify.cpp +++ b/lib/Analysis/InstructionSimplify.cpp @@ -4397,8 +4397,10 @@ static Value *SimplifyFSubInst(Value *Op0, Value *Op1, FastMathFlags FMF, return Constant::getNullValue(Op0->getType()); // Y - (Y - X) --> X + // (X + Y) - Y --> X if (FMF.noSignedZeros() && FMF.allowReassoc() && - match(Op1, m_FSub(m_Specific(Op0), m_Value(X)))) + (match(Op1, m_FSub(m_Specific(Op0), m_Value(X))) || + match(Op0, m_c_FAdd(m_Specific(Op1), m_Value(X))))) return X; return nullptr; diff --git a/test/Transforms/InstSimplify/floating-point-arithmetic.ll b/test/Transforms/InstSimplify/floating-point-arithmetic.ll index 6350c233a93..9c139d38621 100644 --- a/test/Transforms/InstSimplify/floating-point-arithmetic.ll +++ b/test/Transforms/InstSimplify/floating-point-arithmetic.ll @@ -799,9 +799,7 @@ define float @fsub_fsub_wrong_common_op_wrong_commute(float %x, float %y) { define float @fadd_fsub_common_op(float %x, float %y) { ; CHECK-LABEL: @fadd_fsub_common_op( -; CHECK-NEXT: [[A:%.*]] = fadd float [[Y:%.*]], [[X:%.*]] -; CHECK-NEXT: [[R:%.*]] = fsub reassoc nsz float [[A]], [[Y]] -; CHECK-NEXT: ret float [[R]] +; CHECK-NEXT: ret float [[X:%.*]] ; %a = fadd float %y, %x %r = fsub reassoc nsz float %a, %y @@ -812,9 +810,7 @@ define float @fadd_fsub_common_op(float %x, float %y) { define <2 x float> @fadd_fsub_common_op_commute_vec(<2 x float> %x, <2 x float> %y) { ; CHECK-LABEL: @fadd_fsub_common_op_commute_vec( -; CHECK-NEXT: [[A:%.*]] = fadd <2 x float> [[X:%.*]], [[Y:%.*]] -; CHECK-NEXT: [[R:%.*]] = fsub reassoc nsz <2 x float> [[A]], [[Y]] -; CHECK-NEXT: ret <2 x float> [[R]] +; CHECK-NEXT: ret <2 x float> [[X:%.*]] ; %a = fadd <2 x float> %x, %y %r = fsub reassoc nsz <2 x float> %a, %y