diff options
author | Sanjay Patel <spatel@rotateright.com> | 2018-11-06 15:49:45 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2018-11-06 15:49:45 +0000 |
commit | 70282a050196941167b2589bddcf7a24759e15e3 (patch) | |
tree | ab9429ffca304126ff38ff5a451ff54ed2075b49 /llvm/lib | |
parent | e0d2733bf63f08989947f2a6a227d7301c6b11a3 (diff) | |
download | bcm5719-llvm-70282a050196941167b2589bddcf7a24759e15e3.tar.gz bcm5719-llvm-70282a050196941167b2589bddcf7a24759e15e3.zip |
[InstCombine] propagate fast-math-flags when folding fcmp+fneg
This is another part of solving PR39475:
https://bugs.llvm.org/show_bug.cgi?id=39475
This might be enough to fix that particular issue, but as noted
with the FIXME, we're still dropping FMF on other folds around here.
llvm-svn: 346234
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 059f7523ff9..1946f8903b1 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -5445,14 +5445,6 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) { if (Instruction *NV = foldFCmpIntToFPConst(I, LHSI, RHSC)) return NV; break; - case Instruction::FSub: { - // fcmp pred (fneg x), C -> fcmp swap(pred) x, -C - Value *Op; - if (match(LHSI, m_FNeg(m_Value(Op)))) - return new FCmpInst(I.getSwappedPredicate(), Op, - ConstantExpr::getFNeg(RHSC)); - break; - } case Instruction::FDiv: if (Instruction *NV = foldFCmpReciprocalAndZero(I, LHSI, RHSC)) return NV; @@ -5472,10 +5464,23 @@ 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); + if (match(Op0, m_FNeg(m_Value(X)))) { + if (match(Op1, m_FNeg(m_Value(Y)))) { + // FIXME: Drops FMF. + // fcmp pred (fneg X), (fneg Y) -> fcmp swap(pred) X, Y + return new FCmpInst(I.getSwappedPredicate(), X, Y); + } + + Constant *C; + if (match(Op1, m_Constant(C))) { + // fcmp pred (fneg X), C --> fcmp swap(pred) X, -C + Constant *NegC = ConstantExpr::getFNeg(C); + Instruction *NewFCmp = new FCmpInst(I.getSwappedPredicate(), X, NegC); + NewFCmp->copyFastMathFlags(&I); + return NewFCmp; + } + } // fcmp (fpext x), (fpext y) -> fcmp x, y if (FPExtInst *LHSExt = dyn_cast<FPExtInst>(Op0)) |