[all-commits] [llvm/llvm-project] b1c382: [X86] Improve costmodel for scalar byte swaps

Roman Lebedev via All-commits all-commits at lists.llvm.org
Sat May 8 05:18:22 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: b1c38207e9ca6aba883a8000239163520ee6ed83
      https://github.com/llvm/llvm-project/commit/b1c38207e9ca6aba883a8000239163520ee6ed83
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2021-05-08 (Sat, 08 May 2021)

  Changed paths:
    M llvm/lib/Target/X86/X86.td
    M llvm/lib/Target/X86/X86Subtarget.h
    M llvm/lib/Target/X86/X86TargetTransformInfo.cpp
    M llvm/test/Analysis/CostModel/X86/bswap-store.ll
    M llvm/test/Analysis/CostModel/X86/bswap.ll
    M llvm/test/Analysis/CostModel/X86/load-bswap.ll

  Log Message:
  -----------
  [X86] Improve costmodel for scalar byte swaps

Currently we model i16 bswap as very high cost (`10`),
which doesn't seem right, with all other being at `1`.

Regardless of `MOVBE`, i16 reg-reg bswap is lowered into
(an extending move plus) rot-by-8:
https://godbolt.org/z/8jrq7fMTj
I think it should at worst have throughput of `1`:

Since i32/i64 already have cost of `1`,
`MOVBE` doesn't improve their costs any further.

BUT, `MOVBE` must have at least a single memory operand,
with other being a register. Which means, if we have
a bswap of load, iff load has a single use,
we'll fold bswap into load.

Likewise, if we have store of a bswap, iff bswap
has a single use, we'll fold bswap into store.

So i think we should treat such a bswap as free,
unless of course we know that for the particular CPU
they are performing badly.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D101924




More information about the All-commits mailing list