This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Add RSHRN and RSHRN2 patterns
ClosedPublic

Authored by dmgreen on Dec 19 2022, 5:34 AM.

Details

Summary

This adds some tablegen patterns for RSHRN, which performs a rounding shift with narrow. This is similar to the existing SHRN patterns with an extra addition to perform the rounding, that adds 1<<(shift-1) before the right shift. Because the round immediate and the shift amount are tied, it goes via a ComplexPattern that uses a SelectRoundingVLShr method to perform the selection checks.

aarch64_neon_rshrn are expanded into the sequence of equivalent instructions (trunc(shr(add(x, 1<<(sht-1)), sht))) so that they can be converted back into RSHRN. Which also allows us to match raddhn through the adjusted patterns that previously used aarch64_neon_rshrn.

Diff Detail

Event Timeline

dmgreen created this revision.Dec 19 2022, 5:34 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 19 2022, 5:34 AM
dmgreen requested review of this revision.Dec 19 2022, 5:34 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 19 2022, 5:34 AM
samtebbs added inline comments.Dec 20 2022, 2:30 AM
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
18038

is it possible for the shift amount here to be greater than VT.getScalarSizeInBits() / 2 and so not be selected by SelectRoundingVLShr? If it is possible then a check here would be good.

dmgreen added inline comments.Dec 20 2022, 8:24 AM
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
18038

Yep this should be OK. The aarch64_neon_rshrn intrinsics should only allow shift amounts that are valid for the instruction, which is upto half the input type size. They will be checked in clang: https://godbolt.org/z/99M53cWKz (and would have generated invalid instructions otherwise).

samtebbs accepted this revision.Dec 20 2022, 8:25 AM

Cool, that sounds good to me. Nice change and LGTM!

This revision is now accepted and ready to land.Dec 20 2022, 8:25 AM
This revision was landed with ongoing or failed builds.Dec 22 2022, 8:49 AM
This revision was automatically updated to reflect the committed changes.