[InstCombine] Fold and-reduce idiom
authorMax Kazantsev <mkazantsev@azul.com>
Fri, 28 Jan 2022 04:20:08 +0000 (11:20 +0700)
committerMax Kazantsev <mkazantsev@azul.com>
Fri, 28 Jan 2022 04:20:08 +0000 (11:20 +0700)
commit8599bb0f26738ed88aae62aba57d82f7cf326cf9
treeba9ec2e48a42fd35fb94d30f58d2805094843cf9
parent4a64955c37570ef5f98db705d290d75adbeaf442
[InstCombine] Fold and-reduce idiom

This patch introduces folding of and-reduce idiom and generates code
that is easier to read and which is lest costly in terms of icmp operations.
The folding is
```
  icmp eq (bitcast(icmp ne (lhs, rhs)), 0)
```
into
```
  icmp eq(bitcast(lhs), bitcast(rhs))
```

See PR53419.

Differential Revision: https://reviews.llvm.org/D118317
Reviewed By: lebedev.ri, spatel
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/icmp-vec.ll
llvm/test/Transforms/InstCombine/reduction-and-sext-zext-i1.ll
llvm/test/Transforms/InstCombine/reduction-or-sext-zext-i1.ll