https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127117
--- Comment #1 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Michiel Derhaeg <[email protected]>: https://gcc.gnu.org/g:91109d7b6eea9b7d2b3c6c3198ef761126af69e8 commit r17-4937-g91109d7b6eea9b7d2b3c6c3198ef761126af69e8 Author: Michiel Derhaeg <[email protected]> Date: Fri Aug 28 13:49:07 2026 +0200 arc: Correct ctz(0) and clz(0) for ARCompact [PR127117] CLZ_DEFINED_VALUE_AT_ZERO and CTZ_DEFINED_VALUE_AT_ZERO advertise clz(0) == 31 and ctz(0) == 31. When clzsi2 and ctzsi2 expand to the ARCv2 fls and ffs instructions that holds. Both patterns can also be emulated with norm, which currently happens for ARCompact, in that case it returns 32 for a zero operand. Correct the two emulation patterns. In *arc_clzsi2 only increment the norm result when the operand is strictly positive, which leaves a zero operand at norm's own result of 31. In arc_ctzsi2 produce 31 instead of 32 on the negative-flag path that a zero operand takes. PR target/127117 gcc/ChangeLog: * config/arc/arc.md (*arc_clzsi2): Produce 31 rather than 32 for a zero operand. (arc_ctzsi2): Likewise. gcc/testsuite/ChangeLog: * gcc.target/arc/arc.exp (check_effective_target_norm): New. * gcc.target/arc/pr127117.c: New test. Co-authored-by: Luis Silva <[email protected]> Signed-off-by: Michiel Derhaeg <[email protected]>
