[llvm] [SCEV] Add predicate in SolveLinEq to ensure B is a multiple of A. (PR #108777)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 26 08:34:36 PDT 2024


================
@@ -10146,8 +10149,20 @@ static const SCEV *SolveLinEquationWithOverflow(const APInt &A, const SCEV *B,
   //
   // B is divisible by D if and only if the multiplicity of prime factor 2 for B
   // is not less than multiplicity of this prime factor for D.
-  if (SE.getMinTrailingZeros(B) < Mult2)
-    return SE.getCouldNotCompute();
+  if (SE.getMinTrailingZeros(B) < Mult2) {
+    if (!Predicates)
+      return SE.getCouldNotCompute();
+    // Try to add a predicate ensuring B is a multiple of 1 << Mult2.
+    const SCEV *URem =
+        SE.getURemExpr(B, SE.getConstant(B->getType(), 1 << Mult2));
----------------
goldsteinn wrote:

Is Mult2 guaranteed less than 32? Don't see anything enforcing as much. Maybe `APInt::getOneBitSet(BW, Mult2)`?

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


More information about the llvm-commits mailing list