@@ -1684,30 +1684,47 @@ static void dryRunAddFact(CmpInst::Predicate Pred, Value *A, Value *B,
16841684 auto UpdateEstimate = [&Info, &EstimatedRowsA, &EstimatedRowsB,
16851685 &EstimatedColumns](CmpInst::Predicate Pred, Value *A,
16861686 Value *B) {
1687- SmallVector<Value *> NewVars;
1688- auto R = Info.getConstraint (Pred, A, B, NewVars);
1687+ // What follows is a simplified dry-run of Info.getConstraint and addFact.
1688+ unsigned NumNewVars = 0 ;
1689+ bool IsSigned = false ;
1690+
1691+ switch (Pred) {
1692+ case CmpInst::ICMP_UGT:
1693+ case CmpInst::ICMP_UGE:
1694+ case CmpInst::ICMP_NE:
1695+ case CmpInst::ICMP_EQ:
1696+ break ;
1697+ case CmpInst::ICMP_SGT:
1698+ case CmpInst::ICMP_SGE:
1699+ IsSigned = true ;
1700+ break ;
1701+ default :
1702+ return ;
1703+ }
16891704
1690- // We offset it by 1 due to logic in addFact.
1691- unsigned NewEstimate =
1692- count_if (R.Coefficients , [](int64_t C) { return C != 0 ; }) + 1 ;
1705+ SmallVector<ConditionTy, 4 > Preconditions;
1706+ auto &Value2Index = Info.getValue2Index (IsSigned);
1707+ auto ADec = decompose (A->stripPointerCastsSameRepresentation (),
1708+ Preconditions, IsSigned, Info.getDataLayout ());
1709+ auto BDec = decompose (B->stripPointerCastsSameRepresentation (),
1710+ Preconditions, IsSigned, Info.getDataLayout ());
1711+ for (const auto &KV : concat<DecompEntry>(ADec.Vars , BDec.Vars )) {
1712+ if (!Value2Index.contains (KV.Variable ))
1713+ ++NumNewVars;
1714+ }
16931715
1694- EstimatedColumns = std::max (EstimatedColumns, NewEstimate);
1695- if (R.IsSigned )
1716+ if (IsSigned)
16961717 ++EstimatedRowsA;
16971718 else
16981719 ++EstimatedRowsB;
1720+
1721+ EstimatedColumns =
1722+ std::max (EstimatedColumns, NumNewVars + Value2Index.size () + 2 );
16991723 };
17001724
17011725 UpdateEstimate (Pred, A, B);
17021726
1703- // What follows is a dry-run of transferToOtherSystem.
1704- auto IsKnownNonNegative = [&Info](Value *V) {
1705- return Info.doesHold (CmpInst::ICMP_SGE, V,
1706- ConstantInt::get (V->getType (), 0 )) ||
1707- isKnownNonNegative (V, Info.getDataLayout (),
1708- MaxAnalysisRecursionDepth - 1 );
1709- };
1710-
1727+ // What follows is a simplified dry-run of transferToOtherSystem.
17111728 if (!A->getType ()->isIntegerTy ())
17121729 return ;
17131730
@@ -1716,31 +1733,20 @@ static void dryRunAddFact(CmpInst::Predicate Pred, Value *A, Value *B,
17161733 break ;
17171734 case CmpInst::ICMP_ULT:
17181735 case CmpInst::ICMP_ULE:
1719- if (IsKnownNonNegative (B)) {
1720- UpdateEstimate (CmpInst::ICMP_SGE, A, ConstantInt::get (B->getType (), 0 ));
1721- UpdateEstimate (CmpInst::getSignedPredicate (Pred), A, B);
1722- }
1723- break ;
17241736 case CmpInst::ICMP_UGE:
17251737 case CmpInst::ICMP_UGT:
1726- if (IsKnownNonNegative (A)) {
1727- UpdateEstimate (CmpInst::ICMP_SGE, B, ConstantInt::get (B->getType (), 0 ));
1728- UpdateEstimate (CmpInst::getSignedPredicate (Pred), A, B);
1729- }
1738+ UpdateEstimate (CmpInst::ICMP_SGE, A, ConstantInt::get (B->getType (), 0 ));
1739+ UpdateEstimate (CmpInst::getSignedPredicate (Pred), A, B);
17301740 break ;
17311741 case CmpInst::ICMP_SLT:
1732- if (IsKnownNonNegative (A))
1733- UpdateEstimate (CmpInst::ICMP_ULT, A, B);
1742+ UpdateEstimate (CmpInst::ICMP_ULT, A, B);
17341743 break ;
17351744 case CmpInst::ICMP_SGT:
1736- if (Info.doesHold (CmpInst::ICMP_SGE, B, ConstantInt::get (B->getType (), -1 )))
1737- UpdateEstimate (CmpInst::ICMP_UGE, A, ConstantInt::get (B->getType (), 0 ));
1738- if (IsKnownNonNegative (B))
1739- UpdateEstimate (CmpInst::ICMP_UGT, A, B);
1745+ UpdateEstimate (CmpInst::ICMP_UGE, A, ConstantInt::get (B->getType (), 0 ));
1746+ UpdateEstimate (CmpInst::ICMP_UGT, A, B);
17401747 break ;
17411748 case CmpInst::ICMP_SGE:
1742- if (IsKnownNonNegative (B))
1743- UpdateEstimate (CmpInst::ICMP_UGE, A, B);
1749+ UpdateEstimate (CmpInst::ICMP_UGE, A, B);
17441750 break ;
17451751 }
17461752}
0 commit comments