[PATCH v2] match.pd: popcount(X & -X) -> (X & -X) != 0 [PR102486]
Daniel Henrique Barboza
daniel.barboza@oss.qualcomm.com
Sun Jan 4 20:57:09 GMT 2026
On 1/4/26 4:56 PM, Andrew Pinski wrote:
> On Sun, Jan 4, 2026 at 11:32 AM Jeffrey Law
> <jeffrey.law@oss.qualcomm.com> wrote:
>>
>>
>>
>> On 12/30/2025 2:34 PM, Daniel Barboza wrote:
>>> PR 102486
>>>
>>> gcc/ChangeLog:
>>>
>>> * match.pd (`popcount (X & -X) -> (X & -X) != 0`): New pattern.
>>>
>>> gcc/testsuite/ChangeLog:
>>>
>>> * gcc.dg/tree-ssa/pr102486.c: New test.
>> So isn't it transformed into "X != 0" rather than "(X & -X) != 0)"?
>> Which means the subject line and ChangeLog entry need minor updates.
>> I'm not sure why Andrew suggested optimizing to (X & -X) != 0 since the
>> X & -X is zero when X == 0 and nonzero when X != 0.
>
> I don't remember why I suggested optimizing it to `(X & -X) != 0`
> instead of just `X != 0`. The bug report was filed 4 years ago and I
> can't find my notes for what I was looking at that time or why 2 years
> later mentioned `(X&-X) != 0` either. But yes it should be to `X !=
> 0`.
Should be an easier pattern then. I'll send a v3. Thanks,
Daniel
>
> Thanks,
> Andrew
>
>>
>> I think Andrew also noted some additional type fixes that were needed in
>> the new gimple you're generating. So we probably need a V3 for that.
>>
>> Jeff
More information about the Gcc-patches
mailing list