OSDN Git Service

[llvm-mca][BtVer2] Teach how to identify dependency-breaking idioms.
authorAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>
Tue, 31 Jul 2018 13:21:43 +0000 (13:21 +0000)
committerAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>
Tue, 31 Jul 2018 13:21:43 +0000 (13:21 +0000)
commite40028733823edc57d0ab4a191cf13631492ec8a
treeb3a4c305ca571ee700b3d9803f38108723617518
parent0915eb50a32368727766e1e744ac1206a48cae54
[llvm-mca][BtVer2] Teach how to identify dependency-breaking idioms.

This patch teaches llvm-mca how to identify dependency breaking instructions on
btver2.

An example of dependency breaking instructions is the zero-idiom XOR (example:
`XOR %eax, %eax`), which always generates zero regardless of the actual value of
the input register operands.
Dependency breaking instructions don't have to wait on their input register
operands before executing. This is because the computation is not dependent on
the inputs.

Not all dependency breaking idioms are also zero-latency instructions. For
example, `CMPEQ %xmm1, %xmm1` is independent on
the value of XMM1, and it generates a vector of all-ones.
That instruction is not eliminated at register renaming stage, and its opcode is
issued to a pipeline for execution. So, the latency is not zero.

This patch adds a new method named isDependencyBreaking() to the MCInstrAnalysis
interface. That method takes as input an instruction (i.e. MCInst) and a
MCSubtargetInfo.
The default implementation of isDependencyBreaking() conservatively returns
false for all instructions. Targets may override the default behavior for
specific CPUs, and return a value which better matches the subtarget behavior.

In future, we should teach to Tablegen how to automatically generate the body of
isDependencyBreaking from scheduling predicate definitions. This would allow us
to expose the knowledge about dependency breaking instructions to the machine
schedulers (and, potentially, other codegen passes).

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338372 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/MC/MCInstrAnalysis.h
lib/MC/MCInstrAnalysis.cpp
lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
test/tools/llvm-mca/X86/BtVer2/dependency-breaking-cmp.s
test/tools/llvm-mca/X86/BtVer2/dependency-breaking-pcmpeq.s
test/tools/llvm-mca/X86/BtVer2/dependency-breaking-sbb-2.s
test/tools/llvm-mca/X86/BtVer2/one-idioms.s
tools/llvm-mca/DispatchStage.cpp
tools/llvm-mca/InstrBuilder.cpp
tools/llvm-mca/Instruction.h
tools/llvm-mca/RetireStage.cpp