https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128662

Uroš Bizjak <ubizjak at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |liuhongt at gcc dot gnu.org,
                   |                            |Mayshao-oc at zhaoxin dot com,
                   |                            |vekumar at gcc dot gnu.org

--- Comment #2 from Uroš Bizjak <ubizjak at gmail dot com> ---
Selection of targets for X86_TUNE_AVOID_FALSE_DEP_FOR_BSR

BSF/BSR leave the destination unmodified for a zero source on both Intel
and AMD (AMD documents it, Intel implements it), so the destination is a
true input of the instruction.  The new tuning clears the destination
before BSR when that input is not needed.  Clearing is only worthwhile
where the dst->dst dependency is longer than the instruction's own
throughput cost, so I used the uops.info measurements for BSF r64,r64
(dst->dst latency, uops, reciprocal throughput) to pick the targets.
BSR shares the execution unit and agrees on the parts I checked.

  Microarchitecture                       uops  dst->dst  tput   Enable
  Nehalem .. Skylake, Cannon/Cascade/
    Ice/Tiger/Rocket Lake, Alder Lake-P,
    Emerald Rapids, Meteor Lake-P           1      3      1.0    yes
  Arrow Lake-P                              1      4      1.0    yes
  Tremont, Alder/Meteor/Arrow Lake-E        1      3    0.5-1.0  yes
  Zen 4                                     1      1      0.25   yes
  Zen 5                                     1      1      0.33   yes
  Core 2 (Conroe, Wolfdale)                 2      1      1.0    no
  Bonnell, Silvermont-family, Goldmont(+)  10-11  7-16   8-16    no
  Zen+, Zen 2, Zen 3                        6      2      3.0    no

Enabled targets: the dependency chain is much longer than the cost of
issuing BSR (3 cycles vs 1 on Intel, 1 vs 0.25 on Zen 4), and the xor
zero idiom is eliminated at rename, so independent BSRs can overlap.
This matches the numbers in comment #0 (Alder Lake P: 2.50 -> 0.86,
Zen 5: 1.54 -> 1.18).

Unlike X86_TUNE_AVOID_FALSE_DEP_FOR_BMI, Ice Lake and later are
included: Intel fixed the false dependency for lzcnt/tzcnt (Skylake) and
popcnt (Ice Lake), but not for BSF/BSR.

Not enabled:
  - Core 2: BSR is 2 uops and the dependency goes through the cheap
    merge uop (1 cycle), so there is nothing to gain.
  - Bonnell, Silvermont-family, Goldmont: microcoded; the instruction's
    own throughput (8-16 cycles) already exceeds the dependency.
  - Zen+, Zen 2, Zen 3 (assumed the same for Zen 1): 6 uops with a
    throughput of 3 cycles, longer than the 2-cycle dependency.

m_GENERIC is included so that default -O2 code, as in the testcase,
benefits.  On Zen 1-3 under generic tuning the cost is a single xor next
to a 6-uop instruction.

No data found for K8, K10, Bulldozer-family, Bobcat/Jaguar, KNL/KNM,
Zhaoxin/Lujiazui or Zen 6, so those are left out; target maintainers
can add them if measurements show a benefit.

Note the tuning only matters when BSR is actually emitted, i.e. without
LZCNT (generic, x86-64/x86-64-v2, pre-Haswell -march, -mno-lzcnt).

Adding some CCs to adjust proposed target selection.

Reply via email to