[PATCH] D150324: [X86] Make constant `mul` -> `shl` + `add`/`sub` work for vector types

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 10 16:04:32 PDT 2023


goldstein.w.n created this revision.
goldstein.w.n added reviewers: pengfei, RKSimon.
Herald added a subscriber: 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.

Something like:

  `%r = mul %x, <33, 33, 33, ...>`

Is best lowered as:

  `%tmp = %shl x, <5, 5, 5>; %r = add %tmp, %x`

As well, since vectors have non-destructive shifts, we can also do
cases where the multiply constant is `Pow2A +/- Pow2B` for arbitrary A
and B, unlike in the scalar case where the extra `mov` instructions
make it not worth it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150324

Files:
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/test/CodeGen/X86/avx512-broadcast-unfold.ll
  llvm/test/CodeGen/X86/combine-add.ll
  llvm/test/CodeGen/X86/combine-shl.ll
  llvm/test/CodeGen/X86/masked_gather_scatter.ll
  llvm/test/CodeGen/X86/omit-urem-of-power-of-two-or-zero-when-comparing-with-zero.ll
  llvm/test/CodeGen/X86/rotate-extract-vector.ll
  llvm/test/CodeGen/X86/undo-mul-and.ll
  llvm/test/CodeGen/X86/var-permute-128.ll
  llvm/test/CodeGen/X86/var-permute-256.ll
  llvm/test/CodeGen/X86/vector-idiv-sdiv-128.ll
  llvm/test/CodeGen/X86/vector-idiv-sdiv-256.ll
  llvm/test/CodeGen/X86/vector-idiv-sdiv-512.ll
  llvm/test/CodeGen/X86/vector-idiv-udiv-128.ll
  llvm/test/CodeGen/X86/vector-idiv-udiv-256.ll
  llvm/test/CodeGen/X86/vector-idiv-udiv-512.ll
  llvm/test/CodeGen/X86/vector-mul.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150324.521133.patch
Type: text/x-patch
Size: 64089 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230510/c04e2b35/attachment-0001.bin>


More information about the llvm-commits mailing list