This is an archive of the discontinued LLVM Phabricator instance.

[BasicTTI] Allow generic handling of scalable vector fshr/fshl
ClosedPublic

Authored by reames on Jun 13 2022, 12:06 PM.

Details

Summary

This change removes an explicit scalable vector bailout for fshl and fshr. This bailout was added in 60e4698b9aba8, when sinking a unconditional bailout for all intrinsics into selected cases. Its not clear if the bailout was originally unneeded, or if our cost model infrastructure has simply matured in the meantime. Either way, the generic code appears to handle scalable vectors without issue.

Note that the RISC-V cost model changes here aren't particularly interesting. They do probably better match the current lowering, but the main point is to have coverage of the BasicTTI path and simply show lack of crashing.

Diff Detail

Event Timeline

reames created this revision.Jun 13 2022, 12:06 PM
reames requested review of this revision.Jun 13 2022, 12:06 PM

I suspect we were just being overly conservative at the time when fixing up some FixedVectorType casts, but as you say it seems to work now. Would you be able to add a similar Analysis/CostModel/AArch64/sve-intrinsics.ll test as well for the <vscale x 4 x i32> case?

RISC-V change LGTM

I suspect we were just being overly conservative at the time when fixing up some FixedVectorType casts, but as you say it seems to work now. Would you be able to add a similar Analysis/CostModel/AArch64/sve-intrinsics.ll test as well for the <vscale x 4 x i32> case?

@david-arm It's not really clear which test you want me to add. Since this isn't fixing a crash, could you just land what you have in mind and I'll rebase this over?

craig.topper added a comment.EditedJun 15 2022, 4:29 PM

I suspect we were just being overly conservative at the time when fixing up some FixedVectorType casts, but as you say it seems to work now. Would you be able to add a similar Analysis/CostModel/AArch64/sve-intrinsics.ll test as well for the <vscale x 4 x i32> case?

@david-arm It's not really clear which test you want me to add. Since this isn't fixing a crash, could you just land what you have in mind and I'll rebase this over?

I think the request is to add these to sve-intrinsics.ll

define void @fshr(<vscale x 4 x i32> %a, <vscale x 4 x i32> %b, <vscale x 4 x i32> %c) {
  call <vscale x 4 x i32> @llvm.fshr.nxv4i32(<vscale x 4 x i32> %a, <vscale x 4 x i32> %b, <vscale x 4 x i32> %c)
  ret void
}

define void @fshl(<vscale x 4 x i32> %a, <vscale x 4 x i32> %b, <vscale x 4 x i32> %c) {
  call <vscale x 4 x i32> @llvm.fshl.nxv4i32(<vscale x 4 x i32> %a, <vscale x 4 x i32> %b, <vscale x 4 x i32> %c)
  ret void
}
llvm/test/Analysis/CostModel/RISCV/rvv-intrinsics.ll
39

This should be llvm.fshr.nxv1i32. The instrinsic parser is lax about checking the type part of the string.

Thanks @craig.topper for explaining better than I - yes those are exactly the tests I meant! If it's easier I can add some tests myself though today and then this patch can be rebased? I just haven't had chance to do it yet.

I've now added some fshl/fshr cost model tests for SVE (https://reviews.llvm.org/rGcd53e6b48b67) so I believe you just have to rebase now!

reames updated this revision to Diff 437603.Jun 16 2022, 10:52 AM

Rebase and add AArch64 target code to avoid change in cost modelling.

reames added inline comments.Jun 16 2022, 10:53 AM
llvm/test/Analysis/CostModel/RISCV/rvv-intrinsics.ll
39

Oops, fixed.

Matt added a subscriber: Matt.Jun 16 2022, 4:44 PM
craig.topper added inline comments.Jun 18 2022, 11:30 AM
llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
425

Seems like this should be a FIXME?

dmgreen added inline comments.
llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
425

I don't think this needs to be added. Just updating the costs in the test files to whatever is now produced will likely be more accurate, and more in-line with the scalar and fixed length vector costs. We can then update them more accurately in the future.

reames added inline comments.Jun 20 2022, 9:02 AM
llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
425

I don't work on SVE, don't have any sense for what "reasonable" costs are for the target, and don't particularly want to be on the blame list for a potential performance swing investigation. If you think the costs are likely reasonable, I'd ask that you remove the bailout in a separate following change.

dmgreen accepted this revision.Jun 20 2022, 10:19 AM

Whichever way you go with the test, I think we can all agree that the change looks fine. LGTM

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
425

The numbers looked fine when I looked at them. 13 IIRC? It would be unreasonable for someone to blame this commit for performance regression, considering how little costs we have for funnel shifts. It's more likely to make things better, and they are free to blame me if it does make things worse.

It would seem simpler to remove this code and just update the test. I believe that was what @david-arm was asking for. But if you insist then sure, I can update afterwards. That should be simple enough.

This revision is now accepted and ready to land.Jun 20 2022, 10:19 AM
This revision was landed with ongoing or failed builds.Jun 20 2022, 10:38 AM
This revision was automatically updated to reflect the committed changes.
reames added inline comments.Jun 20 2022, 10:41 AM
llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
425

In this particular case, I'm probably being paranoid, but in generally, yes I think it's well worth splitting changes to minimize the impact on other targets and configurations. You say no one would reasonable blame this patch for a performance regression. My experience says I've wasted a lot of time whether someone was reasonable on patches just this simple. :)