[x86] improve codegen for bit-masked vector compare and select (PR46531)
authorSanjay Patel <spatel@rotateright.com>
Fri, 3 Jul 2020 21:31:57 +0000 (17:31 -0400)
committerSanjay Patel <spatel@rotateright.com>
Fri, 3 Jul 2020 21:31:57 +0000 (17:31 -0400)
commit26543f1c0cee8aad30d9b901e7dcf7282f8a30e0
tree7b775ce0157d88bfd178493cee3b86019a37e1a4
parent7fd8af1de052e5bb0e07adba1d2c9e58d1a8f6a4
[x86] improve codegen for bit-masked vector compare and select (PR46531)

We canonicalize patterns like:
  %s = lshr i32 %a0, 1
  %t = trunc i32 %s to i1

to:
  %a = and i32 %a0, 2
  %c = icmp ne i32 %a, 0

...in IR, but the bit-shifting original sequence may be better for x86 vector codegen.

I tried several variants of the transform, and it's tricky to not induce regressions.
In particular, I did not find a way to cleanly handle non-splat constants, so I've left
that as a TODO item here (currently negative tests for those are included). AVX512
resulted in some diffs, but didn't look meaningful, so I left that out too. Some of
the 256-bit AVX1 diffs are questionable, but close enough that they are probably
insignificant.

Differential Revision: https://reviews.llvm.org/D83073.
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/vselect-pcmp.ll