@@ -1989,59 +1989,6 @@ bool GVNPass::processNonLocalLoad(LoadInst *Load) {
1989
1989
return Changed;
1990
1990
}
1991
1991
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
-
2045
1992
static bool hasUsersIn (Value *V, BasicBlock *BB) {
2046
1993
return llvm::any_of (V->users (), [BB](User *U) {
2047
1994
auto *I = dyn_cast<Instruction>(U);
@@ -2143,7 +2090,7 @@ bool GVNPass::processAssumeIntrinsic(AssumeInst *IntrinsicI) {
2143
2090
// call void @llvm.assume(i1 %cmp)
2144
2091
// ret float %load ; will change it to ret float %0
2145
2092
if (auto *CmpI = dyn_cast<CmpInst>(V)) {
2146
- if (impliesEquivalanceIfTrue ( CmpI)) {
2093
+ if (CmpI-> isEqEquivalence ( )) {
2147
2094
Value *CmpLHS = CmpI->getOperand (0 );
2148
2095
Value *CmpRHS = CmpI->getOperand (1 );
2149
2096
// Heuristically pick the better replacement -- the choice of heuristic
@@ -2567,8 +2514,8 @@ bool GVNPass::propagateEquality(Value *LHS, Value *RHS,
2567
2514
// If "A == B" is known true, or "A != B" is known false, then replace
2568
2515
// A with B everywhere in the scope. For floating point operations, we
2569
2516
// have to be careful since equality does not always imply equivalance.
2570
- if ((isKnownTrue && impliesEquivalanceIfTrue ( Cmp)) ||
2571
- (isKnownFalse && impliesEquivalanceIfFalse ( Cmp)))
2517
+ if ((isKnownTrue && Cmp-> isEqEquivalence ( )) ||
2518
+ (isKnownFalse && Cmp-> isNeEquivalence ( )))
2572
2519
Worklist.push_back (std::make_pair (Op0, Op1));
2573
2520
2574
2521
// If "A >= B" is known true, replace "A < B" with false everywhere.
0 commit comments