@@ -1989,59 +1989,6 @@ bool GVNPass::processNonLocalLoad(LoadInst *Load) {
19891989 return Changed;
19901990}
19911991
1992- static bool impliesEquivalanceIfTrue (CmpInst* Cmp) {
1993- if (Cmp->getPredicate () == CmpInst::Predicate::ICMP_EQ)
1994- return true ;
1995-
1996- // Floating point comparisons can be equal, but not equivalent. Cases:
1997- // NaNs for unordered operators
1998- // +0.0 vs 0.0 for all operators
1999- if (Cmp->getPredicate () == CmpInst::Predicate::FCMP_OEQ ||
2000- (Cmp->getPredicate () == CmpInst::Predicate::FCMP_UEQ &&
2001- Cmp->getFastMathFlags ().noNaNs ())) {
2002- Value *LHS = Cmp->getOperand (0 );
2003- Value *RHS = Cmp->getOperand (1 );
2004- // If we can prove either side non-zero, then equality must imply
2005- // equivalence.
2006- // FIXME: We should do this optimization if 'no signed zeros' is
2007- // applicable via an instruction-level fast-math-flag or some other
2008- // indicator that relaxed FP semantics are being used.
2009- if (isa<ConstantFP>(LHS) && !cast<ConstantFP>(LHS)->isZero ())
2010- return true ;
2011- if (isa<ConstantFP>(RHS) && !cast<ConstantFP>(RHS)->isZero ())
2012- return true ;
2013- // TODO: Handle vector floating point constants
2014- }
2015- return false ;
2016- }
2017-
2018- static bool impliesEquivalanceIfFalse (CmpInst* Cmp) {
2019- if (Cmp->getPredicate () == CmpInst::Predicate::ICMP_NE)
2020- return true ;
2021-
2022- // Floating point comparisons can be equal, but not equivelent. Cases:
2023- // NaNs for unordered operators
2024- // +0.0 vs 0.0 for all operators
2025- if ((Cmp->getPredicate () == CmpInst::Predicate::FCMP_ONE &&
2026- Cmp->getFastMathFlags ().noNaNs ()) ||
2027- Cmp->getPredicate () == CmpInst::Predicate::FCMP_UNE) {
2028- Value *LHS = Cmp->getOperand (0 );
2029- Value *RHS = Cmp->getOperand (1 );
2030- // If we can prove either side non-zero, then equality must imply
2031- // equivalence.
2032- // FIXME: We should do this optimization if 'no signed zeros' is
2033- // applicable via an instruction-level fast-math-flag or some other
2034- // indicator that relaxed FP semantics are being used.
2035- if (isa<ConstantFP>(LHS) && !cast<ConstantFP>(LHS)->isZero ())
2036- return true ;
2037- if (isa<ConstantFP>(RHS) && !cast<ConstantFP>(RHS)->isZero ())
2038- return true ;
2039- // TODO: Handle vector floating point constants
2040- }
2041- return false ;
2042- }
2043-
2044-
20451992static bool hasUsersIn (Value *V, BasicBlock *BB) {
20461993 return llvm::any_of (V->users (), [BB](User *U) {
20471994 auto *I = dyn_cast<Instruction>(U);
@@ -2143,7 +2090,7 @@ bool GVNPass::processAssumeIntrinsic(AssumeInst *IntrinsicI) {
21432090 // call void @llvm.assume(i1 %cmp)
21442091 // ret float %load ; will change it to ret float %0
21452092 if (auto *CmpI = dyn_cast<CmpInst>(V)) {
2146- if (impliesEquivalanceIfTrue ( CmpI)) {
2093+ if (CmpI-> isEquivalence ( )) {
21472094 Value *CmpLHS = CmpI->getOperand (0 );
21482095 Value *CmpRHS = CmpI->getOperand (1 );
21492096 // Heuristically pick the better replacement -- the choice of heuristic
@@ -2577,8 +2524,7 @@ bool GVNPass::propagateEquality(Value *LHS, Value *RHS,
25772524 // If "A == B" is known true, or "A != B" is known false, then replace
25782525 // A with B everywhere in the scope. For floating point operations, we
25792526 // have to be careful since equality does not always imply equivalance.
2580- if ((isKnownTrue && impliesEquivalanceIfTrue (Cmp)) ||
2581- (isKnownFalse && impliesEquivalanceIfFalse (Cmp)))
2527+ if (Cmp->isEquivalence (isKnownFalse))
25822528 Worklist.push_back (std::make_pair (Op0, Op1));
25832529
25842530 // If "A >= B" is known true, replace "A < B" with false everywhere.
0 commit comments