https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126626
Bug ID: 126626
Summary: `(x & -x) == 0` can be optimized to `x == 0`
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: easyhack, missed-optimization
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Here is a full list:
CST == 0
(x & -x) == 0 -> x == 0
(x & -x) != 0 -> x != 0
powerof 2 CST:
(x & -x) == N -> (x&((N<<1)-1)) == N
(x & -x) != N -> (x&((N<<1)-1)) != N
[ Note CST == 1<<precision should basically produce:
(x & -x) == N -> x == N
(x & -x) != N -> x != N
And CST == 1 should produce:
(x & -x) == 1 -> (x&1) == 1 or (bool)(x&1)
(x & -x) != 1 -> (x&1) != 1 or ((x&1) == 0)
]
non powerof 2 CST
(x & -x) == CST -> false
(x & -x) != CST -> true
Note this is more than that is proposed for LLVM (which is just the 0/1 case).
But this has the full CST case.