https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125734
--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Andrea Pinski <[email protected]>: https://gcc.gnu.org/g:e90e0f66051d338c1950d2cc9e36967552d75c3a commit r17-4047-ge90e0f66051d338c1950d2cc9e36967552d75c3a Author: Shivam Gupta <[email protected]> Date: Mon Sep 7 06:36:15 2026 +0530 tree-optimization: Recognize CLZ loop for signed non-negative values is_rshift_by_1 previously checked TYPE_UNSIGNED on the shift statement, preventing signed arithmetic right shifts from being optimized into CLZ calls. However, an arithmetic right shift behaves identically to a logical right shift when the initial operand entering the loop is non-negative. This patch removes the strict TYPE_UNSIGNED requirement from is_rshift_by_1 and adds ranger range_on_edge non-negativity checks in number_of_iterations_cltz and number_of_iterations_cltz_complement on the loop preheader edge. Regression tested on arch64-unknown-linux-gnu. PR tree-optimization/125734 gcc/ChangeLog: * tree-ssa-loop-niter.cc (is_rshift_by_1): Remove TYPE_UNSIGNED restriction. (number_of_iterations_cltz): Use range_on_edge to check non-negativity of signed preheader input. (number_of_iterations_cltz_complement): Likewise. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr125734.c: New test. Signed-off-by: Shivam Gupta <[email protected]>
