RFR: 8282204: Use lea instructions for arithmetic operations on x86_64 [v5]
Quan Anh Mai
duke at openjdk.java.net
Fri Feb 25 15:53:56 UTC 2022
On Fri, 25 Feb 2022 12:11:43 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:
>
> address reviews
May I ask what version of llvm are you using? Because due to [this patch](https://reviews.llvm.org/D32277), clang from 6.0.0 refuses to generate a 3-op `lea` for this operation while gcc seems to not care (although I checked msvc and also rustc all refrain from generating a complex `lea`).
You do see a `lea`, however, but that is due to a peephole that merges a `mov` and an `add` into a `lea` I believe. This is a little hard in hotspot since our peephole is not powerful enough, and using the matcher is not ideal either since an `add` is often more efficient than a `lea`, and if we make a rule such as `Set dst (AddI src1 src2)` and check if `src1 == dst` to use an `add` then most of the time we will end up with a less efficient `lea`.
I don't know if we have a mechanism to tell the register allocator to try its best to allocate the same register for the specified operands and if it fails to do so then it is still fine. If we can do so then we can cut off a portion of an uop for each addition which is really nice.
Thank you very much.
-------------
PR: https://git.openjdk.java.net/jdk/pull/7560
More information about the hotspot-compiler-dev
mailing list