[PATCH] D141180: [X86] Only match BMI (BLSR, BLSI, BLSMSK) if the add/sub op is single use

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 6 19:41:01 PST 2023


goldstein.w.n created this revision.
Herald added subscribers: pengfei, hiraditya.
Herald added a project: All.
goldstein.w.n requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

If the add/sub is not single use, it will need to be materialized
later, in which case using the BMI instruction is a de-optimization in
terms of code-size and throughput.

i.e:

  // Good
  leal -1(%rdi), %eax
  andl %eax, %eax
  xorl %eax, %esi
  ...

  // Unecessary BMI (lower throughput, larger code size)
  leal -1(%rdi), %eax
  blsr %edi, %eax
  xorl %eax, %esi
  ...

Note, this may cause more `mov` instructions to be emitted sometimes
because BMI instructions only have 1 src and write-only to dst.  A
better approach may be to only avoid BMI for (and/xor X, (add/sub
0/-1, X)) if this is the last use of X but NOT the last use of
(add/sub 0/-1, X).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141180

Files:
  llvm/lib/Target/X86/X86InstrInfo.td
  llvm/test/CodeGen/X86/GlobalISel/select-blsi.mir
  llvm/test/CodeGen/X86/GlobalISel/select-blsr.mir
  llvm/test/CodeGen/X86/bmi-out-of-order.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141180.487037.patch
Type: text/x-patch
Size: 8413 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230107/8cf18574/attachment.bin>


More information about the llvm-commits mailing list