On 7/23/24 10:30 AM, Roger Sayle wrote:
The subject line pretty much says it all; the count-trailing-zeros function of -X produces the same result as count-trailing-zeros of X. This transformation eliminates a negation which may potentially overflow with an equivalent expression that doesn't [much like the analogous abs(-X) simplification in match.pd]. Likewise, the undefined at zero remains undefined. I'd noticed this equivalence, which isn't mentioned in Hacker's Delight, investigating whether ranger's non_zero_bits can help determine whether an integer variable may be converted to a floating point type exactly (without raising FE_INEXACT), but it turns out this observation isn't novel, as (disappointingly) LLVM already performs this same folding. This patch has been tested on x86_64-pc-linux-gnu with make bootstrap and make -k check, both with and without --target_board=unix{-m32} with no new failures. Ok for mainline? 2024-07-23 Roger Sayle <ro...@nextmovesoftware.com> gcc/ChangeLog * match.pd (ctz (-X) => ctz (X)): New simplification. gcc/testsuite/ChangeLog * gcc.dg/fold-ctz-1.c: New test case.
OK. Your call on how to handle the additional case that Andrew P. noted. jeff