Patchwork [2/2] if-to-switch conversion pass -- infrastructure

login
register
mail settings
Submitter Tom de Vries
Date July 17, 2012, 1:55 p.m.
Message ID <50056ECC.903@mentor.com>
Download mbox | patch
Permalink /patch/171433/
State New
Headers show

Comments

Tom de Vries - July 17, 2012, 1:55 p.m.
On 17/07/12 13:29, Richard Guenther wrote:
> On Tue, Jul 17, 2012 at 1:25 PM, Tom de Vries <Tom_deVries@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  <tom@codesourcery.com>

	* hwint.c: Fix loop range.

Patch

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;