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

[InstCombine] fold fsub+fsub with common operand

This is a sibling to the simplify from:
rL339171

llvm-svn: 339266
This commit is contained in:
Sanjay Patel 2018-08-08 16:04:48 +00:00
parent 4899351421
commit d8df616a92
2 changed files with 11 additions and 4 deletions

View File

@ -1907,6 +1907,14 @@ Instruction *InstCombiner::visitFSub(BinaryOperator &I) {
return replaceInstUsesWith(I, V); return replaceInstUsesWith(I, V);
if (I.hasAllowReassoc() && I.hasNoSignedZeros()) { if (I.hasAllowReassoc() && I.hasNoSignedZeros()) {
// (Y - X) - Y --> -X
if (match(Op0, m_FSub(m_Specific(Op1), m_Value(X))))
return BinaryOperator::CreateFNegFMF(X, &I);
// TODO: This performs reassociative folds for FP ops. Some fraction of the
// functionality has been subsumed by simple pattern matching here and in
// InstSimplify. We should let a dedicated reassociation pass handle more
// complex pattern matching and remove this from InstCombine.
if (Value *V = FAddCombine(Builder).simplify(&I)) if (Value *V = FAddCombine(Builder).simplify(&I))
return replaceInstUsesWith(I, V); return replaceInstUsesWith(I, V);
} }

View File

@ -335,8 +335,8 @@ define <2 x float> @fsub_fadd_common_op_fneg_commute_vec(<2 x float> %x, <2 x fl
define float @fsub_fsub_common_op_fneg(float %x, float %y) { define float @fsub_fsub_common_op_fneg(float %x, float %y) {
; CHECK-LABEL: @fsub_fsub_common_op_fneg( ; CHECK-LABEL: @fsub_fsub_common_op_fneg(
; CHECK-NEXT: [[TMP1:%.*]] = fsub reassoc nsz float -0.000000e+00, [[X:%.*]] ; CHECK-NEXT: [[R:%.*]] = fsub reassoc nsz float -0.000000e+00, [[X:%.*]]
; CHECK-NEXT: ret float [[TMP1]] ; CHECK-NEXT: ret float [[R]]
; ;
%s = fsub float %y, %x %s = fsub float %y, %x
%r = fsub reassoc nsz float %s, %y %r = fsub reassoc nsz float %s, %y
@ -347,8 +347,7 @@ define float @fsub_fsub_common_op_fneg(float %x, float %y) {
define <2 x float> @fsub_fsub_common_op_fneg_vec(<2 x float> %x, <2 x float> %y) { define <2 x float> @fsub_fsub_common_op_fneg_vec(<2 x float> %x, <2 x float> %y) {
; CHECK-LABEL: @fsub_fsub_common_op_fneg_vec( ; CHECK-LABEL: @fsub_fsub_common_op_fneg_vec(
; CHECK-NEXT: [[S:%.*]] = fsub <2 x float> [[Y:%.*]], [[X:%.*]] ; CHECK-NEXT: [[R:%.*]] = fsub reassoc nsz <2 x float> <float -0.000000e+00, float -0.000000e+00>, [[X:%.*]]
; CHECK-NEXT: [[R:%.*]] = fsub reassoc nsz <2 x float> [[S]], [[Y]]
; CHECK-NEXT: ret <2 x float> [[R]] ; CHECK-NEXT: ret <2 x float> [[R]]
; ;
%s = fsub <2 x float> %y, %x %s = fsub <2 x float> %y, %x