diff options
| author | Sanjay Patel <spatel@rotateright.com> | 2018-08-07 20:23:49 +0000 |
|---|---|---|
| committer | Sanjay Patel <spatel@rotateright.com> | 2018-08-07 20:23:49 +0000 |
| commit | 4364d604c21141794a274166e6b3925e51887e31 (patch) | |
| tree | 0aade90024179953e009b3a4d6f8ea66d6b0eee9 /llvm | |
| parent | 52d5283483cb21c0512b432d9beea3c4dc1f45b3 (diff) | |
| download | bcm5719-llvm-4364d604c21141794a274166e6b3925e51887e31.tar.gz bcm5719-llvm-4364d604c21141794a274166e6b3925e51887e31.zip | |
[InstSimplify] fold fadd+fsub with common operand
llvm-svn: 339174
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 4 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll | 8 |
2 files changed, 5 insertions, 7 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index d0794364a73..22ced5a8665 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/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/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll b/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll index 6350c233a93..9c139d38621 100644 --- a/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll +++ b/llvm/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 |

