[llvm] [DA] Extract duplicated logic from exactSIVtest and exactRDIVtest (NFC) (PR #152712)

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 11 04:52:01 PDT 2025


================
@@ -1531,6 +1531,47 @@ static APInt ceilingOfQuotient(const APInt &A, const APInt &B) {
     return Q;
 }
 
+/// Given an affine expression of the form A*k + B, where k is an arbitrary
+/// integer, infer the possible range of k based on the known range of the
+/// affine expression. If we know A*k + B is non-negative, i.e.,
+///
+///   A*k + B >= 0
+///
+/// we can derive the following inequalities for k when A is positive:
+///
+///   k >= -B / A
+///
+/// Since k is an integer, it means k is greater than or equal to the
+/// ceil(-B / A). Similar logic applies when A is negative, or the upper bound
+/// of the affine expression is passed via \p UB.
+///
+/// Preconditions: \p A is non-zero, and we know A*k + B is non-negative.
+static std::pair<std::optional<APInt>, std::optional<APInt>>
+inferDomainOfAffine(const APInt &A, const APInt &B,
+                    const std::optional<APInt> &UB) {
----------------
Meinersbur wrote:

[not a change request] `UB` not explained in the doxygen.

Since the original code is also just commentged "New bound check - modification to Banerjee's e3 check", I don't think you need to add more if it is just refeormulating tht comment.



https://github.com/llvm/llvm-project/pull/152712


More information about the llvm-commits mailing list