[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)
commita1852b619450f87b96e4f07ef684cd4cd8245ebd
tree2674307b822bd4003f65385d686e1ff309cc5513
parentc5018d46f2da7671873457fef33a63c924b59175
[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

llvm-svn: 338372
llvm/include/llvm/MC/MCInstrAnalysis.h
llvm/lib/MC/MCInstrAnalysis.cpp
llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
llvm/test/tools/llvm-mca/X86/BtVer2/dependency-breaking-cmp.s
llvm/test/tools/llvm-mca/X86/BtVer2/dependency-breaking-pcmpeq.s
llvm/test/tools/llvm-mca/X86/BtVer2/dependency-breaking-sbb-2.s
llvm/test/tools/llvm-mca/X86/BtVer2/one-idioms.s
llvm/tools/llvm-mca/DispatchStage.cpp
llvm/tools/llvm-mca/InstrBuilder.cpp
llvm/tools/llvm-mca/Instruction.h
llvm/tools/llvm-mca/RetireStage.cpp