[X86][BtVer2] correctly model the latency/throughput of LEA instructions.
authorAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>
Thu, 19 Jul 2018 16:42:15 +0000 (16:42 +0000)
committerAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>
Thu, 19 Jul 2018 16:42:15 +0000 (16:42 +0000)
commitb6022aa8d900d175da00a5ca7b948a27ec61f4bf
treeb593879065f37bb5c48bc069f10522d8f42c24a2
parentb3638135432b66aa56831556b51963aef44a352c
[X86][BtVer2] correctly model the latency/throughput of LEA instructions.

This patch fixes the latency/throughput of LEA instructions in the BtVer2
scheduling model.

On Jaguar, A 3-operands LEA has a latency of 2cy, and a reciprocal throughput of
1. That is because it uses one cycle of SAGU followed by 1cy of ALU1.  An LEA
with a "Scale" operand is also slow, and it has the same latency profile as the
3-operands LEA. An LEA16r has a latency of 3cy, and a throughput of 0.5 (i.e.
RThrouhgput of 2.0).

This patch adds a new TIIPredicate named IsThreeOperandsLEAFn to X86Schedule.td.
The tablegen backend (for instruction-info) expands that definition into this
(file X86GenInstrInfo.inc):
```
static bool isThreeOperandsLEA(const MachineInstr &MI) {
  return (
    (
      MI.getOpcode() == X86::LEA32r
      || MI.getOpcode() == X86::LEA64r
      || MI.getOpcode() == X86::LEA64_32r
      || MI.getOpcode() == X86::LEA16r
    )
    && MI.getOperand(1).isReg()
    && MI.getOperand(1).getReg() != 0
    && MI.getOperand(3).isReg()
    && MI.getOperand(3).getReg() != 0
    && (
      (
        MI.getOperand(4).isImm()
        && MI.getOperand(4).getImm() != 0
      )
      || (MI.getOperand(4).isGlobal())
    )
  );
}
```

A similar method is generated in the X86_MC namespace, and included into
X86MCTargetDesc.cpp (the declaration lives in X86MCTargetDesc.h).

Back to the BtVer2 scheduling model:
A new scheduling predicate named JSlowLEAPredicate now checks if either the
instruction is a three-operands LEA, or it is an LEA with a Scale value
different than 1.
A variant scheduling class uses that new predicate to correctly select the
appropriate latency profile.

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

llvm-svn: 337469
13 files changed:
llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.h
llvm/lib/Target/X86/X86.td
llvm/lib/Target/X86/X86FixupLEAs.cpp
llvm/lib/Target/X86/X86SchedPredicates.td [new file with mode: 0644]
llvm/lib/Target/X86/X86Schedule.td
llvm/lib/Target/X86/X86ScheduleBtVer2.td
llvm/test/CodeGen/X86/lea32-schedule.ll
llvm/test/CodeGen/X86/lea64-schedule.ll
llvm/test/CodeGen/X86/mul-constant-i32.ll
llvm/test/CodeGen/X86/mul-constant-i64.ll
llvm/test/CodeGen/X86/schedule-x86-64-shld.ll
llvm/test/tools/llvm-mca/X86/BtVer2/resources-lea.s