https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127117
Bug ID: 127117
Summary: [16/17 Regression] arc: ctz(0) and clz(0) are
incorrect for arc600 and arc700
Product: gcc
Version: 16.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: michiel at derhaeg dot be
Target Milestone: ---
The arc backend defines
#define CLZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) ((VALUE) = 31, 2)
#define CTZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) ((VALUE) = 31, 2)
This is only valid for cores that implement clz and ctz using fls and ffs
respectively.
Cores that don't fall back to the norm instruction. 31 is not the correct value
in that case.
gcc.dg/torture/pr122212.c currently fails because of this.
The arc backend implementation for clzsi2 and ctzsi2 was always wrong. But
"tree-optimization/120032 - matching of table based CLZ"
introduced additional reliance on CLZ_DEFINED_VALUE_AT_ZERO, hence I consider
this a regression.