diff options
author | Sanjay Patel <spatel@rotateright.com> | 2018-11-07 00:00:42 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2018-11-07 00:00:42 +0000 |
commit | d1172a0c204f782d0531f2d6ac68e7e0f5e31f00 (patch) | |
tree | 90c89f110c7ea6b7f4cf460d47767a8e4385b66a /llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | |
parent | 5652cd3fe9f38328361606636095e62c4f894d8c (diff) | |
download | bcm5719-llvm-d1172a0c204f782d0531f2d6ac68e7e0f5e31f00.tar.gz bcm5719-llvm-d1172a0c204f782d0531f2d6ac68e7e0f5e31f00.zip |
[IR] add optional parameter for copying IR flags to compare instructions
As shown, this is used to eliminate redundant code in InstCombine,
and there are more cases where we should be using this pattern, but
we're currently unintentionally dropping flags.
llvm-svn: 346282
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 43 |
1 files changed, 14 insertions, 29 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 2381e26a1d8..c6dbfd92844 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -5281,11 +5281,7 @@ static Instruction *foldFCmpReciprocalAndZero(FCmpInst &I, Instruction *LHSI, if (C->isNegative()) Pred = I.getSwappedPredicate(); - // Finally emit the new fcmp. - Value *X = LHSI->getOperand(1); - FCmpInst *NewFCI = new FCmpInst(Pred, X, RHSC); - NewFCI->copyFastMathFlags(&I); - return NewFCI; + return new FCmpInst(Pred, LHSI->getOperand(1), RHSC, "", &I); } /// Optimize fabs(X) compared with zero. @@ -5434,43 +5430,34 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) { if (Instruction *Res = foldCmpLoadFromIndexedGlobal(GEP, GV, I)) return Res; break; - case Instruction::Call: - if (Instruction *X = foldFabsWithFcmpZero(I)) - return X; - break; } } + if (Instruction *R = foldFabsWithFcmpZero(I)) + return R; + Value *X, *Y; if (match(Op0, m_FNeg(m_Value(X)))) { - if (match(Op1, m_FNeg(m_Value(Y)))) { - // fcmp pred (fneg X), (fneg Y) -> fcmp swap(pred) X, Y - Instruction *NewFCmp = new FCmpInst(I.getSwappedPredicate(), X, Y); - NewFCmp->copyFastMathFlags(&I); - return NewFCmp; - } + // 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))) { - // 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; + return new FCmpInst(I.getSwappedPredicate(), X, NegC, "", &I); } } if (match(Op0, m_FPExt(m_Value(X)))) { - if (match(Op1, m_FPExt(m_Value(Y))) && X->getType() == Y->getType()) { - // fcmp (fpext X), (fpext Y) -> fcmp X, Y - Instruction *NewFCmp = new FCmpInst(Pred, X, Y); - NewFCmp->copyFastMathFlags(&I); - return NewFCmp; - } + // fcmp (fpext X), (fpext Y) -> fcmp X, Y + if (match(Op1, m_FPExt(m_Value(Y))) && X->getType() == Y->getType()) + return new FCmpInst(Pred, X, Y, "", &I); + // fcmp (fpext X), C -> fcmp X, (fptrunc C) if fptrunc is lossless const APFloat *C; if (match(Op1, m_APFloat(C))) { - // fcmp (fpext X), C -> fcmp X, (fptrunc C) if fptrunc is lossless const fltSemantics &FPSem = X->getType()->getScalarType()->getFltSemantics(); bool Lossy; @@ -5485,9 +5472,7 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) { ((Fabs.compare(APFloat::getSmallestNormalized(FPSem)) != APFloat::cmpLessThan) || Fabs.isZero())) { Constant *NewC = ConstantFP::get(X->getType(), TruncC); - Instruction *NewFCmp = new FCmpInst(Pred, X, NewC); - NewFCmp->copyFastMathFlags(&I); - return NewFCmp; + return new FCmpInst(Pred, X, NewC, "", &I); } } } |