diff options
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 10 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstCombine/minmax-fp.ll | 28 |
2 files changed, 17 insertions, 21 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index ef72f3bbb72..ce6b38c90ca 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -5518,6 +5518,11 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) { } } + // fcmp pred (fneg X), (fneg Y) -> fcmp swap(pred) X, Y + Value *X, *Y; + if (match(Op0, m_FNeg(m_Value(X))) && match(Op1, m_FNeg(m_Value(Y)))) + return new FCmpInst(I.getSwappedPredicate(), X, Y, "", &I); + // Test if the FCmpInst instruction is used exclusively by a select as // part of a minimum or maximum operation. If so, refrain from doing // any other folding. This helps out other analyses which understand @@ -5576,12 +5581,7 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) { if (Instruction *R = foldFabsWithFcmpZero(I)) return R; - Value *X, *Y; if (match(Op0, m_FNeg(m_Value(X)))) { - // fcmp pred (fneg X), (fneg Y) -> fcmp swap(pred) X, Y - if (match(Op1, m_FNeg(m_Value(Y)))) - return new FCmpInst(I.getSwappedPredicate(), X, Y, "", &I); - // fcmp pred (fneg X), C --> fcmp swap(pred) X, -C Constant *C; if (match(Op1, m_Constant(C))) { diff --git a/llvm/test/Transforms/InstCombine/minmax-fp.ll b/llvm/test/Transforms/InstCombine/minmax-fp.ll index 9cdbf4f2d80..e139137727c 100644 --- a/llvm/test/Transforms/InstCombine/minmax-fp.ll +++ b/llvm/test/Transforms/InstCombine/minmax-fp.ll @@ -257,10 +257,9 @@ define double @t17(i32 %x) { define float @fneg_fmax(float %x, float %y) { ; CHECK-LABEL: @fneg_fmax( -; CHECK-NEXT: [[N1:%.*]] = fneg float [[X:%.*]] -; CHECK-NEXT: [[N2:%.*]] = fneg float [[Y:%.*]] -; CHECK-NEXT: [[COND:%.*]] = fcmp nnan ogt float [[N1]], [[N2]] -; CHECK-NEXT: [[MAX:%.*]] = select i1 [[COND]], float [[N1]], float [[N2]] +; CHECK-NEXT: [[COND:%.*]] = fcmp nnan olt float [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[MAX_V:%.*]] = select i1 [[COND]], float [[X]], float [[Y]] +; CHECK-NEXT: [[MAX:%.*]] = fneg float [[MAX_V]] ; CHECK-NEXT: ret float [[MAX]] ; %n1 = fneg float %x @@ -272,10 +271,9 @@ define float @fneg_fmax(float %x, float %y) { define <2 x float> @fsub_fmax(<2 x float> %x, <2 x float> %y) { ; CHECK-LABEL: @fsub_fmax( -; CHECK-NEXT: [[N1:%.*]] = fsub <2 x float> <float -0.000000e+00, float -0.000000e+00>, [[X:%.*]] -; CHECK-NEXT: [[N2:%.*]] = fsub <2 x float> <float -0.000000e+00, float -0.000000e+00>, [[Y:%.*]] -; CHECK-NEXT: [[COND_INV:%.*]] = fcmp nnan nsz olt <2 x float> [[N1]], [[N2]] -; CHECK-NEXT: [[MAX:%.*]] = select <2 x i1> [[COND_INV]], <2 x float> [[N2]], <2 x float> [[N1]] +; CHECK-NEXT: [[COND_INV:%.*]] = fcmp nnan nsz ogt <2 x float> [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[MAX_V:%.*]] = select <2 x i1> [[COND_INV]], <2 x float> [[Y]], <2 x float> [[X]] +; CHECK-NEXT: [[MAX:%.*]] = fsub <2 x float> <float -0.000000e+00, float -0.000000e+00>, [[MAX_V]] ; CHECK-NEXT: ret <2 x float> [[MAX]] ; %n1 = fsub <2 x float> <float -0.0, float -0.0>, %x @@ -287,10 +285,9 @@ define <2 x float> @fsub_fmax(<2 x float> %x, <2 x float> %y) { define <2 x double> @fsub_fmin(<2 x double> %x, <2 x double> %y) { ; CHECK-LABEL: @fsub_fmin( -; CHECK-NEXT: [[N1:%.*]] = fsub <2 x double> <double -0.000000e+00, double -0.000000e+00>, [[X:%.*]] -; CHECK-NEXT: [[N2:%.*]] = fsub <2 x double> <double -0.000000e+00, double -0.000000e+00>, [[Y:%.*]] -; CHECK-NEXT: [[COND:%.*]] = fcmp nnan olt <2 x double> [[N1]], [[N2]] -; CHECK-NEXT: [[MAX:%.*]] = select <2 x i1> [[COND]], <2 x double> [[N1]], <2 x double> [[N2]] +; CHECK-NEXT: [[COND:%.*]] = fcmp nnan ogt <2 x double> [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[MAX_V:%.*]] = select <2 x i1> [[COND]], <2 x double> [[X]], <2 x double> [[Y]] +; CHECK-NEXT: [[MAX:%.*]] = fsub <2 x double> <double -0.000000e+00, double -0.000000e+00>, [[MAX_V]] ; CHECK-NEXT: ret <2 x double> [[MAX]] ; %n1 = fsub <2 x double> <double -0.0, double -0.0>, %x @@ -302,10 +299,9 @@ define <2 x double> @fsub_fmin(<2 x double> %x, <2 x double> %y) { define double @fneg_fmin(double %x, double %y) { ; CHECK-LABEL: @fneg_fmin( -; CHECK-NEXT: [[N1:%.*]] = fneg double [[X:%.*]] -; CHECK-NEXT: [[N2:%.*]] = fneg double [[Y:%.*]] -; CHECK-NEXT: [[COND_INV:%.*]] = fcmp nnan nsz ogt double [[N1]], [[N2]] -; CHECK-NEXT: [[MAX:%.*]] = select i1 [[COND_INV]], double [[N2]], double [[N1]] +; CHECK-NEXT: [[COND_INV:%.*]] = fcmp nnan nsz olt double [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: [[MAX_V:%.*]] = select i1 [[COND_INV]], double [[Y]], double [[X]] +; CHECK-NEXT: [[MAX:%.*]] = fneg double [[MAX_V]] ; CHECK-NEXT: ret double [[MAX]] ; %n1 = fneg double %x |

