[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
Fri Sep 27 13:16:05 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) {
----------------
fhahn wrote:
I stand corrected, the assertion actually uncovered a case where getMinTrailingZeros returns a worse result and I think catching this in getMinTrailingZeros would require matching a specific pattern (https://alive2.llvm.org/ce/z/t3A5X2)
I updated the code to check if the URem is zero if the trailing bits check failed, as we need to build the expression there already. Test is in `llvm/test/Analysis/ScalarEvolution/trip-count-urem.ll`
https://github.com/llvm/llvm-project/pull/108777
More information about the llvm-commits
mailing list