This is an archive of the discontinued LLVM Phabricator instance.

[AAch64] Don't treat SVE scalable extends as free widening instructions
ClosedPublic

Authored by dmgreen on Nov 23 2022, 10:38 AM.

Details

Summary

The logic in isWideningInstruction handles instructions like uaddw and smull, where add(x, zext(y)) or mul(sext(x), sext(y)) can be converted to single instructions, making the extends free. This doesn't apply the same to SVE instructions though.
https://godbolt.org/z/695d3nhGd

(There are instructions like SMULLT/B, but they require top/bottom lane interleaving. That is similar to MVE instructions, which required a special pass to perform the lane interleaving).

This patch just bails out of the call to isWideningInstruction if the vector is scalable, getting a more accurate cost.

Diff Detail

Event Timeline

dmgreen created this revision.Nov 23 2022, 10:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 23 2022, 10:38 AM
dmgreen requested review of this revision.Nov 23 2022, 10:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 23 2022, 10:38 AM
Matt added a subscriber: Matt.Nov 23 2022, 4:02 PM
sdesmalen added inline comments.Nov 24 2022, 3:51 AM
llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
1640

It seems that the implementation of isWideningInstruction is historically a bit NEON specific and although SVE2 adds similar instructions, they work a little bit different and LLVM doesn't currently make use of them.
It might make more sense to add this condition to isWideningInstruction instead and possibly add a FIXME to enable this in the future when LLVM does have support for it. What do you think?

dmgreen updated this revision to Diff 478138.Nov 28 2022, 12:29 AM
dmgreen edited the summary of this revision. (Show Details)

Sounds OK to me. I've moved the check into isWideningInstruction and added a comment about SVE instruction variants.

sdesmalen added inline comments.Nov 28 2022, 12:53 AM
llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
1570

It's probably better to use !useNeonVector(DstTy) for this, given that fixed-width SVE has the same issue.

You may want to add a similar test to llvm/test/Analysis/CostModel/AArch64/sve-fixed-length.ll for this as well.

dmgreen updated this revision to Diff 478509.Nov 29 2022, 3:56 AM

Use useNeonVector instead of checking for scalable vectors. Fixed length SVE vectors is not something I ever remember about.

sdesmalen accepted this revision.Nov 29 2022, 4:56 AM

Thanks @dmgreen, LGTM

This revision is now accepted and ready to land.Nov 29 2022, 4:56 AM
This revision was landed with ongoing or failed builds.Nov 30 2022, 5:10 AM
This revision was automatically updated to reflect the committed changes.