[llvm] [ValueTracking] Don't limit the recursion depth for single-incoming phis in isKnownNonZero (PR #226173)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 24 07:05:05 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Konstantin Bogdanov (thevar1able)

<details>
<summary>Changes</summary>

`isKnownNonZero` only lets a phi recurse into its incoming values at the last level of depth. A phi with a single incoming value is just a copy, and LCSSA puts one between a loop result and its users. After InstCombine removes the zero check in front of a clz loop, LoopIdiomRecognize can then no longer prove that the value reaching the loop through the LCSSA phi is non-zero, and it doesn't form `llvm.ctlz`. This keeps the current depth for such phis.

`PhaseOrdering/X86/ctlz-loop-or-reduction.ll` (reduced from ffmpeg's `sbc_calc_scalefactors`) covers the end-to-end result, and the first commit precommits it.

Split out of #<!-- -->222334. Depends on #<!-- -->226155.


---
Full diff: https://github.com/llvm/llvm-project/pull/226173.diff


2 Files Affected:

- (modified) llvm/lib/Analysis/ValueTracking.cpp (+5-2) 
- (added) llvm/test/Transforms/PhaseOrdering/X86/ctlz-loop-or-reduction.ll (+117) 


``````````diff
The server is unavailable at this time. Please wait a few minutes before you try again.
``````````

</details>


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


More information about the llvm-commits mailing list