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

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 26 08:20:45 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) {
+    if (!Predicates)
+      return SE.getCouldNotCompute();
+    // Try to add a predicate ensuring B is a multiple of A.
+    const SCEV *URem = SE.getURemExpr(B, SE.getConstant(A));
+    const SCEV *Zero = SE.getZero(B->getType());
+    // Avoid adding a predicate that is known to be false.
+    if (SE.isKnownPredicate(CmpInst::ICMP_NE, URem, Zero))
+      return SE.getCouldNotCompute();
+    Predicates->insert(SE.getEqualPredicate(URem, Zero));
----------------
fhahn wrote:

I think the terminology is a bit confusing, the predicate in `isKnownPredicate` refers to condition to check for the arguments, while predicate in getEqualPredicate refers to a SCEVPredicate (used by PredicateScalarEvolution) and those cannot be used by the isKnownPredicate helpers AFAIK

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


More information about the llvm-commits mailing list