return BinaryOperator::CreateFMulFMF(X, NewMulC, &I);
}
+ // (-X - Y) + (X + Z) --> Z - Y
+ if (match(&I, m_c_FAdd(m_FSub(m_FNeg(m_Value(X)), m_Value(Y)),
+ m_c_FAdd(m_Deferred(X), m_Value(Z)))))
+ return BinaryOperator::CreateFSubFMF(Z, Y, &I);
+
if (Value *V = FAddCombine(Builder).simplify(&I))
return replaceInstUsesWith(I, V);
}
; CHECK-LABEL: @fadd_fneg_reass_commute0(
; CHECK-NEXT: [[N:%.*]] = fneg reassoc nsz float [[X:%.*]]
; CHECK-NEXT: call void @use(float [[N]])
-; CHECK-NEXT: [[S:%.*]] = fsub reassoc nsz float [[N]], [[Y:%.*]]
-; CHECK-NEXT: [[A:%.*]] = fadd reassoc nsz float [[X]], [[Z:%.*]]
-; CHECK-NEXT: [[R:%.*]] = fadd reassoc nsz float [[S]], [[A]]
+; CHECK-NEXT: [[R:%.*]] = fsub reassoc nsz float [[Z:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret float [[R]]
;
%n = fneg reassoc nsz float %x
; CHECK-NEXT: call void @use(float [[N]])
; CHECK-NEXT: [[S:%.*]] = fsub float [[N]], [[Y:%.*]]
; CHECK-NEXT: call void @use(float [[S]])
-; CHECK-NEXT: [[A:%.*]] = fadd float [[X]], [[Z:%.*]]
-; CHECK-NEXT: [[R:%.*]] = fadd reassoc nsz float [[A]], [[S]]
+; CHECK-NEXT: [[R:%.*]] = fsub reassoc nsz float [[Z:%.*]], [[Y]]
; CHECK-NEXT: ret float [[R]]
;
%n = fneg float %x
; CHECK-NEXT: call void @use(float [[S]])
; CHECK-NEXT: [[A:%.*]] = fadd float [[Z:%.*]], [[X]]
; CHECK-NEXT: call void @use(float [[A]])
-; CHECK-NEXT: [[R:%.*]] = fadd fast float [[S]], [[A]]
+; CHECK-NEXT: [[R:%.*]] = fsub fast float [[Z]], [[Y]]
; CHECK-NEXT: ret float [[R]]
;
%n = fneg float %x
; CHECK-LABEL: @fadd_fneg_reass_commute3(
; CHECK-NEXT: [[N:%.*]] = fneg reassoc nsz <2 x float> [[X:%.*]]
; CHECK-NEXT: call void @use_vec(<2 x float> [[N]])
-; CHECK-NEXT: [[S:%.*]] = fsub reassoc nsz <2 x float> [[N]], [[Y:%.*]]
-; CHECK-NEXT: [[A:%.*]] = fadd reassoc nsz <2 x float> [[Z:%.*]], [[X]]
-; CHECK-NEXT: [[R:%.*]] = fadd reassoc nsz <2 x float> [[A]], [[S]]
+; CHECK-NEXT: [[R:%.*]] = fsub reassoc nsz <2 x float> [[Z:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret <2 x float> [[R]]
;
%n = fneg reassoc nsz <2 x float> %x
ret <2 x float> %r
}
+; negative test - need reassoc (+ nsz)
+
define float @fadd_fneg_commute0(float %x, float %y, float %z) {
; CHECK-LABEL: @fadd_fneg_commute0(
; CHECK-NEXT: [[N:%.*]] = fneg float [[X:%.*]]