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

[InstSimplify] fold fadd+fsub with common operand

llvm-svn: 339174
This commit is contained in:
Sanjay Patel 2018-08-07 20:23:49 +00:00
parent 3319c5d7e2
commit e2f9ad1467
2 changed files with 5 additions and 7 deletions

View File

@ -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;

View File

@ -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