This is an archive of the discontinued LLVM Phabricator instance.

[LoongArch] Emit bytepick for picking from concatenation of two values
ClosedPublic

Authored by xen0n on Feb 12 2023, 11:46 PM.

Details

Summary

It seems the ISA manual's pseudo-code description for the
BYTEPICK.[WD] instructions is inaccurate; the behavior described here
should be correct though. The instructions' names are misleading too
(they pick full GRLen-wide words instead of bytes; they just index by
bytes) but let's stick to the official names for now.

Diff Detail

Event Timeline

xen0n created this revision.Feb 12 2023, 11:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 12 2023, 11:46 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
xen0n requested review of this revision.Feb 12 2023, 11:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 12 2023, 11:46 PM

@xry111: BTW your GCC implementation of this pattern looks for *arithmetic* right shifts; do you mean logical instead? Because obviously the higher bits would be full of ones after shifting if rj happen to have its MSB set. The sign extension shall happen *after* the pick.

Self note: the pattern may need more love, because the signext i32 cases appear wrong on LA64.

xen0n added a comment.Feb 13 2023, 4:48 AM

@xry111: BTW your GCC implementation of this pattern looks for *arithmetic* right shifts; do you mean logical instead? Because obviously the higher bits would be full of ones after shifting if rj happen to have its MSB set. The sign extension shall happen *after* the pick.

My bad, I'm not familiar with GCC RTL patterns so I've mistakenly thought "lshiftrt could be some 'left' shift, so ashift must be an arithmetic right shift". Actually your pattern is correct as you have perfect test coverage. Please ignore my comment...

@xry111: BTW your GCC implementation of this pattern looks for *arithmetic* right shifts; do you mean logical instead? Because obviously the higher bits would be full of ones after shifting if rj happen to have its MSB set. The sign extension shall happen *after* the pick.

My bad, I'm not familiar with GCC RTL patterns so I've mistakenly thought "lshiftrt could be some 'left' shift, so ashift must be an arithmetic right shift". Actually your pattern is correct as you have perfect test coverage. Please ignore my comment...

Yes, the naming in GCC confused me as well :).

xen0n updated this revision to Diff 496939.Feb 13 2023, 5:30 AM

Fix the pattern for bstrpick.w on LA64.

xen0n updated this revision to Diff 496986.Feb 13 2023, 7:44 AM

update other affected tests

SixWeining accepted this revision.Feb 16 2023, 10:50 PM

LGTM. Thanks!

Yes, I think the ISA's pseudo-code description is incorrect. Maybe it shoud be:

bytepick.w:

  tmp = {GR[rk][31:0],  GR[rj][31:0]}

  GR[rd] = SignExtend(tmp[8×(8-sa2)-1:8×(4-sa2)], GRLEN)

  or

  GR[rd] = SignExtend(tmp[8×(4-sa2)+31:8×(4-sa2)], GRLEN)
This revision is now accepted and ready to land.Feb 16 2023, 10:50 PM
This revision was landed with ongoing or failed builds.Mar 16 2023, 12:07 AM
This revision was automatically updated to reflect the committed changes.