[llvm] efd3ec4 - [ConstraintElimination] Clear new indices directly in getConstraint(NFC)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 14 07:31:51 PDT 2022
Author: Florian Hahn
Date: 2022-09-14T15:31:25+01:00
New Revision: efd3ec47d9648a1243ff36eeaf10c51a84d0fa3e
URL: https://github.com/llvm/llvm-project/commit/efd3ec47d9648a1243ff36eeaf10c51a84d0fa3e
DIFF: https://github.com/llvm/llvm-project/commit/efd3ec47d9648a1243ff36eeaf10c51a84d0fa3e.diff
LOG: [ConstraintElimination] Clear new indices directly in getConstraint(NFC)
Instead of checking if any of the new indices has a non-zero coefficient
before using the constraint, do this directly when constructing the
constraint.
Added:
Modified:
llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index e939aab83912..41d9dd995dce 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -90,18 +90,6 @@ struct ConstraintTy {
unsigned empty() const { return Coefficients.empty(); }
- /// Returns true if any constraint has a non-zero coefficient for any of the
- /// newly added indices. Zero coefficients for new indices are removed. If it
- /// returns true, no new variable need to be added to the system.
- bool needsNewIndices(const DenseMap<Value *, unsigned> &NewIndices) {
- for (unsigned I = 0; I < NewIndices.size(); ++I) {
- int64_t Last = Coefficients.pop_back_val();
- if (Last != 0)
- return true;
- }
- return false;
- }
-
/// Returns true if all preconditions for this list of constraints are
/// satisfied given \p CS and the corresponding \p Value2Index mapping.
bool isValid(const ConstraintInfo &Info) const;
@@ -384,6 +372,23 @@ ConstraintInfo::getConstraint(CmpInst::Predicate Pred, Value *Op0, Value *Op1,
return {};
R[0] = OffsetSum;
Res.Preconditions = std::move(Preconditions);
+
+ // Remove any (Coefficient, Variable) entry where the Coefficient is 0 for the
+ // new variables that need to be added to the system. Set NewIndexNeeded to
+ // true if any of the new variables has a non-zero coefficient.
+ bool NewIndexNeeded = false;
+ for (unsigned I = 0; I < NewIndices.size(); ++I) {
+ int64_t Last = R.back();
+ if (Last != 0) {
+ NewIndexNeeded = true;
+ break;
+ }
+ R.pop_back();
+ }
+ // All new variables had Coefficients of 0, so no new variables are needed.
+ if (!NewIndexNeeded)
+ NewIndices.clear();
+
return Res;
}
@@ -645,7 +650,7 @@ tryToSimplifyOverflowMath(IntrinsicInst *II, ConstraintInfo &Info,
ConstraintInfo &Info) {
DenseMap<Value *, unsigned> NewIndices;
auto R = Info.getConstraint(Pred, A, B, NewIndices);
- if (R.size() < 2 || R.needsNewIndices(NewIndices) || !R.isValid(Info))
+ if (R.size() < 2 || !NewIndices.empty() || !R.isValid(Info))
return false;
auto &CSToUse = Info.getCS(CmpInst::isSigned(Pred));
@@ -763,8 +768,7 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT) {
DenseMap<Value *, unsigned> NewIndices;
auto R = Info.getConstraint(Cmp, NewIndices);
- if (R.IsEq || R.empty() || R.needsNewIndices(NewIndices) ||
- !R.isValid(Info))
+ if (R.IsEq || R.empty() || !NewIndices.empty() || !R.isValid(Info))
continue;
auto &CSToUse = Info.getCS(R.IsSigned);
More information about the llvm-commits
mailing list