On 9/24/26 5:48 AM, Samarth Tandale via Sourceware Forge wrote:
From: Samarth Tandale <[email protected]> Fold (a != 0) | (popcount(a) == n) into (a != 0) | (n == 0), and (a == 0) & (popcount(a) != n) into (a == 0) & (n != 0). This follows from x == 0 => popcount(x) == 0: when a == 0 the popcount comparison reduces to a comparison against zero, and when a != 0 the outer OR/AND already determines the result. PR tree-optimization/112094 gcc/ChangeLog: * match.pd: Add fold for (a != 0) | (popcount(a) == n) and (a == 0) & (popcount(a) != n). gcc/testsuite/ChangeLog: * gcc.dg/fold-popcount-12.c: New test. * gcc.dg/fold-popcount-13.c: New test. Signed-off-by: Samarth Tandale <[email protected]> --- Fold (a != 0) | (popcount(a) == n) into (a != 0) | (n == 0), and (a == 0) & (popcount(a) != n) into (a == 0) & (n != 0). This follows from x == 0 => popcount(x) == 0: when a == 0 the popcount comparison reduces to a comparison against zero, and when a != 0 the outer OR/AND already determines the result. PR tree-optimization/112094 ``` gcc/ChangeLog: * match.pd: Add fold for (a != 0) | (popcount(a) == n) and (a == 0) & (popcount(a) != n). gcc/testsuite/ChangeLog: * gcc.dg/fold-popcount-12.c: New test. * gcc.dg/fold-popcount-13.c: New test. ``` Signed-off-by: Samarth Tandale <[email protected]>
THanks. I've pushed this to the trunk. jeff
