This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Correct isLegalAddressingMode for ldp/stp
AbandonedPublic

Authored by bcl5980 on Apr 19 2022, 10:24 AM.

Details

Summary

AArch64 doesn't support ldp/stp with scale register. So if the load/store instruction may be selected to ldp/stp, return illegal addressing mode when the address pattern has scale register.

Fix https://github.com/llvm/llvm-project/issues/53877

Diff Detail

Unit TestsFailed

Event Timeline

bcl5980 created this revision.Apr 19 2022, 10:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 19 2022, 10:24 AM
bcl5980 requested review of this revision.Apr 19 2022, 10:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 19 2022, 10:24 AM
bcl5980 added inline comments.Apr 19 2022, 10:26 AM
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
13217

I'm not sure if we have better way to check here. Can someone help to find some other clean solution?

bcl5980 added inline comments.Apr 19 2022, 10:27 AM
llvm/test/Transforms/LoopStrengthReduce/AArch64/issue53877.ll
1

I will update the baseline if reviewers look good for the test.

This is an area of the compiler that is very performance sensitive. We have known there is room for improvement here for a while, but what you are adding is a heuristic built on top of other heuristics, and it can be difficult to make improvements without causing other issues. This patch looks sensible to me, but do you have any performance results on a larger set of results?

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
13217

From what I can tell, you mean that the Ty is a vector, loaded into a FPR? Not really a 128bit scalar type. There is an LDR q [r,r] addressing mode, so we are adding a heuristic saying it is better to assume they will later become an ldp, which don't have a rr addressing mode.

It would probably be best to check it is a vector directly. Or maybe have the isLegalAddressingMode return more precise results (as it does at the moment) and teach the next layer up (LSR) about paired addressing modes.

llvm/test/Transforms/LoopStrengthReduce/AArch64/issue53877.ll
1

Can you give it a better name? And do some cleanup of "; Function Attrs: mustprogress..", etc.

This is an area of the compiler that is very performance sensitive. We have known there is room for improvement here for a while, but what you are adding is a heuristic built on top of other heuristics, and it can be difficult to make improvements without causing other issues. This patch looks sensible to me, but do you have any performance results on a larger set of results?

Thanks for the detail explaination. I agree addressing mode legal check is perf sensitive.
I'm a beginner so I don't know we already have some plan to improve here. I don't have any real perf data. So I will abandon the patch if someone is working on it.
And can you tell me if we do some perf sensitive change. what should we test ? I know some CPU perf bench like specCPU, cinebench, geekbench, but all of them are not open-source.

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
13217

The purpose of this code is find the type will be select to ldp/stp.
What I thought is i128 also can be compile to stp/ldp with 2 int registers so the type is scalar of vector is not the key point.
And SVE load store may not come to here as line 13183

if (isa<ScalableVectorType>(Ty)) {

So we need to fix the FixedVectorType with 128bits FP register here also. Am I right?

Matt added a subscriber: Matt.Apr 20 2022, 12:24 PM

Hmm. So I think that the current version of isLegalAddressingMode is technically correct - in that AArch64 does have r+r addressing modes for both scalars and vectors. (It might not for strange types, but that's not what we are targeting here). Adding a heuristic to make it wrong, so that the next level up produces better code is an option - but it may be better in the long run to fix the places using this (LSR for example) so that they understand about paired loads and can produce better code in all cases.

And can you tell me if we do some perf sensitive change. what should we test ? I know some CPU perf bench like specCPU, cinebench, geekbench, but all of them are not open-source.

There are the benchmarks in the llvm-test-suite. They can be a bit noisy though, unfortunately, so need to be ran with care.

bcl5980 abandoned this revision.Apr 21 2022, 7:24 AM

Hmm. So I think that the current version of isLegalAddressingMode is technically correct - in that AArch64 does have r+r addressing modes for both scalars and vectors. (It might not for strange types, but that's not what we are targeting here). Adding a heuristic to make it wrong, so that the next level up produces better code is an option - but it may be better in the long run to fix the places using this (LSR for example) so that they understand about paired loads and can produce better code in all cases.

And can you tell me if we do some perf sensitive change. what should we test ? I know some CPU perf bench like specCPU, cinebench, geekbench, but all of them are not open-source.

There are the benchmarks in the llvm-test-suite. They can be a bit noisy though, unfortunately, so need to be ran with care.

Thanks,I will abandon this change.

@dmgreen , do I need to add a todo and check in the test after clean?

@dmgreen , do I need to add a todo and check in the test after clean?

I'm not sure about a TODO. Where would it be added? I find they tend to bitrot and muddle the code, more then they help sometimes.

Having a test sounds useful, to show inefficiencies that can be fixed.