From: Mehdi Amini Date: Fri, 13 Feb 2015 07:38:04 +0000 (+0000) Subject: InstCombine: cleanup redundant dyn_cast<> (NFC) X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=6ffd7173f2c11324c1e3a2fb06c11560fafec042 InstCombine: cleanup redundant dyn_cast<> (NFC) From: Mehdi Amini git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229075 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/InstructionSimplify.cpp b/lib/Analysis/InstructionSimplify.cpp index d02bb2b8f52..603a10fa869 100644 --- a/lib/Analysis/InstructionSimplify.cpp +++ b/lib/Analysis/InstructionSimplify.cpp @@ -3052,57 +3052,56 @@ static Value *SimplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS, } // Handle fcmp with constant RHS - if (Constant *RHSC = dyn_cast(RHS)) { + if (ConstantFP *CFP = dyn_cast(RHS)) { // If the constant is a nan, see if we can fold the comparison based on it. - if (ConstantFP *CFP = dyn_cast(RHSC)) { - if (CFP->getValueAPF().isNaN()) { - if (FCmpInst::isOrdered(Pred)) // True "if ordered and foo" - return ConstantInt::getFalse(CFP->getContext()); - assert(FCmpInst::isUnordered(Pred) && - "Comparison must be either ordered or unordered!"); - // True if unordered. - return ConstantInt::getTrue(CFP->getContext()); - } - // Check whether the constant is an infinity. - if (CFP->getValueAPF().isInfinity()) { - if (CFP->getValueAPF().isNegative()) { - switch (Pred) { - case FCmpInst::FCMP_OLT: - // No value is ordered and less than negative infinity. - return ConstantInt::getFalse(CFP->getContext()); - case FCmpInst::FCMP_UGE: - // All values are unordered with or at least negative infinity. - return ConstantInt::getTrue(CFP->getContext()); - default: - break; - } - } else { - switch (Pred) { - case FCmpInst::FCMP_OGT: - // No value is ordered and greater than infinity. - return ConstantInt::getFalse(CFP->getContext()); - case FCmpInst::FCMP_ULE: - // All values are unordered with and at most infinity. - return ConstantInt::getTrue(CFP->getContext()); - default: - break; - } - } - } - if (CFP->getValueAPF().isZero()) { + if (CFP->getValueAPF().isNaN()) { + if (FCmpInst::isOrdered(Pred)) // True "if ordered and foo" + return ConstantInt::getFalse(CFP->getContext()); + assert(FCmpInst::isUnordered(Pred) && + "Comparison must be either ordered or unordered!"); + // True if unordered. + return ConstantInt::getTrue(CFP->getContext()); + } + // Check whether the constant is an infinity. + if (CFP->getValueAPF().isInfinity()) { + if (CFP->getValueAPF().isNegative()) { switch (Pred) { - case FCmpInst::FCMP_UGE: - if (CannotBeOrderedLessThanZero(LHS)) - return ConstantInt::getTrue(CFP->getContext()); - break; case FCmpInst::FCMP_OLT: - if (CannotBeOrderedLessThanZero(LHS)) - return ConstantInt::getFalse(CFP->getContext()); + // No value is ordered and less than negative infinity. + return ConstantInt::getFalse(CFP->getContext()); + case FCmpInst::FCMP_UGE: + // All values are unordered with or at least negative infinity. + return ConstantInt::getTrue(CFP->getContext()); + default: break; + } + } else { + switch (Pred) { + case FCmpInst::FCMP_OGT: + // No value is ordered and greater than infinity. + return ConstantInt::getFalse(CFP->getContext()); + case FCmpInst::FCMP_ULE: + // All values are unordered with and at most infinity. + return ConstantInt::getTrue(CFP->getContext()); default: break; } - } + } + } + if (CFP->getValueAPF().isZero()) { + switch (Pred) { + case FCmpInst::FCMP_UGE: + if (CannotBeOrderedLessThanZero(LHS)) + return ConstantInt::getTrue(CFP->getContext()); + break; + case FCmpInst::FCMP_OLT: + // X < 0 + if (CannotBeOrderedLessThanZero(LHS)) + return ConstantInt::getFalse(CFP->getContext()); + break; + default: + break; + } } }