diff options
author | Yingwei Zheng <dtcxzyw2333@gmail.com> | 2025-03-17 13:59:16 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-17 13:59:16 +0800 |
commit | c5a491e9ea22014b65664b6e09134b4f055933e2 (patch) | |
tree | 5be472a74cf51e89eb7c817f3cfbc1cee29605ce /llvm/lib/Analysis/ScalarEvolution.cpp | |
parent | baab447aadd59b34bd838584b16d11475329853f (diff) | |
download | llvm-c5a491e9ea22014b65664b6e09134b4f055933e2.zip llvm-c5a491e9ea22014b65664b6e09134b4f055933e2.tar.gz llvm-c5a491e9ea22014b65664b6e09134b4f055933e2.tar.bz2 |
[SCEV] Check whether the start is non-zero in `ScalarEvolution::howFarToZero` (#131522)
https://github.com/llvm/llvm-project/pull/94525 assumes that the loop
will be infinite when the stride is zero. However, it doesn't hold when
the start value of addrec is also zero.
Closes https://github.com/llvm/llvm-project/issues/131465.
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp')
-rw-r--r-- | llvm/lib/Analysis/ScalarEvolution.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 8f74c1c..314baa7 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -10635,10 +10635,11 @@ ScalarEvolution::ExitLimit ScalarEvolution::howFarToZero(const SCEV *V, if (ControlsOnlyExit && AddRec->hasNoSelfWrap() && loopHasNoAbnormalExits(AddRec->getLoop())) { - // If the stride is zero, the loop must be infinite. In C++, most loops - // are finite by assumption, in which case the step being zero implies - // UB must execute if the loop is entered. - if (!loopIsFiniteByAssumption(L) && !isKnownNonZero(StepWLG)) + // If the stride is zero and the start is non-zero, the loop must be + // infinite. In C++, most loops are finite by assumption, in which case the + // step being zero implies UB must execute if the loop is entered. + if (!(loopIsFiniteByAssumption(L) && isKnownNonZero(Start)) && + !isKnownNonZero(StepWLG)) return getCouldNotCompute(); const SCEV *Exact = |