[mlir] Use std::lcm (NFC)

This patch replaces mlir::lcm with std::lcm, a C++17 feature.

Note that all the arguments to mlir::lcm are of int64_t with no
implicit type conversion as they are passed to mlir::lcm, which I've
verified by modifying mlir::lcm as:

  template <typename TA, typename TB>
  inline int64_t lcm(TA a, TB b) {
    static_assert(std::is_same_v<TA, int64_t>);
    static_assert(std::is_same_v<TB, int64_t>);
    :
This commit is contained in:
Kazu Hirata
2022-08-27 09:53:14 -07:00
parent 86bc4587e1
commit 099775c2d6
3 changed files with 5 additions and 12 deletions

View File

@@ -46,15 +46,6 @@ inline int64_t mod(int64_t lhs, int64_t rhs) {
assert(rhs >= 1);
return lhs % rhs < 0 ? lhs % rhs + rhs : lhs % rhs;
}
/// Returns the least common multiple of 'a' and 'b'.
inline int64_t lcm(int64_t a, int64_t b) {
uint64_t x = std::abs(a);
uint64_t y = std::abs(b);
int64_t lcm = (x * y) / llvm::GreatestCommonDivisor64(x, y);
assert((lcm >= a && lcm >= b) && "LCM overflow");
return lcm;
}
} // namespace mlir
#endif // MLIR_SUPPORT_MATHEXTRAS_H_

View File

@@ -21,6 +21,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/Support/Debug.h"
#include <numeric>
#define DEBUG_TYPE "presburger"
@@ -537,7 +538,7 @@ static void eliminateFromConstraint(IntegerRelation *constraints,
return;
int64_t pivotCoeff = constraints->atEq(pivotRow, pivotCol);
int64_t sign = (leadCoeff * pivotCoeff > 0) ? -1 : 1;
int64_t lcm = mlir::lcm(pivotCoeff, leadCoeff);
int64_t lcm = std::lcm(pivotCoeff, leadCoeff);
int64_t pivotMultiplier = sign * (lcm / std::abs(pivotCoeff));
int64_t rowMultiplier = lcm / std::abs(leadCoeff);
@@ -1827,7 +1828,7 @@ void IntegerRelation::fourierMotzkinEliminate(unsigned pos, bool darkShadow,
if (l == pos)
continue;
assert(lbCoeff >= 1 && ubCoeff >= 1 && "bounds wrongly identified");
int64_t lcm = mlir::lcm(lbCoeff, ubCoeff);
int64_t lcm = std::lcm(lbCoeff, ubCoeff);
ineq.push_back(atIneq(ubPos, l) * (lcm / ubCoeff) +
atIneq(lbPos, l) * (lcm / lbCoeff));
assert(lcm > 0 && "lcm should be positive!");

View File

@@ -11,6 +11,7 @@
#include "mlir/Support/MathExtras.h"
#include "llvm/ADT/Optional.h"
#include "llvm/Support/Compiler.h"
#include <numeric>
using namespace mlir;
using namespace presburger;
@@ -149,7 +150,7 @@ unsigned SimplexBase::addRow(ArrayRef<int64_t> coeffs, bool makeRestricted) {
// row, scaled by the coefficient for the variable, accounting for the two
// rows potentially having different denominators. The new denominator is
// the lcm of the two.
int64_t lcm = mlir::lcm(tableau(newRow, 0), tableau(pos, 0));
int64_t lcm = std::lcm(tableau(newRow, 0), tableau(pos, 0));
int64_t nRowCoeff = lcm / tableau(newRow, 0);
int64_t idxRowCoeff = coeffs[i] * (lcm / tableau(pos, 0));
tableau(newRow, 0) = lcm;