[InstCombine] Fold cttz of lowest set bit
authorNikita Popov <npopov@redhat.com>
Fri, 14 Jul 2023 10:20:04 +0000 (12:20 +0200)
committerNikita Popov <npopov@redhat.com>
Fri, 14 Jul 2023 12:31:35 +0000 (14:31 +0200)
commitdc2b2ae7dc333f9c3769785fa147c7872adb9bba
tree79090fff3fa8e607f8eb7cbce6b2ef67fda30147
parentc8bc1abf55551741fbd887ec1b293c45065ac022
[InstCombine] Fold cttz of lowest set bit

cttz(-a & a) is the same as cttz(a). -a & a is an idiom to extract
the lowest set bit, which naturally does not affect the number of
trailing zeroes.

Proof: https://alive2.llvm.org/ce/z/Yp26x7
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/test/Transforms/InstCombine/cttz.ll
llvm/test/Transforms/InstCombine/select-ctlz-to-cttz.ll
llvm/test/Transforms/InstCombine/xor.ll