Enables the ctpop((x & -x ) - 1) -> cttz(x, false) fold
Alive2: https://alive2.llvm.org/ce/z/EDk4h7 (((X & -X) - 1) --> (~X & (X - 1)) )
Alive2: https://alive2.llvm.org/ce/z/8Yr3XG (CTPOP -> CTTZ)
Fixes #51126
Differential D110488
[InstCombine] Canonicalize ((X & -X) - 1) --> (~X & (X - 1)) (PR51784) RKSimon on Sep 25 2021, 1:15 PM. Authored by
Details Enables the ctpop((x & -x ) - 1) -> cttz(x, false) fold Alive2: https://alive2.llvm.org/ce/z/EDk4h7 (((X & -X) - 1) --> (~X & (X - 1)) ) Alive2: https://alive2.llvm.org/ce/z/8Yr3XG (CTPOP -> CTTZ) Fixes #51126
Diff Detail
Event TimelineComment Actions An alternative would be to decide if (~x & (x - 1)) or ((x & -x ) - 1) should be the canonical pattern? Comment Actions I'd go with the 'not' pattern since that is likely better for known bits - and that's what we were already expecting here. So this patch might be made less important with the 'not' canonicalization, but it could still fire. Comment Actions Having spoken to @spatel offline, I'm going to add a fold for ((x & -x ) - 1) -> (~x & (x - 1)) as well as the ctpop fold - this will require single/multiuse tests for the inner fold (where it shouldn't fold multiuses) and for the ctpop case (where it should always fold to cttz). Comment Actions Replaced the ctpop fold with a generic ((X & -X) - 1) --> (~X & (X - 1)) canonicalization
Comment Actions This breaks check-llvm on non-win afaict: http://45.33.8.238/linux/84811/step_12.txt Please take a look and revert for now if it takes a while to fix.
|
The -1 constant should always be canonicalized to operand 1 (RHS), so this doesn't really need to match m_c_Add. You could match each of LHS and RHS instead.