This is an archive of the discontinued LLVM Phabricator instance.

[SVE] Fix incorrect code generation for bitcasts of unpacked vector types.
ClosedPublic

Authored by paulwalker-arm on Jun 3 2022, 4:13 AM.

Details

Summary

Bitcasting between unpacked scalable vector types of different
element counts is not a NOP because the live elements are laid out
differently.

01234567

e.g. nxv2i32 = XX??XX??

nxv4f16 = X?X?X?X?

Diff Detail

Event Timeline

paulwalker-arm created this revision.Jun 3 2022, 4:13 AM
Herald added a project: Restricted Project. · View Herald Transcript
paulwalker-arm requested review of this revision.Jun 3 2022, 4:13 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 3 2022, 4:13 AM

For this patch I'm just playing it safe and using common expansion via the stack rather than anything more exotic.

The "correct" expansion isn't too tricky. First, compute "packed" types for the source and destination. Then just insert_subvector into the packed source, bitcast to the packed destination, then extract_subvector. Should optimize to one or two instructions once we lower the insert_subvector/extract_subvector into shuffles. Not that I'm really against the current version, but if we're going to end up rewriting this code anyway, might as well do it now.

Should we add an assertion to getSVESafeBitCast() that we aren't performing a bitcast like this?

@efriedma I'd still rather have the improved code generation as a separate patch, mainly because this patch forces the need to remove an invalid type size conversion from SelectionDAGLegalize::EmitStackConvert and I'd like there to be a window (however small) that validates the code now works for fixed and scalable vector types.

Allen added a subscriber: Allen.Jun 4 2022, 9:08 PM

Add assert to getSVESafeBitCast to detect original failure case.

This revision is now accepted and ready to land.Jun 6 2022, 11:18 AM
This revision was landed with ongoing or failed builds.Jun 8 2022, 2:31 AM
This revision was automatically updated to reflect the committed changes.