[PATCH] D66424: [X86][Btver2] Fix latency and throughput of CMPXCHG instructions.

Andrea Di Biagio via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 19 09:17:30 PDT 2019


andreadb created this revision.
andreadb added reviewers: RKSimon, craig.topper.
Herald added subscribers: jfb, gbedwell.

On Jaguar, CMPXCHG has a latency of 11cy, and a maximum throughput of 0.33 IPC. Throughput is superiorly limited to 0.33 because of the implicit in/out dependency on register EAX. In the case of repeated non-atomic CMPXCHG with the same memory location, store-to-load forwarding occurs and values for sequent loads are quickly forwarded from the store buffer.

Interestingly, the functionality in LLVM that computes the reciprocal throughput doesn't seem to know about RMW instructions. That functionality only looks at the "consumed resource cycles" for the throughput computation. It should be fixed/improved by a future patch. In particular, for RMW instructions, that logic should also take into account for the write latency of in/out register operands.

An atomic CMPXCHG has a latency of ~17cy. Throughput is also limited to ~17cy/inst due to cache locking, which prevents other memory uOPs to start executing before the "lock releasing" store uOP.

CMPXCHG8rr and CMPXCHG8rm are treated specially because they decode to one less macro opcode. Their latency tend to be the same as the other RR/RM variants. RR variants are relatively fast 3cy (but still microcoded - 5 macro opcodes).

The two new `hasLockPrefix()` functions are used by the btver2 scheduling model check if a MCInst/MachineInst has a LOCK prefix. Calls to `hasLockPrefix()` have been encoded in predicates of variant scheduling classes that describe lat/thr of CMPXCHG.

Let me know if okay to commit.


https://reviews.llvm.org/D66424

Files:
  lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
  lib/Target/X86/MCTargetDesc/X86MCTargetDesc.h
  lib/Target/X86/X86InstrInfo.h
  lib/Target/X86/X86SchedPredicates.td
  lib/Target/X86/X86ScheduleBtVer2.td
  test/tools/llvm-mca/X86/BtVer2/resources-cmpxchg.s
  test/tools/llvm-mca/X86/BtVer2/resources-x86_64.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66424.215917.patch
Type: text/x-patch
Size: 16673 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190819/67953289/attachment.bin>


More information about the llvm-commits mailing list