On 17/07/12 13:29, Richard Guenther wrote: > On Tue, Jul 17, 2012 at 1:25 PM, Tom de Vries <tom_devr...@mentor.com> wrote: >> On 17/07/12 13:21, Tom de Vries wrote: >>> attached patch implements an if-to-switch conversion tree pass >>> pass_if_to_switch. I will follow up this email with an infrastructure patch >>> that >>> provides double_int_popcount and popcount_hwi. >> >> Bootstrapped and reg-tested (Ada inclusive) on x86_64, with >> pass_if_to_switch as >> only client. >>
Mark pointed out that the popcount_hwi function had a bug: The loop should visit all bits of the type but uses sizeof (type) as loop counter which returns the number of bytes of the type. Unit-tested and committed. Thanks, - Tom 2012-07-17 Tom de Vries <t...@codesourcery.com> * hwint.c: Fix loop range.
Index: gcc/hwint.c =================================================================== --- gcc/hwint.c (revision 189575) +++ gcc/hwint.c (working copy) @@ -113,8 +113,9 @@ int popcount_hwi (unsigned HOST_WIDE_INT x) { int i, ret = 0; + size_t bits = sizeof (x) * CHAR_BIT; - for (i = 0; i < sizeof (x); i += 1) + for (i = 0; i < bits; i += 1) { ret += x & 1; x >>= 1;