RFR: 8282204: Use lea instructions for arithmetic operations on x86_64 [v6]

Jie Fu jiefu at openjdk.java.net
Mon Feb 28 15:13:54 UTC 2022


On Mon, 28 Feb 2022 12:01:31 GMT, Quan Anh Mai <duke at openjdk.java.net> wrote:

>> Hi,
>> 
>> This patch adds several matching rules for x86_64 backend to use `lea` instructions for several fused arithmetic operations. Also, `lea`s don't kill flags and allow different `dst` and `src`, so it is preferred over `sll` if possible, too. 
>> 
>> Thank you very much.
>
> Quan Anh Mai has updated the pull request incrementally with one additional commit since the last revision:
> 
>   reviews

The Intel manual mentions that

For LEA instructions with three source operands and some specific situations, instruction latency has
increased to 3 cycles, and must dispatch via port 1:
— LEA that has all three source operands: base, index, and offset.
— LEA that uses base and index registers where the base is EBP, RBP, or R13.
...


My understanding is that we should avoid generating lea with base=rbp/r13.
But the current patch fails to do so, e.g., 

instruct leaI_rReg_rReg_immI(rRegI dst, rRegI src1, rRegI src2, immI disp)
%{
  predicate(VM_Version::supports_fast_3op_lea());
  match(Set dst (AddI (AddI src1 src2) disp));

  format %{ "addr32 leal $dst, [$src1 + $src2 + $disp]\t# int" %}
  ins_encode %{
    __ leal($dst$$Register, Address($src1$$Register, $src2$$Register, Address::times_1, $disp$$constant));
  %}
  ins_pipe(ialu_reg_reg);
%}

-------------

PR: https://git.openjdk.java.net/jdk/pull/7560


More information about the hotspot-compiler-dev mailing list