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

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 26 11:52:11 PDT 2024


================
@@ -10137,8 +10140,17 @@ 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) {
----------------
preames wrote:

With the reframing of urem (B, 1 << Mult2) == 0, I agree with your comment, but I think we could reasonable see divergence with the original urem(B,A) check.  Those are just different enough.

My suggestion is basically, can we prove the original fact without using the trailing bits proof strategy?  Said differently. what if D = gcd(A, N) is something like 3^M?

Hm, though now I see that the multiplicative inverse code below would need updated too.  I'd missed that originally.

(Totally fine to move forward here, this is purely a possible followup.)

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


More information about the llvm-commits mailing list