[InstCombine] fold negated low-bit-mask to cmp+select
authorSanjay Patel <spatel@rotateright.com>
Sun, 3 Jul 2022 16:23:29 +0000 (12:23 -0400)
committerSanjay Patel <spatel@rotateright.com>
Sun, 3 Jul 2022 16:25:26 +0000 (12:25 -0400)
commitf9f40aa10d9862b8db1b99bb9e7f5898a90b35f7
treef4e39dfc241b27e9ecdae2fd6596d0c7080228f5
parentc1c3134ac422c51c635ea7f28c37838b3805c912
[InstCombine] fold negated low-bit-mask to cmp+select

(-(X & 1)) & Y --> (X & 1) == 0 ? 0 : Y
https://alive2.llvm.org/ce/z/rhpH3i

This is noted as a missing IR canonicalization in issue #55618.
We already managed to fix codegen to the expected form.
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/test/Transforms/InstCombine/and.ll